From 5218f1859932562ba772bfae03ab2ab8f90644c3 Mon Sep 17 00:00:00 2001 From: idk Date: Mon, 2 Aug 2021 17:04:44 -0400 Subject: [PATCH] Make sure working config dir is created. Add Tor Browser support to .bat scripts. Register UPP in a thread, see @zlatinb's example in i2p-jpackage-mac. --- java/net/i2p/router/WinLauncher.java | 68 ++++++++++++------- .../router/WindowsUpdatePostProcessor.java | 2 + src/win/i2pbrowser-private.bat | 33 ++++++--- src/win/i2pbrowser.bat | 25 +++++-- src/win/i2pconfig.bat | 2 +- 5 files changed, 92 insertions(+), 38 deletions(-) diff --git a/java/net/i2p/router/WinLauncher.java b/java/net/i2p/router/WinLauncher.java index 8ab3782..8768699 100644 --- a/java/net/i2p/router/WinLauncher.java +++ b/java/net/i2p/router/WinLauncher.java @@ -9,6 +9,7 @@ import net.i2p.router.Router; import net.i2p.update.UpdateManager; import net.i2p.update.UpdatePostProcessor; import net.i2p.util.SystemVersion; +import net.i2p.update.*; import static net.i2p.update.UpdateType.*; @@ -25,6 +26,12 @@ public class WinLauncher { private static WindowsUpdatePostProcessor wupp = new WindowsUpdatePostProcessor(); public static void main(String[] args) throws Exception { File programs = wupp.selectProgramFile(); + if (!programs.exists()) + programs.mkdirs(); + else if (!programs.isDirectory()) { + System.err.println(programs + " exists but is not a directory. Please get it out of the way"); + System.exit(1); + } File home = selectHome(); if (!home.exists()) @@ -42,19 +49,44 @@ public class WinLauncher { wupp.i2pRouter = new Router(System.getProperties()); System.out.println("Router is configured"); - UpdateManager upmgr = updateManagerClient(); - while (upmgr == null) { - upmgr = updateManagerClient(); - System.out.println("Waiting for update manager so we can pull our own updates"); - } - upmgr.register(wupp, ROUTER_SIGNED_SU3, 6); - System.out.println("Registered signed updates"); - upmgr.register(wupp, ROUTER_DEV_SU3, 6); - System.out.println("Registered dev updates"); + Thread registrationThread = new Thread(REGISTER_UPP); + registrationThread.setName("UPP Registration"); + registrationThread.setDaemon(true); + registrationThread.start(); wupp.i2pRouter.runRouter(); } + private static final Runnable REGISTER_UPP = () -> { + + // first wait for the RouterContext to appear + RouterContext ctx; + while ((ctx = (RouterContext) wupp.i2pRouter.getContext().getCurrentContext()) == null) { + sleep(1000); + } + + // then wait for the update manager + ClientAppManager cam = ctx.clientAppManager(); + UpdateManager um; + while ((um = (UpdateManager) cam.getRegisteredApp(UpdateManager.APP_NAME)) == null) { + sleep(1000); + } + + wupp = new WindowsUpdatePostProcessor(); + um.register(wupp, UpdateType.ROUTER_SIGNED_SU3, 6);//SU3File.TYPE_EXE); + um.register(wupp, UpdateType.ROUTER_DEV_SU3, 6);//SU3File.TYPE_EXE); + }; + + private static void sleep(int millis) { + try { + Thread.sleep(millis); + } catch (InterruptedException bad) { + bad.printStackTrace(); + throw new RuntimeException(bad); + } + } + + private static File selectHome() { //throws Exception { if (SystemVersion.isWindows()) { File home = new File(System.getProperty("user.home")); @@ -62,28 +94,14 @@ public class WinLauncher { File local = new File(appData, "Local"); File i2p; i2p = new File(local, "I2P"); - System.out.println("Windows jpackage wrapper started, using: " + i2p + "as config"); + System.out.println("Windows jpackage wrapper started, using: " + i2p + " as base config"); return i2p.getAbsoluteFile(); } else { File jrehome = new File(System.getProperty("java.home")); File programs = new File(jrehome.getParentFile().getParentFile(), ".i2p"); - System.out.println("Linux portable jpackage wrapper started, using: " + programs + "as config"); + System.out.println("Linux portable jpackage wrapper started, using: " + programs + " as base config"); return programs.getAbsoluteFile(); } } - private static UpdateManager updateManagerClient() { - ClientAppManager clmgr = wupp.i2pRouter.getContext().getCurrentContext().clientAppManager(); - if (clmgr == null) { - return null; - } - - UpdateManager upmgr = (UpdateManager) clmgr.getRegisteredApp(UpdateManager.APP_NAME); - if (upmgr == null) { - return null; - } - - return upmgr; - } - } diff --git a/java/net/i2p/router/WindowsUpdatePostProcessor.java b/java/net/i2p/router/WindowsUpdatePostProcessor.java index 6e74d92..4826c25 100644 --- a/java/net/i2p/router/WindowsUpdatePostProcessor.java +++ b/java/net/i2p/router/WindowsUpdatePostProcessor.java @@ -52,10 +52,12 @@ public class WindowsUpdatePostProcessor implements UpdatePostProcessor { if (SystemVersion.isWindows()) { File jrehome = new File(System.getProperty("java.home")); File programs = jrehome.getParentFile(); + System.out.println("Windows portable jpackage wrapper started, using: " + programs + " as working config"); return programs.getAbsoluteFile(); } else { File jrehome = new File(System.getProperty("java.home")); File programs = new File(jrehome.getParentFile().getParentFile(), "i2p"); + System.out.println("Linux portable jpackage wrapper started, using: " + programs + " as working config"); return programs.getAbsoluteFile(); } } diff --git a/src/win/i2pbrowser-private.bat b/src/win/i2pbrowser-private.bat index 2354be3..8baf4c8 100644 --- a/src/win/i2pbrowser-private.bat +++ b/src/win/i2pbrowser-private.bat @@ -1,15 +1,32 @@ @echo off -start "" "c:\Program Files\I2P\i2p.exe" - -if exist "%LOCALAPPDATA%\I2PBrowser-Launcher\firefox.profile.i2p\" ( - echo "profile is configured" - xcopy /s /i /y "c:\Program Files\I2PBrowser-Launcher\firefox.profile.i2p\extensions" "%LOCALAPPDATA%\I2PBrowser-Launcher\firefox.profile.i2p\extensions" +if exist "%ProgramFiles%\I2P\jpackaged" ( + start /D "%LOCALAPPDATA%\I2P" "%ProgramFiles%\I2P\i2p.exe" ) else ( - echo "configuring profile" - xcopy /s /i /y "c:\Program Files\I2PBrowser-Launcher\firefox.profile.i2p" "%LOCALAPPDATA%\I2PBrowser-Launcher\firefox.profile.i2p" + start "i2p" "%ProgramFiles%\I2P\i2p.exe" ) -start "" "c:\Program Files\Mozilla Firefox\firefox.exe" -no-remote -profile "%LOCALAPPDATA%\I2PBrowser-Launcher\firefox.profile.i2p" -private-window about:blank +if exist "%LOCALAPPDATA%\I2PBrowser-Launcher\firefox.profile.i2p\" ( + echo "profile is configured, updating extensions" + xcopy /s /i /y "%ProgramFiles%\I2PBrowser-Launcher\firefox.profile.i2p\extensions" "%LOCALAPPDATA%\I2PBrowser-Launcher\firefox.profile.i2p\extensions" +) else ( + echo "configuring profile" + xcopy /s /i /y "%ProgramFiles%\I2PBrowser-Launcher\firefox.profile.i2p" "%LOCALAPPDATA%\I2PBrowser-Launcher\firefox.profile.i2p" +) + +if exist "%USERPROFILE%/Desktop/Tor Browser/Browser/firefox.exe" ( + start "i2pbrowser" "%USERPROFILE%/Desktop/Tor Browser/Browser/firefox.exe" -no-remote -profile "%LOCALAPPDATA%\I2PBrowser-Launcher\firefox.profile.i2p" -private-window about:blank + exit +) + +if exist "%USERPROFILE%/OneDrive/Desktop/Tor Browser/Browser/firefox.exe" ( + start "i2pbrowser" "%USERPROFILE%/OneDrive/Desktop/Tor Browser/Browser/firefox.exe" -no-remote -profile "%LOCALAPPDATA%\I2PBrowser-Launcher\firefox.profile.i2p" -private-window about:blank + exit +) + +if exist "%ProgramFiles%\Mozilla Firefox\firefox.exe" ( + start "i2pbrowser" "%ProgramFiles%\Mozilla Firefox\firefox.exe" -no-remote -profile "%LOCALAPPDATA%\I2PBrowser-Launcher\firefox.profile.i2p" -private-window about:blank + exit +) exit diff --git a/src/win/i2pbrowser.bat b/src/win/i2pbrowser.bat index a05a3c4..1c0b437 100644 --- a/src/win/i2pbrowser.bat +++ b/src/win/i2pbrowser.bat @@ -1,15 +1,32 @@ @echo off -start "" "c:\Program Files\I2P\i2p.exe" +if exist "%ProgramFiles%\I2P\jpackaged" ( + start "i2p" /D "%LOCALAPPDATA%\I2P" "%ProgramFiles%\I2P\i2p.exe" +) else ( + start "i2p" "%ProgramFiles%\I2P\i2p.exe" +) if exist "%LOCALAPPDATA%\I2PBrowser-Launcher\firefox.profile.i2p\" ( echo "profile is configured, updating extensions" - xcopy /s /i /y "c:\Program Files\I2PBrowser-Launcher\firefox.profile.i2p\extensions" "%LOCALAPPDATA%\I2PBrowser-Launcher\firefox.profile.i2p\extensions" + xcopy /s /i /y "%ProgramFiles%\I2PBrowser-Launcher\firefox.profile.i2p\extensions" "%LOCALAPPDATA%\I2PBrowser-Launcher\firefox.profile.i2p\extensions" ) else ( echo "configuring profile" - xcopy /s /i /y "c:\Program Files\I2PBrowser-Launcher\firefox.profile.i2p" "%LOCALAPPDATA%\I2PBrowser-Launcher\firefox.profile.i2p" + xcopy /s /i /y "%ProgramFiles%\I2PBrowser-Launcher\firefox.profile.i2p" "%LOCALAPPDATA%\I2PBrowser-Launcher\firefox.profile.i2p" ) -start "" "c:\Program Files\Mozilla Firefox\firefox.exe" -no-remote -profile "%LOCALAPPDATA%\I2PBrowser-Launcher\firefox.profile.i2p" -url %1 +if exist "%USERPROFILE%/Desktop/Tor Browser/Browser/firefox.exe" ( + start "i2pbrowser" "%USERPROFILE%/Desktop/Tor Browser/Browser/firefox.exe" -no-remote -profile "%LOCALAPPDATA%\I2PBrowser-Launcher\firefox.profile.i2p" -url %1 + exit +) + +if exist "%USERPROFILE%/OneDrive/Desktop/Tor Browser/Browser/firefox.exe" ( + start "i2pbrowser" "%USERPROFILE%/OneDrive/Desktop/Tor Browser/Browser/firefox.exe" -no-remote -profile "%LOCALAPPDATA%\I2PBrowser-Launcher\firefox.profile.i2p" -url %1 + exit +) + +if exist "%ProgramFiles%\Mozilla Firefox\firefox.exe" ( + start "i2pbrowser" "%ProgramFiles%\Mozilla Firefox\firefox.exe" -no-remote -profile "%LOCALAPPDATA%\I2PBrowser-Launcher\firefox.profile.i2p" -url %1 + exit +) exit diff --git a/src/win/i2pconfig.bat b/src/win/i2pconfig.bat index 8edf349..17a4f2a 100644 --- a/src/win/i2pconfig.bat +++ b/src/win/i2pconfig.bat @@ -8,6 +8,6 @@ if exist "%LOCALAPPDATA%\I2PBrowser-Launcher\firefox.profile.config.i2p\" ( xcopy /s /i /y "$INSTDIR\firefox.profile.config.i2p" "%LOCALAPPDATA%\I2PBrowser-Launcher\firefox.profile.config.i2p" ) -start "" "c:\Program Files\Mozilla Firefox\firefox.exe" -no-remote -profile "%LOCALAPPDATA%\I2PBrowser-Launcher\firefox.profile.config.i2p" -url %1 +start "i2pconfig" "c:\Program Files\Mozilla Firefox\firefox.exe" -no-remote -profile "%LOCALAPPDATA%\I2PBrowser-Launcher\firefox.profile.config.i2p" -url %1 exit