From bf89c119a7eae410f5d6d39ec7201fe17c94aeac Mon Sep 17 00:00:00 2001 From: eyedeekay Date: Fri, 8 Mar 2024 18:44:24 -0500 Subject: [PATCH] start getting rid of CCD --- buildscripts/launcher.sh | 1 + java/net/i2p/router/CopyConfigDir.java | 173 ++---------------------- java/net/i2p/router/WinLauncher.java | 30 ++-- java/net/i2p/router/WindowsAppUtil.java | 156 +++++++++++++++++++++ 4 files changed, 180 insertions(+), 180 deletions(-) create mode 100644 java/net/i2p/router/WindowsAppUtil.java diff --git a/buildscripts/launcher.sh b/buildscripts/launcher.sh index 5b4a6cb..d87315d 100755 --- a/buildscripts/launcher.sh +++ b/buildscripts/launcher.sh @@ -124,6 +124,7 @@ cd "$SCRIPT_DIR"/java "$JAVA_HOME"/bin/javac -Xlint:deprecation -d ../build -classpath "$SCRIPT_DIR/build/i2pfirefox.jar:$SCRIPT_DIR/build/jna.jar:$SCRIPT_DIR/build/jna-platform.jar":"$SCRIPT_DIR/build/i2p.jar:$SCRIPT_DIR/build/router.jar:$SCRIPT_DIR/build/routerconsole.jar:$SCRIPT_DIR/build/jbigi.jar" \ net/i2p/router/CopyConfigDir.java \ net/i2p/router/WindowsServiceUtil.java \ + net/i2p/router/WindowsAppUtil.java \ net/i2p/router/WindowsUpdatePostProcessor.java \ net/i2p/router/WinLauncher.java \ net/i2p/router/WinUpdateProcess.java \ diff --git a/java/net/i2p/router/CopyConfigDir.java b/java/net/i2p/router/CopyConfigDir.java index d54a3a8..35b2da7 100644 --- a/java/net/i2p/router/CopyConfigDir.java +++ b/java/net/i2p/router/CopyConfigDir.java @@ -9,26 +9,14 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.logging.FileHandler; -import java.util.logging.Logger; import java.util.logging.SimpleFormatter; +import net.i2p.util.Log; public class CopyConfigDir extends WindowsServiceUtil { - final Logger logger = Logger.getLogger("configlog"); + final Log logger; - public void initLogger() { - try { - // This block configure the logger with handler and formatter - FileHandler 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(); - } + public CopyConfigDir(RouterContext ctx) { + logger = ctx.logManager().getLog(CopyConfigDir.class); } public boolean copyDirectory(String baseDir, String workDir) { @@ -73,7 +61,7 @@ public class CopyConfigDir extends WindowsServiceUtil { try { jpackagedConfigsInUse.createNewFile(); } catch (IOException e) { - logger.warning( + logger.warn( "Error creating jpackaged file, delete config files manually when uninstalling"); } } @@ -128,164 +116,19 @@ public class CopyConfigDir extends WindowsServiceUtil { out.close(); return 1; } catch (Throwable e) { - logger.warning(e.toString()); - logger.warning("failed to copy " + basePath.getAbsolutePath() + " to " + - workPath.getAbsolutePath()); + logger.warn(e.toString()); + logger.warn("failed to copy " + basePath.getAbsolutePath() + " to " + + workPath.getAbsolutePath()); return 0; } } - protected File selectHome() { // throws Exception { - String path_override = System.getenv("I2P_CONFIG"); - if (path_override != null) { - File path = new File(path_override); - if (path != null && path.exists()) { - if (path.isDirectory()) - return path.getAbsoluteFile(); - else - throw new RuntimeException("I2P_CONFIG is not a directory: " + path); - } - } - File i2p = appImageHome(); - logger.info("Checking for signs of life in I2P_CONFIG directory: " + i2p); - return i2p; - } - - protected File selectProgramFile() { - String path_override = System.getenv("I2P"); - if (path_override != null) { - File path = new File(path_override); - if (path.exists()) { - if (path.isDirectory()) - return path.getAbsoluteFile(); - else - throw new RuntimeException("I2P is not a directory: " + path); - } - } - File i2p = appImageHome(); - logger.info("Checking for signs of life in I2P directory: " + i2p); - return i2p; - } - - /** - * get the path to the java home, for jpackage this is related to the - * executable itself, which is handy to know. It's a directory called runtime, - * relative to the root of the app-image on each platform: - * - * Windows - Root of appimage is 1 directory above directory named runtime - * ./runtime - * - * Linux - Root of appimage is 2 directories above directory named runtime - * ./lib/runtime - * - * Mac OSX - Unknown for now - * - * @return - */ - protected File javaHome() { - File jrehome = new File(System.getProperty("java.home")); - if (jrehome != null) { - if (jrehome.exists()) { - return jrehome; - } - } - return null; - } - - /** - * get the path to the root 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. - * - * @return the app-image root - */ - protected File appImageHome() { - File jreHome = javaHome(); - if (jreHome != null) { - switch (osName()) { - case "windows": - return jreHome.getAbsoluteFile().getParentFile(); - case "mac": - case "linux": - return jreHome.getAbsoluteFile().getParentFile().getParentFile(); - } - } - 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 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 - * information, then appending the config directory to the end onn a - * per-platform basis - * - * @return the app-image root - */ - protected File appImageConfig() { - File aih = appImageHome(); - if (aih == null) { - return null; - } - String osName = osName(); - switch (osName) { - case "windows": - File winConfigDir = new File(aih, "config"); - if (winConfigDir != null) { - if (winConfigDir.exists()) { - return winConfigDir; - } - } - case "mac": - case "linux": - File linConfigDir = new File(aih, "lib/config"); - if (linConfigDir != null) { - if (linConfigDir.exists()) { - return linConfigDir; - } - } - } - return null; - } - protected boolean copyConfigDir() { File appImageConfigDir = appImageConfig(); File appImageHomeDir = selectHome(); return copyConfigDirectory(appImageConfigDir, appImageHomeDir); } - protected String routerConfig() { - File appImageHomeDir = selectHome(); - 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 f8da851..9452d86 100644 --- a/java/net/i2p/router/WinLauncher.java +++ b/java/net/i2p/router/WinLauncher.java @@ -5,18 +5,14 @@ import java.net.InetAddress; import java.net.ServerSocket; import java.net.Socket; import java.util.*; -import java.util.logging.FileHandler; -import java.util.logging.Logger; -import java.util.logging.SimpleFormatter; import net.i2p.app.ClientAppManager; import net.i2p.crypto.*; -//import net.i2p.i2pfirefox.*; import net.i2p.router.Router; import net.i2p.router.RouterLaunch; import net.i2p.update.*; import net.i2p.update.UpdateManager; -import net.i2p.update.UpdatePostProcessor; import net.i2p.update.UpdateType.*; +import net.i2p.util.Log; /** * Launches a router from %WORKINGDIR%/I2P using configuration data in @@ -28,14 +24,20 @@ import net.i2p.update.UpdateType.*; * appdata * router.pid - the pid of the java process. */ -public class WinLauncher extends CopyConfigDir { +public class WinLauncher extends WindowsServiceUtil { + private final CopyConfigDir copyConfigDir; WindowsUpdatePostProcessor wupp = null; - private Router i2pRouter; + private final Router i2pRouter; + final Log logger; + public WinLauncher() { + i2pRouter = new Router(routerConfig(), System.getProperties()); + copyConfigDir = new CopyConfigDir(i2pRouter.getContext()); + logger = i2pRouter.getContext().logManager().getLog(WinLauncher.class); + } public static void main(String[] args) { var launcher = new WinLauncher(); launcher.setupLauncher(); - launcher.initLogger(); int proxyTimeoutTime = 200; ArrayList newArgsList = new ArrayList(); @@ -101,25 +103,23 @@ public class WinLauncher extends CopyConfigDir { launcher.logger.info("\t" + System.getProperty("router.pid")); boolean continuerunning = launcher.promptServiceStartIfAvailable("i2p"); if (!continuerunning) { - launcher.logger.severe( + launcher.logger.error( "Service startup failure, please start I2P service with services.msc"); System.exit(2); } continuerunning = launcher.promptUserInstallStartIfAvailable(); if (!continuerunning) { - launcher.logger.severe("User-install startup required."); + launcher.logger.error("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 (!launcher.copyConfigDir()) { - launcher.logger.severe("Cannot copy the configuration directory"); + launcher.logger.error("Cannot copy the configuration directory"); System.exit(1); } - launcher.i2pRouter = - new Router(launcher.routerConfig(), System.getProperties()); if (!launcher.isInstalled("i2p")) { if (launcher.i2pRouter.saveConfig("routerconsole.browser", null)) { launcher.logger.info("removed routerconsole.browser config"); @@ -155,7 +155,7 @@ public class WinLauncher extends CopyConfigDir { if (!programs.exists()) programs.mkdirs(); else if (!programs.isDirectory()) { - logger.warning( + logger.warn( programs + " exists but is not a directory. Please get it out of the way"); System.exit(1); @@ -168,7 +168,7 @@ public class WinLauncher extends CopyConfigDir { if (!home.exists()) home.mkdirs(); else if (!home.isDirectory()) { - logger.warning( + logger.warn( home + " exists but is not a directory. Please get it out of the way"); System.exit(1); diff --git a/java/net/i2p/router/WindowsAppUtil.java b/java/net/i2p/router/WindowsAppUtil.java new file mode 100644 index 0000000..5d609e6 --- /dev/null +++ b/java/net/i2p/router/WindowsAppUtil.java @@ -0,0 +1,156 @@ +package net.i2p.router; + +import java.io.File; +import net.i2p.util.Log; + +public class WindowsAppUtil extends WindowsServiceUtil { + final Log logger; + public WindowsAppUtil(RouterContext ctx) { + super(); + logger = ctx.logManager().getLog(WindowsAppUtil.class); + } + protected File selectHome() { // throws Exception { + String path_override = System.getenv("I2P_CONFIG"); + if (path_override != null) { + File path = new File(path_override); + if (path != null && path.exists()) { + if (path.isDirectory()) + return path.getAbsoluteFile(); + else + throw new RuntimeException("I2P_CONFIG is not a directory: " + path); + } + } + File i2p = appImageHome(); + logger.info("Checking for signs of life in I2P_CONFIG directory: " + i2p); + return i2p; + } + + protected File selectProgramFile() { + String path_override = System.getenv("I2P"); + if (path_override != null) { + File path = new File(path_override); + if (path.exists()) { + if (path.isDirectory()) + return path.getAbsoluteFile(); + else + throw new RuntimeException("I2P is not a directory: " + path); + } + } + File i2p = appImageHome(); + logger.info("Checking for signs of life in I2P directory: " + i2p); + return i2p; + } + + /** + * get the path to the java home, for jpackage this is related to the + * executable itself, which is handy to know. It's a directory called runtime, + * relative to the root of the app-image on each platform: + * + * Windows - Root of appimage is 1 directory above directory named runtime + * ./runtime + * + * Linux - Root of appimage is 2 directories above directory named runtime + * ./lib/runtime + * + * Mac OSX - Unknown for now + * + * @return + */ + protected File javaHome() { + File jrehome = new File(System.getProperty("java.home")); + if (jrehome != null) { + if (jrehome.exists()) { + return jrehome; + } + } + return null; + } + + /** + * get the path to the root 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. + * + * @return the app-image root + */ + protected File appImageHome() { + File jreHome = javaHome(); + if (jreHome != null) { + switch (osName()) { + case "windows": + return jreHome.getAbsoluteFile().getParentFile(); + case "mac": + case "linux": + return jreHome.getAbsoluteFile().getParentFile().getParentFile(); + } + } + 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 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 + * information, then appending the config directory to the end onn a + * per-platform basis + * + * @return the app-image root + */ + protected File appImageConfig() { + File aih = appImageHome(); + if (aih == null) { + return null; + } + String osName = osName(); + switch (osName) { + case "windows": + File winConfigDir = new File(aih, "config"); + if (winConfigDir != null) { + if (winConfigDir.exists()) { + return winConfigDir; + } + } + case "mac": + case "linux": + File linConfigDir = new File(aih, "lib/config"); + if (linConfigDir != null) { + if (linConfigDir.exists()) { + return linConfigDir; + } + } + } + return null; + } + + protected String routerConfig() { + File appImageHomeDir = selectHome(); + File routerConf = new File(appImageHomeDir, "router.config"); + if (routerConf != null) { + if (routerConf.exists()) { + return routerConf.getAbsolutePath(); + } + } + return null; + } +}