summaryrefslogtreecommitdiff
path: root/tools/tmwcon/src/Converter.java
blob: b7082844da51bb1a7f29a41aa3eda66b3cf369dd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
 * TMWServ to eAthena Converter (c) 2008 Jared Adams
 * License: GPL, v2 or later
 */

import java.io.*;
import java.lang.reflect.*;
import java.net.*;
import java.util.*;

public abstract class Converter {
    static String[] tiledJars = {"tile-core.jar", "tiled.jar"};
    static String[] wlkJars = {"plugins/tmw.jar", "tmw.jar"};

    public static void main(String[] args) throws Exception {
        List<URL> urls = new ArrayList<URL>();

        File tiled = null;
        for (String s : tiledJars) {
            tiled = new File(s);
            if (tiled.exists()) break;
        }
        if (tiled == null || !tiled.exists()) {
            System.err.println("Unable to find a Tiled jar file! Exiting.");
            System.exit(-5);
        }
        urls.add(tiled.toURI().toURL());

        File wlkWriter = null;
        for (String s : wlkJars) {
            wlkWriter = new File(s);
            if (wlkWriter.exists()) break;
        }
        if (wlkWriter == null || !wlkWriter.exists()) {
            System.err.println("Unable to find the tmw plugin for Tiled! No wlk files will be made!");
        } else {
            urls.add(wlkWriter.toURI().toURL());
        }

        File self = new File("converter.jar");
        if (!self.exists()) {
            System.err.println("Unable to find a the converter jar! Exiting.");
            System.exit(-5);
        }
        urls.add(self.toURI().toURL());

        URLClassLoader loader = new URLClassLoader(urls.toArray(new URL[0]));
        Class c = loader.loadClass("converter.Main");
        Method m = c.getMethod("run", String[].class, Integer.TYPE);
        System.out.println("Starting");
        
        m.invoke(null, args, 0);
    }
}