Try a way of determining required rights for the installer

This commit is contained in:
idk
2022-03-21 11:04:27 -04:00
parent a28bb6ac3c
commit 9da43b3961
3 changed files with 46 additions and 31 deletions

View File

@ -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)

View File

@ -42,7 +42,10 @@ class WinUpdateProcess implements Runnable {
var workingDir = workDir();
var logFile = new File(workingDir, "log-" + version + ".txt");
ProcessBuilder pb = new ProcessBuilder(file.getAbsolutePath());
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");
@ -56,6 +59,12 @@ class WinUpdateProcess implements Runnable {
} 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

View File

@ -43,6 +43,7 @@ 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);
@ -63,8 +64,9 @@ public class WindowsUpdatePostProcessor implements UpdatePostProcessor {
}
_log.info("adding shutdown hook");
ctx.addFinalShutdownTask(new WinUpdateProcess(ctx, this::getVersion, this::getFile));
ctx.addFinalShutdownTask(new WinUpdateProcess(ctx, this::getVersion, this::getFile));
}
}
private File moveUpdateInstaller(File file) throws IOException {