From f4f7935cdc38e8d5e65cf0c6712cf735192fc74c Mon Sep 17 00:00:00 2001 From: idk Date: Mon, 19 Sep 2022 23:46:34 -0400 Subject: [PATCH] fix the router.config file for the user if they installed un-bundled after bundled --- java/net/i2p/router/WinLauncher.java | 76 +++++++++++++++------ java/net/i2p/router/WindowsServiceUtil.java | 51 +++++++++----- 2 files changed, 90 insertions(+), 37 deletions(-) diff --git a/java/net/i2p/router/WinLauncher.java b/java/net/i2p/router/WinLauncher.java index d0a268b..43bafcb 100644 --- a/java/net/i2p/router/WinLauncher.java +++ b/java/net/i2p/router/WinLauncher.java @@ -88,25 +88,6 @@ public class WinLauncher extends CopyConfigDir { File programs = programFile(); File home = homeDir(); - boolean continuerunning = promptServiceStartIfAvailable("i2p"); - if (!continuerunning) { - logger.severe( - "Service startup failure, please start I2P service with services.msc"); - System.exit(2); - } - continuerunning = promptUserInstallStartIfAvailable(); - if (!continuerunning) { - logger.severe("User-install startup required."); - System.exit(2); - } - - // This actually does most of what we use NSIS for if NSIS hasn't - // already done it, which essentially makes this whole thing portable. - if (!copyConfigDir()) { - logger.severe("Cannot copy the configuration directory"); - System.exit(1); - } - System.setProperty("i2p.dir.base", programs.getAbsolutePath()); System.setProperty("i2p.dir.config", home.getAbsolutePath()); System.setProperty("router.pid", @@ -122,6 +103,29 @@ public class WinLauncher extends CopyConfigDir { logger.info("\t" + System.getProperty("i2p.dir.base")); logger.info("\t" + System.getProperty("i2p.dir.config")); logger.info("\t" + System.getProperty("router.pid")); + boolean continuerunning = promptServiceStartIfAvailable("i2p"); + if (!continuerunning) { + logger.severe( + "Service startup failure, please start I2P service with services.msc"); + System.exit(2); + } else { + fixServiceConfig(); + } + continuerunning = promptUserInstallStartIfAvailable(); + if (!continuerunning) { + logger.severe("User-install startup required."); + System.exit(2); + } else { + fixServiceConfig(); + } + + // This actually does most of what we use NSIS for if NSIS hasn't + // already done it, which essentially makes this whole thing portable. + if (!copyConfigDir()) { + logger.severe("Cannot copy the configuration directory"); + System.exit(1); + } + if (launchBrowser(privateBrowsing, usabilityMode, chromiumFirst, proxyTimeoutTime, newArgsList)) { System.exit(0); @@ -148,6 +152,40 @@ public class WinLauncher extends CopyConfigDir { i2pRouter.runRouter(); } + private static void fixServiceConfig() { + // If the user installed the Easy bundle before installing the + // regulalr bundle, then they have a config file which contains the + // wrong update URL. Check for it, and change it back if necessary. + i2pRouter = new Router(routerConfig(), System.getProperties()); + if (isInstalled("i2p") || checkProgramFilesInstall()) { + if (i2pRouter.getConfig("router.newsURL").contains("win/beta")) { + logger.info( + "checked router.newsURL config, containes win/beta in a service install, invalid update type"); + if (i2pRouter.saveConfig("router.newsURL", ServiceUpdaterString())) { + logger.info("updated routerconsole.browser config " + appImageExe()); + } + } + if (i2pRouter.getConfig("router.backupNewsURL").contains("win/beta")) { + logger.info( + "checked router.backupNewsURL config, containes win/beta in a service install, invalid update type"); + if (i2pRouter.saveConfig("router.backupNewsURL", + ServiceUpdaterString())) { + logger.info("updated routerconsole.browser config " + appImageExe()); + } + } + String updateURL = i2pRouter.getConfig("router.updateURL") + if (updateURL + .contains("i2pwinupdate.su3")) { + logger.info( + "checked router.updateURL config, containes win/beta in a service install, invalid update type"); + if (i2pRouter.saveConfig("router.updateURL", + ServerStaticUpdaterString())) { + logger.info("updated routerconsole.browser config " + appImageExe()); + } + } + } + } + private static void setupLauncher() { File jrehome = javaHome(); logger.info("jre home is: " + jrehome.getAbsolutePath()); diff --git a/java/net/i2p/router/WindowsServiceUtil.java b/java/net/i2p/router/WindowsServiceUtil.java index e72d54a..6788889 100644 --- a/java/net/i2p/router/WindowsServiceUtil.java +++ b/java/net/i2p/router/WindowsServiceUtil.java @@ -131,16 +131,17 @@ public class WindowsServiceUtil { // user can start the service themselves. OR maybe we ask for // elevation here? May need to refactor Elevator and Shell32X to // achieve it though - ProcessBuilder pb = new ProcessBuilder("C:\\Windows\\System32\\services.msc"); - try{ + ProcessBuilder pb = + new ProcessBuilder("C:\\Windows\\System32\\services.msc"); + try { Process p = pb.start(); int exitCode = p.waitFor(); - if (exitCode != 0){ + if (exitCode != 0) { return false; } - }catch(IOException e){ + } catch (IOException e) { return false; - }catch(InterruptedException e){ + } catch (InterruptedException e) { return false; } } @@ -154,27 +155,39 @@ public class WindowsServiceUtil { public static String ServiceUpdaterString() { return "http://tc73n4kivdroccekirco7rhgxdg5f3cjvbaapabupeyzrqwv5guq.b32.i2p/news.su3"; } + public static String ServiceStaticUpdaterString() { + return "http://echelon.i2p/i2p/i2pupdate.sud,http://stats.i2p/i2p/i2pupdate.sud"; + } public static String getProgramFilesInstall() { String programFiles = System.getenv("PROGRAMFILES"); - File programFilesI2P = new File(programFiles, "i2p/i2p.exe"); - if (programFilesI2P.exists()) - return programFilesI2P.getAbsolutePath(); + if (programFiles != null) { + File programFilesI2P = new File(programFiles, "i2p/i2p.exe"); + if (programFilesI2P.exists()) + return programFilesI2P.getAbsolutePath(); + } String programFiles86 = System.getenv("PROGRAMFILES86"); - File programFiles86I2P = new File(programFiles86, "i2p/i2p.exe"); - if (programFiles86I2P.exists()) - return programFiles86I2P.getAbsolutePath(); + if (programFiles86 != null) { + File programFiles86I2P = new File(programFiles86, "i2p/i2p.exe"); + if (programFiles86I2P.exists()) + return programFiles86I2P.getAbsolutePath(); + } + return null; } public static boolean checkProgramFilesInstall() { String programFiles = System.getenv("PROGRAMFILES"); - File programFilesI2P = new File(programFiles, "i2p/i2p.exe"); - if (programFilesI2P.exists()) - return true; + if (programFiles != null) { + File programFilesI2P = new File(programFiles, "i2p/i2p.exe"); + if (programFilesI2P.exists()) + return true; + } String programFiles86 = System.getenv("PROGRAMFILES86"); - File programFiles86I2P = new File(programFiles86, "i2p/i2p.exe"); - if (programFiles86I2P.exists()) - return true; + if (programFiles86 != null) { + File programFiles86I2P = new File(programFiles86, "i2p/i2p.exe"); + if (programFiles86I2P.exists()) + return true; + } return false; } @@ -198,7 +211,9 @@ public class WindowsServiceUtil { return true; } else { try { - Runtime.getRuntime().exec(getProgramFilesInstall()); + String pfi = getProgramFilesInstall(); + if (pfi != null) + Runtime.getRuntime().exec(pfi); } catch (IOException e) { return false; }