From 6165131c66d8894db89e3e5304be9eff4df0cc14 Mon Sep 17 00:00:00 2001 From: idk Date: Sat, 3 Jul 2021 22:39:54 -0400 Subject: [PATCH] When a Silent installer is run, loop until there isn't an I2P.exe process anymore. --- Makefile | 3 + java/net/i2p/router/WinLauncher.java | 9 +- .../router/WindowsUpdatePostProcessor.java | 2 +- src/nsis/FindProcess.nsh | 122 ++++++++++++++++++ src/nsis/i2pbrowser-installer.nsi | 8 ++ 5 files changed, 138 insertions(+), 6 deletions(-) create mode 100644 src/nsis/FindProcess.nsh diff --git a/Makefile b/Makefile index fe19f0a..5dac399 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,9 @@ install.exe: prep export RES_DIR="../i2p.i2p/installer/resources" export PKG_DIR="../i2p.i2p/pkg-temp" +distclean: clean + rm -rf I2P + I2P: ./build.sh diff --git a/java/net/i2p/router/WinLauncher.java b/java/net/i2p/router/WinLauncher.java index b38cb8b..972a997 100644 --- a/java/net/i2p/router/WinLauncher.java +++ b/java/net/i2p/router/WinLauncher.java @@ -42,12 +42,11 @@ public class WinLauncher extends WindowsUpdatePostProcessor { i2pRouter = new Router(System.getProperties()); UpdateManager upmgr = updateManagerClient(); - if (upmgr != null) { - upmgr.register(this, ROUTER_SIGNED_SU3, 6); - upmgr.register(this, ROUTER_DEV_SU3, 6); - }else{ - System.out.println("\t unable to register updates"); + while (upmgr == null) { + System.out.println("Waiting for update manager so we can pull our own updates");; } + upmgr.register(this, ROUTER_SIGNED_SU3, 6); + upmgr.register(this, ROUTER_DEV_SU3, 6); i2pRouter.runRouter(); } diff --git a/java/net/i2p/router/WindowsUpdatePostProcessor.java b/java/net/i2p/router/WindowsUpdatePostProcessor.java index 6f169bf..79c53c5 100644 --- a/java/net/i2p/router/WindowsUpdatePostProcessor.java +++ b/java/net/i2p/router/WindowsUpdatePostProcessor.java @@ -82,7 +82,7 @@ public class WindowsUpdatePostProcessor implements UpdatePostProcessor { } protected File selectProgramFileExe() { - File pfpath = selectProgramFile(); + File pfpath = selectProgramFile(); if (SystemVersion.isWindows()) { File app = new File(pfpath, "I2P.exe"); return app.getAbsoluteFile(); diff --git a/src/nsis/FindProcess.nsh b/src/nsis/FindProcess.nsh new file mode 100644 index 0000000..7020bd2 --- /dev/null +++ b/src/nsis/FindProcess.nsh @@ -0,0 +1,122 @@ +/* FindProcess.nsh +* +* written by Donald Miller +* Mar 7, 2007 +* +*/ + +!include LogicLib.nsh +!include WordFunc.nsh +!insertmacro WordFind + +!ifndef FindProcess +!define FindProcess '!insertmacro FindProcess' + +!macro FindProcess ProcessList BoolReturn + Push '${ProcessList}' + Call FindProcess + Pop ${BoolReturn} +!macroend + +Function FindProcess + # return True if any process in ProcessList is active + Exch $0 ; get ProcessList, save $0 + Push $1 + Push $2 + Push $R0 + Push $R1 + Push $R2 + + StrCpy $2 "$0," ; $2 = ProcessList + + Push 0 ; set return value = False + + # method based upon one by Phoenix1701@gmail.com 1/27/07 + + System::Alloc 1024 + Pop $R0 ; process list buffer + + # get an array of all process ids + System::Call "Psapi::EnumProcesses(i R0, i 1024, *i .R1)i .r0" + ${Unless} $0 = 0 + + IntOp $R1 $R1 / 4 ; Divide by sizeof(DWORD) to get $R1 process count + IntOp $R1 $R1 - 1 ; decr for 0 base loop + + ClearErrors + ${For} $R2 0 $R1 + # get a PID from the array + IntOp $0 $R2 << 2 + IntOp $0 $0 + $R0 ; buffer.dword[i] + System::Call "*$0(i .r0)" ; Get next PID + + ${Unless} $0 = 0 + Push $0 + Call GetProcessName + Pop $1 + + # is this process one we are looking for? + ${WordFind} '$2' ',' 'E/$1' $0 + ${Unless} ${Errors} + # yes, change return value + Pop $0 ; discard old result + Push 1 ; set return True + + # exit the loop + ${Break} + ${EndUnless} + ${EndUnless} + ${Next} + + ${EndUnless} + + System::Free $R0 + + Pop $0 ; get return value + Pop $R2 ; restore registers + Pop $R1 + Pop $R0 + Pop $2 + Pop $1 + Exch $0 +FunctionEnd + +Function GetProcessName + # ( Pid -- ProcessName ) + Exch $2 ; get Pid, save $2 + Push $0 + Push $1 + Push $3 + Push $R0 + + System::Call "Kernel32::OpenProcess(i 1040, i 0, i r2)i .r3" + + StrCpy $2 "" ; set return value + + ${Unless} $3 = 0 ; $3 is hProcess + # get hMod array + System::Alloc 1024 + Pop $R0 + + # params: Pid, &hMod, sizeof(hMod), &cb + System::Call "Psapi::EnumProcessModules(i r3, i R0, i 1024, *i .r1)i .r0" + + ${Unless} $0 = 0 + # get first hMod + System::Call "*$R0(i .r0)" + + # get BaseName; params: Pid, hMod, szBuffer, sizeof(szBuffer) + System::Call "Psapi::GetModuleBaseName(i r3, i r0, t .r2, i 256)i .r0" + ${EndUnless} + + System::Free $R0 + System::Call "kernel32::CloseHandle(i r3)" + ${EndUnless} + + Pop $R0 ; restore registers + Pop $3 + Pop $1 + Pop $0 + Exch $2 ; save process name +FunctionEnd +!endif \ No newline at end of file diff --git a/src/nsis/i2pbrowser-installer.nsi b/src/nsis/i2pbrowser-installer.nsi index 7e8e0a6..b1ba5ea 100644 --- a/src/nsis/i2pbrowser-installer.nsi +++ b/src/nsis/i2pbrowser-installer.nsi @@ -11,6 +11,7 @@ UniCode true !define CONSOLE_URL "http://127.0.0.1:7657/home" !include i2pbrowser-version.nsi +!include FindProcess.nsh var FFINSTEXE var FFNONTORINSTEXE @@ -221,6 +222,13 @@ FunctionEnd # start default section Section Install + ${If} ${Silent} + ${Do} + ${FindProcess} "I2P.exe" $0 + Sleep 500 + ${LoopWhile} $0 <> 0 + ${EndIf} + # set the installation directory as the destination for the following actions createDirectory $INSTDIR SetOutPath $INSTDIR