Try a way of determining required rights for the installer
This commit is contained in:
@ -10,6 +10,10 @@ public class Elevator {
|
||||
}
|
||||
|
||||
public static void executeAsAdministrator(String command, String args) {
|
||||
if (command == "" || command == null) {
|
||||
System.out.println("No command specified");
|
||||
return;
|
||||
}
|
||||
Shell32X.SHELLEXECUTEINFO execInfo = new Shell32X.SHELLEXECUTEINFO();
|
||||
execInfo.lpFile = new WString(command);
|
||||
if (args != null)
|
||||
|
@ -42,20 +42,29 @@ class WinUpdateProcess implements Runnable {
|
||||
var workingDir = workDir();
|
||||
var logFile = new File(workingDir, "log-" + version + ".txt");
|
||||
|
||||
ProcessBuilder pb = new ProcessBuilder(file.getAbsolutePath());
|
||||
var env = pb.environment();
|
||||
env.put("OLD_I2P_VERSION", version);
|
||||
env.remove("RESTART_I2P");
|
||||
if (logFile.canWrite()) {
|
||||
// check if we can write to the log file. If we can, use the ProcessBuilder to
|
||||
// run the installer.
|
||||
ProcessBuilder pb = new ProcessBuilder(file.getAbsolutePath(), "/S", "/D=" + workingDir.getAbsolutePath());
|
||||
var env = pb.environment();
|
||||
env.put("OLD_I2P_VERSION", version);
|
||||
env.remove("RESTART_I2P");
|
||||
|
||||
int exitCode = ctx.router().scheduledGracefulExitCode();
|
||||
if (exitCode == Router.EXIT_HARD_RESTART || exitCode == Router.EXIT_GRACEFUL_RESTART)
|
||||
env.put("RESTART_I2P", "true");
|
||||
int exitCode = ctx.router().scheduledGracefulExitCode();
|
||||
if (exitCode == Router.EXIT_HARD_RESTART || exitCode == Router.EXIT_GRACEFUL_RESTART)
|
||||
env.put("RESTART_I2P", "true");
|
||||
|
||||
try {
|
||||
pb.directory(workingDir).redirectErrorStream(true).redirectOutput(logFile).start();
|
||||
} catch (IOException ex) {
|
||||
System.out.println("Unable to run update-program in background. Update will fail.");
|
||||
try {
|
||||
pb.directory(workingDir).redirectErrorStream(true).redirectOutput(logFile).start();
|
||||
} catch (IOException ex) {
|
||||
System.out.println("Unable to run update-program in background. Update will fail.");
|
||||
}
|
||||
} else {
|
||||
// If we cant write to the log file and we're on Windows, use the elevator to
|
||||
// execute the installer instead of the ProcessBuilder.
|
||||
Elevator.executeAsAdministrator(file.getAbsolutePath(), " /S /D=" + workingDir.getAbsolutePath());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -43,28 +43,30 @@ public class WindowsUpdatePostProcessor implements UpdatePostProcessor {
|
||||
public void updateDownloadedandVerified(UpdateType type, int fileType, String version, File file)
|
||||
throws IOException {
|
||||
_log.info("Got an update to post-process");
|
||||
if (SystemVersion.isWindows()) {
|
||||
|
||||
if (type != UpdateType.ROUTER_SIGNED_SU3 && type != UpdateType.ROUTER_DEV_SU3) {
|
||||
_log.warn("Unsupported update type " + type);
|
||||
return;
|
||||
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;
|
||||
}
|
||||
|
||||
this.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, this::getFile));
|
||||
}
|
||||
|
||||
if (fileType != SU3File.TYPE_EXE) {
|
||||
_log.warn("Unsupported file type " + fileType);
|
||||
return;
|
||||
}
|
||||
|
||||
this.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, this::getFile));
|
||||
|
||||
}
|
||||
|
||||
private File moveUpdateInstaller(File file) throws IOException {
|
||||
|
Reference in New Issue
Block a user