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