From 11a8f2cb087a2845499658365595cc0c61d0be99 Mon Sep 17 00:00:00 2001 From: idk Date: Tue, 13 Sep 2022 02:03:09 -0400 Subject: [PATCH] update the configuration file to point back automatically --- java/net/i2p/router/CopyConfigDir.java | 33 ++++++++++++++++++++++++++ java/net/i2p/router/WinLauncher.java | 32 ++++++++++--------------- 2 files changed, 45 insertions(+), 20 deletions(-) diff --git a/java/net/i2p/router/CopyConfigDir.java b/java/net/i2p/router/CopyConfigDir.java index cfb7ed8..b4ccc69 100644 --- a/java/net/i2p/router/CopyConfigDir.java +++ b/java/net/i2p/router/CopyConfigDir.java @@ -232,6 +232,28 @@ public class CopyConfigDir { return null; } + /** + * get the path to the binary of the app-image root by getting the path to + * java.home and the OS, and traversing up to the app-image root based on that + * information, then getting the binary path on a per-platform basis. The path + * returned will be relative to the root. + * + * @return the app-image root + */ + protected static String appImageExe() { + File aih = appImageHome(); + if (aih != null) { + switch (osName()) { + case "windows": + return "I2P.exe"; + case "mac": + case "linux": + return "./bin/I2P"; + } + } + return null; + } + /** * get the path to the default config of the app-image by getting the path to * java.home and the OS, and traversing up to the app-image root based on that @@ -272,6 +294,17 @@ public class CopyConfigDir { return copyConfigDirectory(appImageConfigDir, appImageHomeDir); } + protected static String routerConfig() { + File appImageHomeDir = appImageHome(); + File routerConf = new File(appImageHomeDir, "router.config"); + if (routerConf != null) { + if (routerConf.exists()) { + return routerConf.getAbsolutePath(); + } + } + return null; + } + /** * set up the path to the log file * diff --git a/java/net/i2p/router/WinLauncher.java b/java/net/i2p/router/WinLauncher.java index e063ae4..e569783 100644 --- a/java/net/i2p/router/WinLauncher.java +++ b/java/net/i2p/router/WinLauncher.java @@ -94,11 +94,6 @@ public class WinLauncher extends CopyConfigDir { System.exit(1); } - if (launchBrowser(privateBrowsing, usabilityMode, chromiumFirst, - proxyTimeoutTime, newArgsList)) { - System.exit(0); - } - System.setProperty("i2p.dir.base", programs.getAbsolutePath()); System.setProperty("i2p.dir.config", home.getAbsolutePath()); System.setProperty("router.pid", @@ -115,7 +110,18 @@ public class WinLauncher extends CopyConfigDir { */ System.setProperty("user.dir", programs.getAbsolutePath()); - i2pRouter = new Router(System.getProperties()); + i2pRouter = new Router(routerConfig(), System.getProperties()); + + if (i2pRouter.saveConfig("routerconsole.browser", null)) { + logger.info("removed routerconsole.browser config"); + } + if (i2pRouter.saveConfig("routerconsole.browser", appImageExe())) { + logger.info("updated routerconsole.browser config " + appImageExe()); + } + if (launchBrowser(privateBrowsing, usabilityMode, chromiumFirst, + proxyTimeoutTime, newArgsList)) { + System.exit(0); + } logger.info("Router is configured"); Thread registrationThread = new Thread(REGISTER_UPP); @@ -129,20 +135,6 @@ public class WinLauncher extends CopyConfigDir { } private static void setupLauncher() { - try { - // This block configure the logger with handler and formatter - fh = new FileHandler(logFile().toString()); - logger.addHandler(fh); - SimpleFormatter formatter = new SimpleFormatter(); - fh.setFormatter(formatter); - // the following statement is used to log any messages - logger.info("My first log"); - } catch (SecurityException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - File jrehome = javaHome(); logger.info("jre home is: " + jrehome.getAbsolutePath()); File appimagehome = appImageHome();