diff --git a/build.sh b/build.sh index 75119e7..915478b 100755 --- a/build.sh +++ b/build.sh @@ -30,9 +30,9 @@ cd java cd .. #echo "building launcher.jar" -#cd build -#"$JAVA_HOME"/bin/jar -cf launcher.jar -#cd .. +cd build +"$JAVA_HOME"/bin/jar -cf launcher.jar net +cd .. if [ -z $I2P_VERSION ]; then I2P_VERSION=$("$JAVA_HOME"/bin/java -cp build/router.jar net.i2p.router.RouterVersion | sed "s/.*: //" | head -n 1) diff --git a/java/net/i2p/router/WinLauncher.java b/java/net/i2p/router/WinLauncher.java index 9eebd8a..736b8c2 100644 --- a/java/net/i2p/router/WinLauncher.java +++ b/java/net/i2p/router/WinLauncher.java @@ -2,34 +2,50 @@ package net.i2p.router; import java.io.*; import java.util.*; +import net.i2p.router.RouterLaunch; /** - * Launches a router from a Mac App Bundle. Uses Java 9 APIs. + * Launches a router from %PROGRAMFILES%/I2P using configuration data in + * %LOCALAPPDATA%/I2P.. Uses Java 9 APIs. + * Sets the following properties: * i2p.dir.base - this points to the (read-only) resources inside the bundle - * i2p.dir.config - this points to the folder the configuration files are located in + * i2p.dir.config this points to the (read-write) config directory in local appdata * router.pid - the pid of the java process. */ public class WinLauncher { /** this is totally undocumented */ - private static final String APP_PATH = "jpackage.app-path"; +// private static final String APP_PATH = "jpackage.app-path"; private static final String LOCALAPPDATA = System.getenv("LOCALAPPDATA"); public static void main(String[] args) throws Exception { - String path = System.getProperty(APP_PATH,"unknown"); - File f = new File(path); + for (int i = 0; i < args.length; i++){ + System.out.println("arguments" + i + args[i]); + } + +// String path = System.getProperty(APP_PATH, "unknown"); + File f = selectProgramFile(); File contents = f.getParentFile().getParentFile(); + File home = selectHome(); + if (!home.exists()) + home.mkdirs(); + else if (!home.isDirectory()) { + System.err.println(home + " exists but is not a directory. Please get it out of the way"); + System.exit(1); + } + File resources = new File(contents, "Resources"); File bundleLocation = contents.getParentFile().getParentFile(); System.setProperty("i2p.dir.base", resources.getAbsolutePath()); - + System.setProperty("i2p.dir.config", home.getAbsolutePath()); System.setProperty("router.pid", String.valueOf(ProcessHandle.current().pid())); try { + // TODO: See if I need to do anything like this for Windows //System.load(resources.getAbsolutePath() + "/libMacLauncher.jnilib"); //disableAppNap(); } catch (Throwable bad) { @@ -41,6 +57,20 @@ public class WinLauncher { RouterLaunch.main(args); } + private static File selectHome() throws Exception { + File home = new File(System.getProperty("user.home")); + File i2p; + File appData = new File(home, "AppData"); + File local = new File(appData, "Local"); + i2p = new File(local, "I2P"); + return i2p.getAbsoluteFile(); + } + private static File selectProgramFile() throws Exception { + File programs = new File(System.getenv("ProgramFiles")); + File i2p; + i2p = new File(programs, "I2P"); + return i2p.getAbsoluteFile(); + } }