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) {
|
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();
|
Shell32X.SHELLEXECUTEINFO execInfo = new Shell32X.SHELLEXECUTEINFO();
|
||||||
execInfo.lpFile = new WString(command);
|
execInfo.lpFile = new WString(command);
|
||||||
if (args != null)
|
if (args != null)
|
||||||
|
@ -42,20 +42,29 @@ class WinUpdateProcess implements Runnable {
|
|||||||
var workingDir = workDir();
|
var workingDir = workDir();
|
||||||
var logFile = new File(workingDir, "log-" + version + ".txt");
|
var logFile = new File(workingDir, "log-" + version + ".txt");
|
||||||
|
|
||||||
ProcessBuilder pb = new ProcessBuilder(file.getAbsolutePath());
|
if (logFile.canWrite()) {
|
||||||
var env = pb.environment();
|
// check if we can write to the log file. If we can, use the ProcessBuilder to
|
||||||
env.put("OLD_I2P_VERSION", version);
|
// run the installer.
|
||||||
env.remove("RESTART_I2P");
|
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();
|
int exitCode = ctx.router().scheduledGracefulExitCode();
|
||||||
if (exitCode == Router.EXIT_HARD_RESTART || exitCode == Router.EXIT_GRACEFUL_RESTART)
|
if (exitCode == Router.EXIT_HARD_RESTART || exitCode == Router.EXIT_GRACEFUL_RESTART)
|
||||||
env.put("RESTART_I2P", "true");
|
env.put("RESTART_I2P", "true");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
pb.directory(workingDir).redirectErrorStream(true).redirectOutput(logFile).start();
|
pb.directory(workingDir).redirectErrorStream(true).redirectOutput(logFile).start();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
System.out.println("Unable to run update-program in background. Update will fail.");
|
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
|
@Override
|
||||||
|
@ -43,28 +43,30 @@ public class WindowsUpdatePostProcessor implements UpdatePostProcessor {
|
|||||||
public void updateDownloadedandVerified(UpdateType type, int fileType, String version, File file)
|
public void updateDownloadedandVerified(UpdateType type, int fileType, String version, File file)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
_log.info("Got an update to post-process");
|
_log.info("Got an update to post-process");
|
||||||
|
if (SystemVersion.isWindows()) {
|
||||||
|
|
||||||
if (type != UpdateType.ROUTER_SIGNED_SU3 && type != UpdateType.ROUTER_DEV_SU3) {
|
if (type != UpdateType.ROUTER_SIGNED_SU3 && type != UpdateType.ROUTER_DEV_SU3) {
|
||||||
_log.warn("Unsupported update type " + type);
|
_log.warn("Unsupported update type " + type);
|
||||||
return;
|
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 {
|
private File moveUpdateInstaller(File file) throws IOException {
|
||||||
|
Reference in New Issue
Block a user