Remove admin update subsystem along with admin installs. There is no more need to change the update URL on the first run now that it uses it's own directory. Tweak WindowsUpdatePostProcessor to use a zip update only as a backup.

This commit is contained in:
idk
2023-02-08 21:47:54 +00:00
parent 402cede106
commit 65fb9e1847
8 changed files with 98 additions and 335 deletions

View File

@ -57,8 +57,10 @@ if [ -z "$EXTRA" ]; then
export EXTRA=" public final static String EXTRA = \"-$EXTRACODE\";" export EXTRA=" public final static String EXTRA = \"-$EXTRACODE\";"
fi fi
find . -name RouterVersion.java -exec sed -i "s|$OLDEXTRA|$EXTRA|g" {} \; find . -name RouterVersion.java -exec sed -i "s|$OLDEXTRA|$EXTRA|g" {} \;
git checkout -b "i2p-$VERSION-$EXTRACODE" && git commit -am "i2p-$VERSION-$EXTRACODE" git switch - || :
git pull --tags git pull --tags
git checkout -b "i2p-$VERSION-$EXTRACODE" || :
git commit -am "i2p-$VERSION-$EXTRACODE" || :
git archive --format=tar.gz --output="$SCRIPT_DIR/../i2p.firefox/i2p.i2p.jpackage-build.tar.gz" "i2p-$VERSION-$EXTRACODE" git archive --format=tar.gz --output="$SCRIPT_DIR/../i2p.firefox/i2p.i2p.jpackage-build.tar.gz" "i2p-$VERSION-$EXTRACODE"
for i in $COUNT; do for i in $COUNT; do
@ -105,10 +107,8 @@ for dll in "$I2P_JBIGI/"*windows*.dll; do
done done
cd "$SCRIPT_DIR"/java cd "$SCRIPT_DIR"/java
"$JAVA_HOME"/bin/javac -d ../build -classpath "$SCRIPT_DIR/build/i2pfirefox.jar:$SCRIPT_DIR/build/jna.jar":"$SCRIPT_DIR/build/jna-platform.jar":"$SCRIPT_DIR/build/i2p.jar":"$SCRIPT_DIR/build/router.jar":"$SCRIPT_DIR/build/routerconsole.jar":"$SCRIPT_DIR/build/jbigi.jar" \ "$JAVA_HOME"/bin/javac -Xlint:deprecation -d ../build -classpath "$SCRIPT_DIR/build/i2pfirefox.jar:$SCRIPT_DIR/build/jna.jar":"$SCRIPT_DIR/build/jna-platform.jar":"$SCRIPT_DIR/build/i2p.jar":"$SCRIPT_DIR/build/router.jar":"$SCRIPT_DIR/build/routerconsole.jar":"$SCRIPT_DIR/build/jbigi.jar" \
net/i2p/router/CopyConfigDir.java \ net/i2p/router/CopyConfigDir.java \
net/i2p/router/Elevator.java \
net/i2p/router/Shell32X.java \
net/i2p/router/WindowsServiceUtil.java \ net/i2p/router/WindowsServiceUtil.java \
net/i2p/router/WinLauncher.java \ net/i2p/router/WinLauncher.java \
net/i2p/router/WindowsUpdatePostProcessor.java \ net/i2p/router/WindowsUpdatePostProcessor.java \

View File

@ -13,9 +13,9 @@ import java.util.logging.Logger;
import java.util.logging.SimpleFormatter; import java.util.logging.SimpleFormatter;
public class CopyConfigDir extends WindowsServiceUtil { public class CopyConfigDir extends WindowsServiceUtil {
static final Logger logger = Logger.getLogger("configlog"); final Logger logger = Logger.getLogger("configlog");
public static void initLogger() { public void initLogger() {
try { try {
// This block configure the logger with handler and formatter // This block configure the logger with handler and formatter
FileHandler fh = new FileHandler(logFile().toString()); FileHandler fh = new FileHandler(logFile().toString());
@ -31,13 +31,13 @@ public class CopyConfigDir extends WindowsServiceUtil {
} }
} }
public static boolean copyDirectory(String baseDir, String workDir) { public boolean copyDirectory(String baseDir, String workDir) {
File baseFile = new File(baseDir); File baseFile = new File(baseDir);
File workFile = new File(workDir); File workFile = new File(workDir);
return copyDirectory(baseFile, workFile); return copyDirectory(baseFile, workFile);
} }
public static boolean copyDirectory(File baseDir, File workDir) { public boolean copyDirectory(File baseDir, File workDir) {
for (File file : baseDir.listFiles()) { for (File file : baseDir.listFiles()) {
String fPath = file.getAbsolutePath().replace( String fPath = file.getAbsolutePath().replace(
file.getParentFile().getAbsolutePath(), ""); file.getParentFile().getAbsolutePath(), "");
@ -52,7 +52,7 @@ public class CopyConfigDir extends WindowsServiceUtil {
return true; return true;
} }
public static boolean copyConfigDirectory(File baseDir, File workDir) { public boolean copyConfigDirectory(File baseDir, File workDir) {
for (File file : baseDir.listFiles()) { for (File file : baseDir.listFiles()) {
// System.out.println(file.getAbsolutePath()); // System.out.println(file.getAbsolutePath());
String fPath = file.getAbsolutePath().replace( String fPath = file.getAbsolutePath().replace(
@ -87,17 +87,17 @@ public class CopyConfigDir extends WindowsServiceUtil {
return true; return true;
} }
public static int copyFileNeverOverwrite(String basePath, String workPath) { public int copyFileNeverOverwrite(String basePath, String workPath) {
File baseFile = new File(basePath); File baseFile = new File(basePath);
File workFile = new File(workPath); File workFile = new File(workPath);
return copyFileNeverOverwrite(baseFile, workFile); return copyFileNeverOverwrite(baseFile, workFile);
} }
public static int copyFileNeverOverwrite(File basePath, File workPath) { public int copyFileNeverOverwrite(File basePath, File workPath) {
return copyFile(basePath, workPath, false); return copyFile(basePath, workPath, false);
} }
public static int copyFile(File basePath, File workPath, boolean overWrite) { public int copyFile(File basePath, File workPath, boolean overWrite) {
if (!basePath.exists()) { if (!basePath.exists()) {
logger.info(basePath.getAbsolutePath() + " doesn't exist, not copying"); logger.info(basePath.getAbsolutePath() + " doesn't exist, not copying");
return 0; return 0;
@ -135,7 +135,7 @@ public class CopyConfigDir extends WindowsServiceUtil {
} }
} }
protected static File selectHome() { // throws Exception { protected File selectHome() { // throws Exception {
String path_override = System.getenv("I2P_CONFIG"); String path_override = System.getenv("I2P_CONFIG");
if (path_override != null) { if (path_override != null) {
File path = new File(path_override); File path = new File(path_override);
@ -151,7 +151,7 @@ public class CopyConfigDir extends WindowsServiceUtil {
return i2p; return i2p;
} }
protected static File selectProgramFile() { protected File selectProgramFile() {
String path_override = System.getenv("I2P"); String path_override = System.getenv("I2P");
if (path_override != null) { if (path_override != null) {
File path = new File(path_override); File path = new File(path_override);
@ -182,7 +182,7 @@ public class CopyConfigDir extends WindowsServiceUtil {
* *
* @return * @return
*/ */
protected static File javaHome() { protected File javaHome() {
File jrehome = new File(System.getProperty("java.home")); File jrehome = new File(System.getProperty("java.home"));
if (jrehome != null) { if (jrehome != null) {
if (jrehome.exists()) { if (jrehome.exists()) {
@ -199,7 +199,7 @@ public class CopyConfigDir extends WindowsServiceUtil {
* *
* @return the app-image root * @return the app-image root
*/ */
protected static File appImageHome() { protected File appImageHome() {
File jreHome = javaHome(); File jreHome = javaHome();
if (jreHome != null) { if (jreHome != null) {
switch (osName()) { switch (osName()) {
@ -221,7 +221,7 @@ public class CopyConfigDir extends WindowsServiceUtil {
* *
* @return the app-image root * @return the app-image root
*/ */
protected static String appImageExe() { protected String appImageExe() {
File aih = appImageHome(); File aih = appImageHome();
if (aih != null) { if (aih != null) {
switch (osName()) { switch (osName()) {
@ -243,7 +243,7 @@ public class CopyConfigDir extends WindowsServiceUtil {
* *
* @return the app-image root * @return the app-image root
*/ */
protected static File appImageConfig() { protected File appImageConfig() {
File aih = appImageHome(); File aih = appImageHome();
if (aih == null) { if (aih == null) {
return null; return null;
@ -269,13 +269,13 @@ public class CopyConfigDir extends WindowsServiceUtil {
return null; return null;
} }
protected static boolean copyConfigDir() { protected boolean copyConfigDir() {
File appImageConfigDir = appImageConfig(); File appImageConfigDir = appImageConfig();
File appImageHomeDir = selectHome(); File appImageHomeDir = selectHome();
return copyConfigDirectory(appImageConfigDir, appImageHomeDir); return copyConfigDirectory(appImageConfigDir, appImageHomeDir);
} }
protected static String routerConfig() { protected String routerConfig() {
File appImageHomeDir = selectHome(); File appImageHomeDir = selectHome();
File routerConf = new File(appImageHomeDir, "router.config"); File routerConf = new File(appImageHomeDir, "router.config");
if (routerConf != null) { if (routerConf != null) {
@ -291,14 +291,14 @@ public class CopyConfigDir extends WindowsServiceUtil {
* *
* @return * @return
*/ */
protected static File logFile() { return logFile("launcher.log"); } protected File logFile() { return logFile("launcher.log"); }
/** /**
* set up the path to the log file * set up the path to the log file
* *
* @return * @return
*/ */
protected static File logFile(String p) { protected File logFile(String p) {
File log = new File(selectProgramFile(), "logs"); File log = new File(selectProgramFile(), "logs");
if (!log.exists()) if (!log.exists())
log.mkdirs(); log.mkdirs();

View File

@ -1,38 +0,0 @@
package net.i2p.router;
import com.sun.jna.WString;
import com.sun.jna.platform.win32.Kernel32;
import com.sun.jna.platform.win32.Kernel32Util;
//TODO: This is obsolete. I don't know if a single user still has an admin-style install of this.
// it should be removed a the earliest convenient time.
public class Elevator {
public static void main(String... args) {
executeAsAdministrator("c:\\windows\\system32\\notepad.exe", "");
}
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)
execInfo.lpParameters = new WString(args);
execInfo.nShow = Shell32X.SW_SHOWDEFAULT;
execInfo.fMask = Shell32X.SEE_MASK_NOCLOSEPROCESS;
execInfo.lpVerb = new WString("runas");
boolean result = Shell32X.INSTANCE.ShellExecuteEx(execInfo);
if (!result) {
int lastError = Kernel32.INSTANCE.GetLastError();
String errorMessage =
Kernel32Util.formatMessageFromLastErrorCode(lastError);
throw new RuntimeException("Error performing elevation: " + lastError +
": " + errorMessage +
" (apperror=" + execInfo.hInstApp + ")");
}
}
}

View File

@ -1,125 +0,0 @@
package net.i2p.router;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.Structure;
import com.sun.jna.WString;
import com.sun.jna.platform.win32.Shell32;
import com.sun.jna.platform.win32.WinDef.HINSTANCE;
import com.sun.jna.platform.win32.WinDef.HWND;
import com.sun.jna.platform.win32.WinNT.HANDLE;
import com.sun.jna.platform.win32.WinReg.HKEY;
import com.sun.jna.win32.W32APIOptions;
import java.util.*;
//TODO: This is obsolete. I don't know if a single user still has an admin-style install of this.
// it should be removed a the earliest convenient time.
public interface Shell32X extends Shell32 {
Shell32X INSTANCE = (Shell32X)Native.loadLibrary(
"shell32", Shell32X.class, W32APIOptions.UNICODE_OPTIONS);
int SW_HIDE = 0;
int SW_MAXIMIZE = 3;
int SW_MINIMIZE = 6;
int SW_RESTORE = 9;
int SW_SHOW = 5;
int SW_SHOWDEFAULT = 10;
int SW_SHOWMAXIMIZED = 3;
int SW_SHOWMINIMIZED = 2;
int SW_SHOWMINNOACTIVE = 7;
int SW_SHOWNA = 8;
int SW_SHOWNOACTIVATE = 4;
int SW_SHOWNORMAL = 1;
/** File not found. */
int SE_ERR_FNF = 2;
/** Path not found. */
int SE_ERR_PNF = 3;
/** Access denied. */
int SE_ERR_ACCESSDENIED = 5;
/** Out of memory. */
int SE_ERR_OOM = 8;
/** DLL not found. */
int SE_ERR_DLLNOTFOUND = 32;
/** Cannot share an open file. */
int SE_ERR_SHARE = 26;
int SEE_MASK_NOCLOSEPROCESS = 0x00000040;
int ShellExecute(int i, String lpVerb, String lpFile, String lpParameters,
String lpDirectory, int nShow);
boolean ShellExecuteEx(SHELLEXECUTEINFO lpExecInfo);
public static class SHELLEXECUTEINFO extends Structure {
/*
* DWORD cbSize;
* ULONG fMask;
* HWND hwnd;
* LPCTSTR lpVerb;
* LPCTSTR lpFile;
* LPCTSTR lpParameters;
* LPCTSTR lpDirectory;
* int nShow;
* HINSTANCE hInstApp;
* LPVOID lpIDList;
* LPCTSTR lpClass;
* HKEY hkeyClass;
* DWORD dwHotKey;
* union {
* HANDLE hIcon;
* HANDLE hMonitor;
* } DUMMYUNIONNAME;
* HANDLE hProcess;
*/
public int cbSize = size();
public int fMask;
public HWND hwnd;
public WString lpVerb;
public WString lpFile;
public WString lpParameters;
public WString lpDirectory;
public int nShow;
public HINSTANCE hInstApp;
public Pointer lpIDList;
public WString lpClass;
public HKEY hKeyClass;
public int dwHotKey;
/*
* Actually:
* union {
* HANDLE hIcon;
* HANDLE hMonitor;
* } DUMMYUNIONNAME;
*/
public HANDLE hMonitor;
public HANDLE hProcess;
protected List getFieldOrder() {
return Arrays.asList(new String[] {
"cbSize",
"fMask",
"hwnd",
"lpVerb",
"lpFile",
"lpParameters",
"lpDirectory",
"nShow",
"hInstApp",
"lpIDList",
"lpClass",
"hKeyClass",
"dwHotKey",
"hMonitor",
"hProcess",
});
}
}
}

View File

@ -1,7 +1,5 @@
package net.i2p.router; package net.i2p.router;
import static net.i2p.update.UpdateType.*;
import java.io.*; import java.io.*;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.ServerSocket; import java.net.ServerSocket;
@ -18,6 +16,7 @@ import net.i2p.router.RouterLaunch;
import net.i2p.update.*; import net.i2p.update.*;
import net.i2p.update.UpdateManager; import net.i2p.update.UpdateManager;
import net.i2p.update.UpdatePostProcessor; import net.i2p.update.UpdatePostProcessor;
import net.i2p.update.UpdateType.*;
/** /**
* Launches a router from %PROGRAMFILES%/I2P using configuration data in * Launches a router from %PROGRAMFILES%/I2P using configuration data in
@ -30,10 +29,10 @@ import net.i2p.update.UpdatePostProcessor;
* router.pid - the pid of the java process. * router.pid - the pid of the java process.
*/ */
public class WinLauncher extends CopyConfigDir { public class WinLauncher extends CopyConfigDir {
static WindowsUpdatePostProcessor wupp = null; WindowsUpdatePostProcessor wupp = null;
private static Router i2pRouter; private Router i2pRouter;
public static void main(String[] args) { public void main(String[] args) {
setupLauncher(); setupLauncher();
initLogger(); initLogger();
int privateBrowsing = 0; int privateBrowsing = 0;
@ -110,15 +109,11 @@ public class WinLauncher extends CopyConfigDir {
logger.severe( logger.severe(
"Service startup failure, please start I2P service with services.msc"); "Service startup failure, please start I2P service with services.msc");
System.exit(2); System.exit(2);
} else {
fixServiceConfig();
} }
continuerunning = promptUserInstallStartIfAvailable(); continuerunning = promptUserInstallStartIfAvailable();
if (!continuerunning) { if (!continuerunning) {
logger.severe("User-install startup required."); logger.severe("User-install startup required.");
System.exit(2); System.exit(2);
} else {
fixServiceConfig();
} }
// This actually does most of what we use NSIS for if NSIS hasn't // This actually does most of what we use NSIS for if NSIS hasn't
@ -154,73 +149,14 @@ public class WinLauncher extends CopyConfigDir {
i2pRouter.runRouter(); i2pRouter.runRouter();
} }
private static void fixServiceConfig() { private void setupLauncher() {
if (osName() != "windows")
return;
// If the user installed the Easy bundle before installing the
// IzPack installer, then they have a config file which contains the
// wrong update URL. Check for it, and change it back if necessary.
// closes #23
String routerconf = routerConfig();
if (routerconf != null) {
File routerconffile = new File(routerconf);
if (!routerconffile.exists()) {
return;
}
} else {
return;
}
if (isInstalled("i2p") || checkProgramFilesInstall()) {
i2pRouter = new Router(routerconf, System.getProperties());
String newsURL = i2pRouter.getConfigSetting("router.newsURL");
if (newsURL != null) {
if (newsURL.contains(
"http://dn3tvalnjz432qkqsvpfdqrwpqkw3ye4n4i2uyfr4jexvo3sp5ka.b32.i2p/news/win/beta/news.su3")) {
logger.info(
"checked router.newsURL config, containes win/beta in a service install, invalid update type");
if (i2pRouter.saveConfig("router.newsURL", ServiceUpdaterString())) {
logger.info("updated routerconsole.browser config " +
appImageExe());
}
}
}
String backupNewsURL = i2pRouter.getConfigSetting("router.backupNewsURL");
if (backupNewsURL != null) {
if (backupNewsURL.contains(
"http://tc73n4kivdroccekirco7rhgxdg5f3cjvbaapabupeyzrqwv5guq.b32.i2p/win/beta/news.su3")) {
logger.info(
"checked router.backupNewsURL config, containes win/beta in a service install, invalid update type");
if (i2pRouter.saveConfig("router.backupNewsURL",
ServiceBackupUpdaterString())) {
logger.info("updated routerconsole.browser config " +
appImageExe());
}
}
}
String updateURL = i2pRouter.getConfigSetting("router.updateURL");
if (updateURL != null) {
if (updateURL.contains(
"http://ekm3fu6fr5pxudhwjmdiea5dovc3jdi66hjgop4c7z7dfaw7spca.b32.i2p/i2pwinupdate.su3")) {
logger.info(
"checked router.updateURL config, containes easy-intall update in a service install, invalid update type");
if (i2pRouter.saveConfig("router.updateURL",
ServiceStaticUpdaterString())) {
logger.info("updated routerconsole.browser config " +
appImageExe());
}
}
}
}
}
private static void setupLauncher() {
File jrehome = javaHome(); File jrehome = javaHome();
logger.info("jre home is: " + jrehome.getAbsolutePath()); logger.info("jre home is: " + jrehome.getAbsolutePath());
File appimagehome = appImageHome(); File appimagehome = appImageHome();
logger.info("appimage home is: " + appimagehome.getAbsolutePath()); logger.info("appimage home is: " + appimagehome.getAbsolutePath());
} }
private static File programFile() { private File programFile() {
File programs = selectProgramFile(); File programs = selectProgramFile();
if (!programs.exists()) if (!programs.exists())
programs.mkdirs(); programs.mkdirs();
@ -233,7 +169,7 @@ public class WinLauncher extends CopyConfigDir {
return programs; return programs;
} }
private static File homeDir() { private File homeDir() {
File home = selectHome(); File home = selectHome();
if (!home.exists()) if (!home.exists())
home.mkdirs(); home.mkdirs();
@ -246,11 +182,9 @@ public class WinLauncher extends CopyConfigDir {
return home; return home;
} }
private static boolean launchBrowser(int privateBrowsing, private boolean launchBrowser(int privateBrowsing, boolean usabilityMode,
boolean usabilityMode, boolean chromiumFirst, int proxyTimeoutTime,
boolean chromiumFirst, ArrayList<String> newArgsList) {
int proxyTimeoutTime,
ArrayList<String> newArgsList) {
if (i2pIsRunning()) { if (i2pIsRunning()) {
logger.info("I2P is already running, launching an I2P browser"); logger.info("I2P is already running, launching an I2P browser");
I2PBrowser i2pBrowser = new I2PBrowser(); I2PBrowser i2pBrowser = new I2PBrowser();
@ -273,7 +207,7 @@ public class WinLauncher extends CopyConfigDir {
// see // see
// https://stackoverflow.com/questions/434718/sockets-discover-port-availability-using-java // https://stackoverflow.com/questions/434718/sockets-discover-port-availability-using-java
private static boolean isAvailable(int portNr) { private boolean isAvailable(int portNr) {
boolean portFree; boolean portFree;
try (var ignored = new ServerSocket(portNr)) { try (var ignored = new ServerSocket(portNr)) {
portFree = true; portFree = true;
@ -283,7 +217,7 @@ public class WinLauncher extends CopyConfigDir {
return portFree; return portFree;
} }
private static boolean i2pIsRunningCheck() { private boolean i2pIsRunningCheck() {
// check if there's something listening on port 7657(Router Console) // check if there's something listening on port 7657(Router Console)
if (!isAvailable(7657)) if (!isAvailable(7657))
return true; return true;
@ -295,7 +229,7 @@ public class WinLauncher extends CopyConfigDir {
return false; return false;
} }
private static void setNotStarting() { private void setNotStarting() {
logger.info("removing startup file, the application has started"); logger.info("removing startup file, the application has started");
File home = selectHome(); File home = selectHome();
File starting = new File(home, "starting"); File starting = new File(home, "starting");
@ -304,7 +238,7 @@ public class WinLauncher extends CopyConfigDir {
} }
} }
private static void setStarting() { private void setStarting() {
logger.info("creating startup file, router is starting up"); logger.info("creating startup file, router is starting up");
File home = selectHome(); File home = selectHome();
File starting = new File(home, "starting"); File starting = new File(home, "starting");
@ -323,7 +257,7 @@ public class WinLauncher extends CopyConfigDir {
}); });
} }
private static boolean checkStarting() { private boolean checkStarting() {
logger.info("checking startup file"); logger.info("checking startup file");
File home = selectHome(); File home = selectHome();
File starting = new File(home, "starting"); File starting = new File(home, "starting");
@ -338,7 +272,7 @@ public class WinLauncher extends CopyConfigDir {
// check for the existence of router.ping file, if it's less then 2 // check for the existence of router.ping file, if it's less then 2
// minutes old, exit // minutes old, exit
private static boolean checkPing() { private boolean checkPing() {
File home = selectHome(); File home = selectHome();
File ping = new File(home, "router.ping"); File ping = new File(home, "router.ping");
if (ping.exists()) { if (ping.exists()) {
@ -355,7 +289,7 @@ public class WinLauncher extends CopyConfigDir {
return false; return false;
} }
private static boolean i2pIsRunning() { private boolean i2pIsRunning() {
if (checkStarting()) if (checkStarting())
return true; return true;
if (checkPing()) if (checkPing())
@ -370,7 +304,7 @@ public class WinLauncher extends CopyConfigDir {
return false; return false;
} }
private static final Runnable REGISTER_UPP = () -> { private final Runnable REGISTER_UPP = () -> {
RouterContext ctx; RouterContext ctx;
while ((ctx = i2pRouter.getContext()) == null) { while ((ctx = i2pRouter.getContext()) == null) {
sleep(1000); sleep(1000);
@ -395,7 +329,7 @@ public class WinLauncher extends CopyConfigDir {
* *
* @param millis * @param millis
*/ */
private static void sleep(int millis) { private void sleep(int millis) {
try { try {
Thread.sleep(millis); Thread.sleep(millis);
} catch (InterruptedException bad) { } catch (InterruptedException bad) {

View File

@ -47,43 +47,34 @@ class WinUpdateProcess implements Runnable {
File workingDir = workDir(); File workingDir = workDir();
File logFile = new File(workingDir, "log-" + version + ".txt"); File logFile = new File(workingDir, "log-" + version + ".txt");
if (logFile.canWrite()) { // check if we can write to the log file. If we can, use the
// check if we can write to the log file. If we can, use the // ProcessBuilder to run the installer.
// ProcessBuilder to run the installer. ProcessBuilder pb = new ProcessBuilder(
ProcessBuilder pb = new ProcessBuilder( file.getAbsolutePath(), "/S", "/D=" + workingDir.getAbsolutePath());
file.getAbsolutePath(), "/S", "/D=" + workingDir.getAbsolutePath()); Map<String, String> env = pb.environment();
Map<String, String> 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 || if (exitCode == Router.EXIT_HARD_RESTART ||
exitCode == Router.EXIT_GRACEFUL_RESTART) exitCode == Router.EXIT_GRACEFUL_RESTART)
env.put("RESTART_I2P", "true"); env.put("RESTART_I2P", "true");
try { try {
Process p = pb.directory(workingDir) Process p = pb.directory(workingDir)
.redirectErrorStream(true) .redirectErrorStream(true)
.redirectOutput(logFile) .redirectOutput(logFile)
.start(); .start();
exitCode = p.waitFor(); exitCode = p.waitFor();
if (exitCode != 0) if (exitCode != 0)
_log.error("Update failed with exit code " + exitCode + " see " + _log.error("Update failed with exit code " + exitCode + " see " +
logFile.getAbsolutePath() + " for more details"); logFile.getAbsolutePath() + " for more details");
} catch (IOException ex) { } catch (IOException ex) {
_log.error( _log.error(
"Unable to run update program in background. Update will fail.", "Unable to run update program in background. Update will fail.", ex);
ex); } catch (InterruptedException ex) {
} catch (InterruptedException ex) { _log.error(
_log.error( "Unable to run update program in background. Update will fail.", ex);
"Unable to run update program in background. Update will fail.",
ex);
}
} 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());
} }
} }

View File

@ -31,7 +31,7 @@ import javax.swing.JOptionPane;
public class WindowsServiceUtil { public class WindowsServiceUtil {
public WindowsServiceUtil() {} public WindowsServiceUtil() {}
public static String queryService(String serviceName) { public String queryService(String serviceName) {
String result = ""; String result = "";
String line; String line;
ProcessBuilder pb = new ProcessBuilder("sc", "query", serviceName); ProcessBuilder pb = new ProcessBuilder("sc", "query", serviceName);
@ -54,7 +54,7 @@ public class WindowsServiceUtil {
} }
return result; return result;
} }
public static String getStatePrefix(String qResult) { public String getStatePrefix(String qResult) {
String statePrefix = "STATE : "; String statePrefix = "STATE : ";
// get the first occurrence of "STATE", then find the // get the first occurrence of "STATE", then find the
// next occurrence of of ":" after that. Count the // next occurrence of of ":" after that. Count the
@ -70,7 +70,7 @@ public class WindowsServiceUtil {
} }
return statePrefix; return statePrefix;
} }
public static int getServiceStateInt(String serviceName) { public int getServiceStateInt(String serviceName) {
// String statePrefix = "STATE : "; // String statePrefix = "STATE : ";
String qResult = queryService(serviceName); String qResult = queryService(serviceName);
String statePrefix = getStatePrefix(qResult); String statePrefix = getStatePrefix(qResult);
@ -86,14 +86,14 @@ public class WindowsServiceUtil {
return -2; return -2;
} }
public static boolean isInstalled(String serviceName) { public boolean isInstalled(String serviceName) {
if (getServiceState(serviceName).equals("uninstalled")) { if (getServiceState(serviceName).equals("uninstalled")) {
return false; return false;
} }
return true; return true;
} }
public static boolean isStart(String serviceName) { public boolean isStart(String serviceName) {
if (getServiceState(serviceName).equals("started")) { if (getServiceState(serviceName).equals("started")) {
return true; return true;
} }
@ -106,7 +106,7 @@ public class WindowsServiceUtil {
return false; return false;
} }
public static boolean promptServiceStartIfAvailable(String serviceName) { public boolean promptServiceStartIfAvailable(String serviceName) {
if (osName() != "windows") { if (osName() != "windows") {
return true; return true;
} }
@ -152,17 +152,17 @@ public class WindowsServiceUtil {
return true; return true;
} }
public static String ServiceUpdaterString() { public String ServiceUpdaterString() {
return "http://tc73n4kivdroccekirco7rhgxdg5f3cjvbaapabupeyzrqwv5guq.b32.i2p/news.su3"; return "http://tc73n4kivdroccekirco7rhgxdg5f3cjvbaapabupeyzrqwv5guq.b32.i2p/news.su3";
} }
public static String ServiceBackupUpdaterString() { public String ServiceBackupUpdaterString() {
return "http://dn3tvalnjz432qkqsvpfdqrwpqkw3ye4n4i2uyfr4jexvo3sp5ka.b32.i2p/news.su3"; return "http://dn3tvalnjz432qkqsvpfdqrwpqkw3ye4n4i2uyfr4jexvo3sp5ka.b32.i2p/news.su3";
} }
public static String ServiceStaticUpdaterString() { public String ServiceStaticUpdaterString() {
return "http://echelon.i2p/i2p/i2pupdate.sud,http://stats.i2p/i2p/i2pupdate.sud"; return "http://echelon.i2p/i2p/i2pupdate.sud,http://stats.i2p/i2p/i2pupdate.sud";
} }
public static String getProgramFilesInstall() { public String getProgramFilesInstall() {
String programFiles = System.getenv("PROGRAMFILES"); String programFiles = System.getenv("PROGRAMFILES");
if (programFiles != null) { if (programFiles != null) {
File programFilesI2P = new File(programFiles, "i2p/i2p.exe"); File programFilesI2P = new File(programFiles, "i2p/i2p.exe");
@ -178,7 +178,7 @@ public class WindowsServiceUtil {
return null; return null;
} }
public static boolean checkProgramFilesInstall() { public boolean checkProgramFilesInstall() {
String programFiles = System.getenv("PROGRAMFILES"); String programFiles = System.getenv("PROGRAMFILES");
if (programFiles != null) { if (programFiles != null) {
File programFilesI2P = new File(programFiles, "i2p/i2p.exe"); File programFilesI2P = new File(programFiles, "i2p/i2p.exe");
@ -194,7 +194,7 @@ public class WindowsServiceUtil {
return false; return false;
} }
public static boolean promptUserInstallStartIfAvailable() { public boolean promptUserInstallStartIfAvailable() {
if (osName() != "windows") { if (osName() != "windows") {
return true; return true;
} }
@ -205,7 +205,7 @@ public class WindowsServiceUtil {
message += message +=
"However, it is not running yet. Please start it using the shortcut on the desktop.\n"; "However, it is not running yet. Please start it using the shortcut on the desktop.\n";
message += message +=
"If you click \"No\", the jpackage router will be launched instead.\n"; "If you click \"No\", the Easy-Install router will be launched instead.\n";
a = JOptionPane.showConfirmDialog(null, message, a = JOptionPane.showConfirmDialog(null, message,
"I2P Service detected not running", "I2P Service detected not running",
JOptionPane.YES_NO_OPTION); JOptionPane.YES_NO_OPTION);
@ -216,7 +216,7 @@ public class WindowsServiceUtil {
try { try {
String pfi = getProgramFilesInstall(); String pfi = getProgramFilesInstall();
if (pfi != null) if (pfi != null)
Runtime.getRuntime().exec(pfi); Runtime.getRuntime().exec(new String[] {pfi});
} catch (IOException e) { } catch (IOException e) {
return false; return false;
} }
@ -226,7 +226,7 @@ public class WindowsServiceUtil {
return true; return true;
} }
public static String getServiceState(String serviceName) { public String getServiceState(String serviceName) {
String stateString = "uninstalled"; String stateString = "uninstalled";
int state = getServiceStateInt(serviceName); int state = getServiceStateInt(serviceName);
switch (state) { switch (state) {
@ -268,7 +268,7 @@ public class WindowsServiceUtil {
return "mac"; return "mac";
return "linux"; return "linux";
} }
public static void main(String args[]) { public void main(String args[]) {
// when querying the I2P router service installed by the IzPack installer // when querying the I2P router service installed by the IzPack installer
// this is the correct call. // this is the correct call.
String state = getServiceState("i2p"); String state = getServiceState("i2p");

View File

@ -44,20 +44,6 @@ public class WindowsUpdatePostProcessor implements UpdatePostProcessor {
_log.warn("Unsupported update type " + type); _log.warn("Unsupported update type " + type);
return; return;
} }
if (fileType != SU3File.TYPE_ZIP) {
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 ZipUpdateProcess(ctx, this::getVersion, this::getFile));
}
if (SystemVersion.isWindows()) { if (SystemVersion.isWindows()) {
if (fileType != SU3File.TYPE_EXE) { if (fileType != SU3File.TYPE_EXE) {
@ -77,6 +63,21 @@ public class WindowsUpdatePostProcessor implements UpdatePostProcessor {
ctx.addFinalShutdownTask( ctx.addFinalShutdownTask(
new WinUpdateProcess(ctx, this::getVersion, this::getFile)); new WinUpdateProcess(ctx, this::getVersion, this::getFile));
} else {
if (fileType == SU3File.TYPE_ZIP) {
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 ZipUpdateProcess(ctx, this::getVersion, this::getFile));
}
} }
} }