OK I think that registers it
This commit is contained in:
@ -2,10 +2,16 @@ package net.i2p.router;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import net.i2p.app.ClientAppManager;
|
||||
import net.i2p.router.RouterLaunch;
|
||||
import net.i2p.router.Router;
|
||||
import net.i2p.update.UpdateManager;
|
||||
import net.i2p.update.UpdatePostProcessor;
|
||||
import net.i2p.util.SystemVersion;
|
||||
|
||||
import static net.i2p.update.UpdateType.*;
|
||||
|
||||
/**
|
||||
* Launches a router from %PROGRAMFILES%/I2P using configuration data in
|
||||
* %LOCALAPPDATA%/I2P.. Uses Java 9 APIs.
|
||||
@ -16,8 +22,9 @@ import net.i2p.util.SystemVersion;
|
||||
* router.pid - the pid of the java process.
|
||||
*/
|
||||
public class WinLauncher extends WindowsUpdatePostProcessor {
|
||||
WindowsUpdatePostProcessor wupp = new WindowsUpdatePostProcessor();
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
public void main(String[] args) throws Exception {
|
||||
File programs = selectProgramFile();
|
||||
|
||||
File home = selectHome();
|
||||
@ -35,10 +42,18 @@ public class WinLauncher extends WindowsUpdatePostProcessor {
|
||||
|
||||
i2pRouter = new Router(System.getProperties());
|
||||
|
||||
UpdateManager upmgr = updateManagerClient();
|
||||
if (upmgr != null) {
|
||||
upmgr.register(this.wupp, ROUTER_SIGNED_SU3, 6);
|
||||
upmgr.register(this.wupp, ROUTER_DEV_SU3, 6);
|
||||
}else{
|
||||
System.out.println("\t unable to register updates");
|
||||
}
|
||||
|
||||
i2pRouter.runRouter();
|
||||
}
|
||||
|
||||
private static File selectHome() { //throws Exception {
|
||||
private File selectHome() { //throws Exception {
|
||||
if (SystemVersion.isWindows()) {
|
||||
File home = new File(System.getProperty("user.home"));
|
||||
File appData = new File(home, "AppData");
|
||||
@ -53,4 +68,18 @@ public class WinLauncher extends WindowsUpdatePostProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
private UpdateManager updateManagerClient() {
|
||||
ClientAppManager clmgr = i2pRouter.getContext().getCurrentContext().clientAppManager();
|
||||
if (clmgr == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
UpdateManager upmgr = (UpdateManager) clmgr.getRegisteredApp(UpdateManager.APP_NAME);
|
||||
if (upmgr == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return upmgr;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,23 +2,28 @@ package net.i2p.router;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static net.i2p.update.UpdateType.*;
|
||||
import net.i2p.update.UpdateType;
|
||||
import net.i2p.update.UpdatePostProcessor;
|
||||
import net.i2p.util.SystemVersion;
|
||||
|
||||
import java.lang.ProcessBuilder;
|
||||
import java.lang.Process;
|
||||
import java.lang.InterruptedException;
|
||||
|
||||
public class WindowsUpdatePostProcessor {
|
||||
protected static Router i2pRouter = null;
|
||||
public class WindowsUpdatePostProcessor implements UpdatePostProcessor {
|
||||
protected Router i2pRouter = null;
|
||||
public void updateDownloadedandVerified(UpdateType type, int fileType, String version, File file) throws IOException {
|
||||
if (fileType == 6) {
|
||||
if (runUpdate(file)) {
|
||||
try {
|
||||
if (shutdownGracefullyAndRerun()) {
|
||||
}
|
||||
} else {
|
||||
} catch (InterruptedException ie) {
|
||||
i2pRouter.cancelGracefulShutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -45,10 +50,11 @@ public class WindowsUpdatePostProcessor {
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean shutdownGracefullyAndRerun() {
|
||||
private boolean shutdownGracefullyAndRerun() throws InterruptedException {
|
||||
i2pRouter.shutdownGracefully();
|
||||
ProcessBuilder pb = new ProcessBuilder("cmd", "/c", selectProgramFile().getAbsolutePath());
|
||||
while (i2pRouter.gracefulShutdownInProgress()) {
|
||||
TimeUnit.MILLISECONDS.sleep(125);
|
||||
}
|
||||
if (i2pRouter.isFinalShutdownInProgress()) {
|
||||
try {
|
||||
@ -62,7 +68,7 @@ public class WindowsUpdatePostProcessor {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected static File selectProgramFile() {
|
||||
protected File selectProgramFile() {
|
||||
if (SystemVersion.isWindows()) {
|
||||
File jrehome = new File(System.getProperty("java.home"));
|
||||
File programs = jrehome.getParentFile();
|
||||
@ -74,7 +80,7 @@ public class WindowsUpdatePostProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
protected static File selectProgramFileExe() {
|
||||
protected File selectProgramFileExe() {
|
||||
File pfpath = selectProgramFile();
|
||||
if (SystemVersion.isWindows()) {
|
||||
File app = new File(pfpath, "I2P.exe");
|
||||
|
Reference in New Issue
Block a user