Fixes for many, but not all the things from zab's code review

This commit is contained in:
idk
2021-08-14 02:08:45 -04:00
parent ac7336f669
commit 688b9ca309
5 changed files with 69 additions and 23 deletions

View File

@@ -49,7 +49,7 @@ I2P:
build/I2P: build
rm -rf build/I2P
cp -rv I2P build/I2P ; true
cp "$(I2P_JBIGI)"/*windows*.dll build/I2P/runtime/lib
cp "$(I2P_JBIGI)"/*windows*.dll build/I2P/runtime/lib; true
configdir: src/I2P/config

View File

@@ -39,7 +39,7 @@ mkdir build
cp "$I2P_JARS"/*.jar build
cd java
"$JAVA_HOME"/bin/javac -d ../build -classpath "$HERE"/build/i2p.jar:"$HERE"/build/router.jar:"$HERE"/build/routerconsole.jar net/i2p/router/WinLauncher.java net/i2p/router/WindowsUpdatePostProcessor.java
"$JAVA_HOME"/bin/javac -d ../build -classpath "$HERE"/build/i2p.jar:"$HERE"/build/router.jar:"$HERE"/build/routerconsole.jar net/i2p/router/WinLauncher.java net/i2p/router/WindowsUpdatePostProcessor.java net/i2p/router/WinUpdateProcess.java
cd ..
#echo "building launcher.jar"

View File

@@ -3,6 +3,8 @@ package net.i2p.router;
import java.io.*;
import java.util.*;
import net.i2p.crypto.*;
import net.i2p.app.ClientAppManager;
import net.i2p.router.RouterLaunch;
import net.i2p.router.Router;
@@ -72,9 +74,9 @@ public class WinLauncher {
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);
wupp = new WindowsUpdatePostProcessor(ctx);
um.register(wupp, UpdateType.ROUTER_SIGNED_SU3, SU3File.TYPE_EXE);
um.register(wupp, UpdateType.ROUTER_DEV_SU3, SU3File.TYPE_EXE);
};
private static void sleep(int millis) {

View File

@@ -3,7 +3,10 @@ package net.i2p.router;
import java.io.*;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.*;
import net.i2p.crypto.*;
import static net.i2p.update.UpdateType.*;
import net.i2p.I2PAppContext;
import net.i2p.update.UpdateType;
@@ -18,36 +21,77 @@ import java.lang.InterruptedException;
public class WindowsUpdatePostProcessor implements UpdatePostProcessor {
private final Log _log = I2PAppContext.getGlobalContext().logManager().getLog(WindowsUpdatePostProcessor.class);
private final RouterContext ctx;
protected static Router i2pRouter = null;
public void updateDownloadedandVerified(UpdateType type, int fileType, String version, File file) throws IOException {
if (fileType == 6) {
File newFile = moveUpdateInstaller(file);
runUpdateInstaller(newFile);
}
private final AtomicBoolean hook = new AtomicBoolean();
private volatile String version;
WindowsUpdatePostProcessor() {
this.ctx = null;
}
private File moveUpdateInstaller(File file){
WindowsUpdatePostProcessor(RouterContext ctx) {
this.ctx = ctx;
}
public String getVersion() {
return version;
}
public void updateDownloadedandVerified(UpdateType type, int fileType, String version, File file) throws IOException {
_log.info("Got an update to post-process");
if (type != UpdateType.ROUTER_SIGNED_SU3 && type != UpdateType.ROUTER_DEV_SU3) {
_log.warn("Unsupported update type " + type);
return;
}
if (fileType != SU3File.TYPE_EXE) {
_log.warn("Unsupported file type " + fileType);
return;
}
File positionedFile = moveUpdateInstaller(file);
this.version = version;
if (!hook.compareAndSet(false,true)) {
_log.info("shutdown hook was already set");
return;
}
_log.info("adding shutdown hook");
ctx.addFinalShutdownTask(new WinUpdateProcess(ctx, this::getVersion, positionedFile));
}
private File moveUpdateInstaller(File file) throws IOException{
RouterContext i2pContext = i2pRouter.getContext();
if (i2pContext != null) {
File appDir = i2pContext.getAppDir();
File newFile = new File(i2pContext.getAppDir().getAbsolutePath(), file.getName());
File newFile = new File(workDir(), file.getName());
file.renameTo(newFile);
return newFile;
}
return null;
}
private void runUpdateInstaller(File file){
ProcessBuilder pb = new ProcessBuilder("cmd", "/c", file.getAbsolutePath(), "/S");
try {
pb.start();
} catch (IOException ex) {
if (_log.shouldWarn())
_log.warn("Unable to loop update-program in background. Update will fail.");
private File workDir() throws IOException{
RouterContext i2pContext = i2pRouter.getContext();
if (i2pContext != null) {
File workDir = new File(i2pContext.getAppDir().getAbsolutePath(), "i2p_update_win");
if (workDir.exists()) {
if (workDir.isFile())
throw new IOException(workDir + " exists but is a file, get it out of the way");
return null;
} else {
workDir.mkdirs();
}
return workDir;
}
return null;
}
protected File selectProgramFile() {
if (SystemVersion.isWindows()) {
File jrehome = new File(System.getProperty("java.home"));

View File

@@ -215,9 +215,9 @@ Function routerDetect
SetOutPath "$I2PINSTEXE\certificates\"
File /nonfatal /a /r "I2P\config\certificates\"
createDirectory "$I2PINSTEXE\certificates\"
SetOutPath "$I2PINSTEXE\certificates\"
File /nonfatal /a /r "I2P\config\certificates\"
createDirectory "$I2PINSTEXE\eepsite\"
SetOutPath "$I2PINSTEXE\eepsite\"
File /nonfatal /a /r "I2P\config\eepsite\"
Abort directory
${EndIf}