format everything for readability and so the brackets all line up again. All whitespace changes.

This commit is contained in:
idk
2022-09-03 21:17:44 -04:00
parent 079ef87c8f
commit a230a49af7
4 changed files with 270 additions and 249 deletions

View File

@@ -25,9 +25,11 @@ public class Elevator {
if (!result) { if (!result) {
int lastError = Kernel32.INSTANCE.GetLastError(); int lastError = Kernel32.INSTANCE.GetLastError();
String errorMessage = Kernel32Util.formatMessageFromLastErrorCode(lastError); String errorMessage =
throw new RuntimeException("Error performing elevation: " + lastError + ": " + errorMessage + " (apperror=" Kernel32Util.formatMessageFromLastErrorCode(lastError);
+ execInfo.hInstApp + ")"); throw new RuntimeException("Error performing elevation: " + lastError +
": " + errorMessage +
" (apperror=" + execInfo.hInstApp + ")");
} }
} }
} }

View File

@@ -1,7 +1,5 @@
package net.i2p.router; package net.i2p.router;
import java.util.*;
import com.sun.jna.Native; import com.sun.jna.Native;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.sun.jna.Structure; import com.sun.jna.Structure;
@@ -12,9 +10,11 @@ import com.sun.jna.platform.win32.WinDef.HWND;
import com.sun.jna.platform.win32.WinNT.HANDLE; import com.sun.jna.platform.win32.WinNT.HANDLE;
import com.sun.jna.platform.win32.WinReg.HKEY; import com.sun.jna.platform.win32.WinReg.HKEY;
import com.sun.jna.win32.W32APIOptions; import com.sun.jna.win32.W32APIOptions;
import java.util.*;
public interface Shell32X extends Shell32 { public interface Shell32X extends Shell32 {
Shell32X INSTANCE = (Shell32X) Native.loadLibrary("shell32", Shell32X.class, W32APIOptions.UNICODE_OPTIONS); Shell32X INSTANCE = (Shell32X)Native.loadLibrary(
"shell32", Shell32X.class, W32APIOptions.UNICODE_OPTIONS);
int SW_HIDE = 0; int SW_HIDE = 0;
int SW_MAXIMIZE = 3; int SW_MAXIMIZE = 3;
@@ -49,7 +49,8 @@ public interface Shell32X extends Shell32 {
int SEE_MASK_NOCLOSEPROCESS = 0x00000040; int SEE_MASK_NOCLOSEPROCESS = 0x00000040;
int ShellExecute(int i, String lpVerb, String lpFile, String lpParameters, String lpDirectory, int nShow); int ShellExecute(int i, String lpVerb, String lpFile, String lpParameters,
String lpDirectory, int nShow);
boolean ShellExecuteEx(SHELLEXECUTEINFO lpExecInfo); boolean ShellExecuteEx(SHELLEXECUTEINFO lpExecInfo);
@@ -101,11 +102,22 @@ public interface Shell32X extends Shell32 {
protected List getFieldOrder() { protected List getFieldOrder() {
return Arrays.asList(new String[] { return Arrays.asList(new String[] {
"cbSize", "fMask", "hwnd", "lpVerb", "lpFile", "lpParameters", "cbSize",
"lpDirectory", "nShow", "hInstApp", "lpIDList", "lpClass", "fMask",
"hKeyClass", "dwHotKey", "hMonitor", "hProcess", "hwnd",
"lpVerb",
"lpFile",
"lpParameters",
"lpDirectory",
"nShow",
"hInstApp",
"lpIDList",
"lpClass",
"hKeyClass",
"dwHotKey",
"hMonitor",
"hProcess",
}); });
} }
} }
} }

View File

@@ -1,10 +1,9 @@
package net.i2p.router; package net.i2p.router;
import net.i2p.router.*;
import net.i2p.I2PAppContext;
import java.util.function.*;
import java.io.*; import java.io.*;
import java.util.function.*;
import net.i2p.I2PAppContext;
import net.i2p.router.*;
import net.i2p.util.Log; import net.i2p.util.Log;
class WinUpdateProcess implements Runnable { class WinUpdateProcess implements Runnable {
@@ -13,7 +12,8 @@ class WinUpdateProcess implements Runnable {
private final Supplier<File> fileSupplier; private final Supplier<File> fileSupplier;
private final Log _log; private final Log _log;
WinUpdateProcess(RouterContext ctx, Supplier<String> versionSupplier, Supplier<File> fileSupplier) { WinUpdateProcess(RouterContext ctx, Supplier<String> versionSupplier,
Supplier<File> fileSupplier) {
this.ctx = ctx; this.ctx = ctx;
this.versionSupplier = versionSupplier; this.versionSupplier = versionSupplier;
this.fileSupplier = fileSupplier; this.fileSupplier = fileSupplier;
@@ -22,10 +22,12 @@ class WinUpdateProcess implements Runnable {
private File workDir() throws IOException { private File workDir() throws IOException {
if (ctx != null) { if (ctx != null) {
File workDir = new File(ctx.getConfigDir().getAbsolutePath(), "i2p_update_win"); File workDir =
new File(ctx.getConfigDir().getAbsolutePath(), "i2p_update_win");
if (workDir.exists()) { if (workDir.exists()) {
if (workDir.isFile()) if (workDir.isFile())
throw new IOException(workDir + " exists but is a file, get it out of the way"); throw new IOException(workDir +
" exists but is a file, get it out of the way");
return workDir; return workDir;
} else { } else {
workDir.mkdirs(); workDir.mkdirs();
@@ -45,28 +47,34 @@ class WinUpdateProcess implements Runnable {
var logFile = new File(workingDir, "log-" + version + ".txt"); var logFile = new File(workingDir, "log-" + version + ".txt");
if (logFile.canWrite()) { if (logFile.canWrite()) {
// check if we can write to the log file. If we can, use the ProcessBuilder to // check if we can write to the log file. If we can, use the
// run the installer. // ProcessBuilder to run the installer.
ProcessBuilder pb = new ProcessBuilder(file.getAbsolutePath(), "/S", "/D=" + workingDir.getAbsolutePath()); ProcessBuilder pb = new ProcessBuilder(
file.getAbsolutePath(), "/S", "/D=" + workingDir.getAbsolutePath());
var env = pb.environment(); var env = pb.environment();
env.put("OLD_I2P_VERSION", version); env.put("OLD_I2P_VERSION", version);
env.remove("RESTART_I2P"); 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) {
_log.error("Unable to run update-program in background. Update will fail."); _log.error(
"Unable to run update-program in background. Update will fail.");
} }
} else { } else {
// If we cant write to the log file and we're on Windows, use the elevator to // If we cant write to the log file and we're on Windows, use the elevator
// execute the installer instead of the ProcessBuilder. // to execute the installer instead of the ProcessBuilder.
Elevator.executeAsAdministrator(file.getAbsolutePath(), " /S /D=" + workingDir.getAbsolutePath()); Elevator.executeAsAdministrator(file.getAbsolutePath(),
" /S /D=" + workingDir.getAbsolutePath());
} }
} }
@Override @Override

View File

@@ -1,22 +1,21 @@
package net.i2p.router; package net.i2p.router;
import static net.i2p.update.UpdateType.*;
import java.io.*; import java.io.*;
import java.lang.InterruptedException;
import java.lang.Process;
import java.lang.ProcessBuilder;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.*; import java.util.concurrent.atomic.*;
import net.i2p.crypto.*;
import static net.i2p.update.UpdateType.*;
import net.i2p.I2PAppContext; import net.i2p.I2PAppContext;
import net.i2p.update.UpdateType; import net.i2p.crypto.*;
import net.i2p.update.UpdatePostProcessor; import net.i2p.update.UpdatePostProcessor;
import net.i2p.update.UpdateType;
import net.i2p.util.Log; import net.i2p.util.Log;
import net.i2p.util.SystemVersion; import net.i2p.util.SystemVersion;
import java.lang.ProcessBuilder;
import java.lang.Process;
import java.lang.InterruptedException;
public class WindowsUpdatePostProcessor implements UpdatePostProcessor { public class WindowsUpdatePostProcessor implements UpdatePostProcessor {
private final Log _log; private final Log _log;
private final RouterContext ctx; private final RouterContext ctx;
@@ -32,20 +31,18 @@ public class WindowsUpdatePostProcessor implements UpdatePostProcessor {
this._log = ctx.logManager().getLog(WindowsUpdatePostProcessor.class); this._log = ctx.logManager().getLog(WindowsUpdatePostProcessor.class);
} }
public String getVersion() { public String getVersion() { return version; }
return version;
}
public File getFile() { public File getFile() { return positionedFile; }
return positionedFile;
}
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 (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;
} }
@@ -65,7 +62,8 @@ public class WindowsUpdatePostProcessor implements UpdatePostProcessor {
_log.info("adding shutdown hook"); _log.info("adding shutdown hook");
ctx.addFinalShutdownTask(new WinUpdateProcess(ctx, this::getVersion, this::getFile)); ctx.addFinalShutdownTask(
new WinUpdateProcess(ctx, this::getVersion, this::getFile));
} }
} }
@@ -85,10 +83,12 @@ public class WindowsUpdatePostProcessor implements UpdatePostProcessor {
private File workDir() throws IOException { private File workDir() throws IOException {
if (this.ctx != null) { if (this.ctx != null) {
File workDir = new File(this.ctx.getConfigDir().getAbsolutePath(), "i2p_update_win"); File workDir =
new File(this.ctx.getConfigDir().getAbsolutePath(), "i2p_update_win");
if (workDir.exists()) { if (workDir.exists()) {
if (workDir.isFile()) if (workDir.isFile())
throw new IOException(workDir + " exists but is a file, get it out of the way"); throw new IOException(workDir +
" exists but is a file, get it out of the way");
return null; return null;
} else { } else {
workDir.mkdirs(); workDir.mkdirs();
@@ -97,5 +97,4 @@ public class WindowsUpdatePostProcessor implements UpdatePostProcessor {
} }
return null; return null;
} }
} }