2021-04-03 16:39:26 -04:00
|
|
|
package net.i2p.router;
|
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
import java.util.*;
|
2021-07-01 19:52:21 -04:00
|
|
|
|
|
|
|
import net.i2p.app.ClientAppManager;
|
2021-04-03 18:08:44 -04:00
|
|
|
import net.i2p.router.RouterLaunch;
|
2021-07-01 16:55:29 -04:00
|
|
|
import net.i2p.router.Router;
|
2021-07-01 19:52:21 -04:00
|
|
|
import net.i2p.update.UpdateManager;
|
|
|
|
import net.i2p.update.UpdatePostProcessor;
|
2021-05-25 13:46:37 -04:00
|
|
|
import net.i2p.util.SystemVersion;
|
2021-04-03 16:39:26 -04:00
|
|
|
|
2021-07-01 19:52:21 -04:00
|
|
|
import static net.i2p.update.UpdateType.*;
|
|
|
|
|
2021-04-03 16:39:26 -04:00
|
|
|
/**
|
2021-04-03 18:08:44 -04:00
|
|
|
* Launches a router from %PROGRAMFILES%/I2P using configuration data in
|
|
|
|
* %LOCALAPPDATA%/I2P.. Uses Java 9 APIs.
|
|
|
|
|
2021-04-03 16:39:26 -04:00
|
|
|
* Sets the following properties:
|
|
|
|
* i2p.dir.base - this points to the (read-only) resources inside the bundle
|
2021-04-03 18:08:44 -04:00
|
|
|
* i2p.dir.config this points to the (read-write) config directory in local appdata
|
2021-04-03 16:39:26 -04:00
|
|
|
* router.pid - the pid of the java process.
|
|
|
|
*/
|
2021-08-02 14:17:02 -04:00
|
|
|
public class WinLauncher {
|
|
|
|
private static WindowsUpdatePostProcessor wupp = new WindowsUpdatePostProcessor();
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
|
File programs = wupp.selectProgramFile();
|
2021-04-03 16:39:26 -04:00
|
|
|
|
2021-04-03 18:08:44 -04:00
|
|
|
File home = selectHome();
|
|
|
|
if (!home.exists())
|
|
|
|
home.mkdirs();
|
|
|
|
else if (!home.isDirectory()) {
|
|
|
|
System.err.println(home + " exists but is not a directory. Please get it out of the way");
|
|
|
|
System.exit(1);
|
|
|
|
}
|
|
|
|
|
2021-04-03 19:16:32 -04:00
|
|
|
System.setProperty("i2p.dir.base", programs.getAbsolutePath());
|
2021-04-03 18:08:44 -04:00
|
|
|
System.setProperty("i2p.dir.config", home.getAbsolutePath());
|
2021-04-03 16:39:26 -04:00
|
|
|
System.setProperty("router.pid", String.valueOf(ProcessHandle.current().pid()));
|
2021-04-03 19:16:32 -04:00
|
|
|
System.out.println("\t"+System.getProperty("i2p.dir.base") +"\n\t"+System.getProperty("i2p.dir.config")+"\n\t"+ System.getProperty("router.pid"));
|
2021-04-03 16:39:26 -04:00
|
|
|
|
2021-08-02 14:17:02 -04:00
|
|
|
wupp.i2pRouter = new Router(System.getProperties());
|
|
|
|
System.out.println("Router is configured");
|
2021-07-01 16:55:29 -04:00
|
|
|
|
2021-07-01 19:52:21 -04:00
|
|
|
UpdateManager upmgr = updateManagerClient();
|
2021-07-03 22:39:54 -04:00
|
|
|
while (upmgr == null) {
|
2021-07-04 10:35:07 -04:00
|
|
|
upmgr = updateManagerClient();
|
2021-08-02 14:17:02 -04:00
|
|
|
System.out.println("Waiting for update manager so we can pull our own updates");
|
2021-07-01 19:52:21 -04:00
|
|
|
}
|
2021-08-02 14:17:02 -04:00
|
|
|
upmgr.register(wupp, ROUTER_SIGNED_SU3, 6);
|
|
|
|
System.out.println("Registered signed updates");
|
|
|
|
upmgr.register(wupp, ROUTER_DEV_SU3, 6);
|
|
|
|
System.out.println("Registered dev updates");
|
2021-07-01 19:52:21 -04:00
|
|
|
|
2021-08-02 14:17:02 -04:00
|
|
|
wupp.i2pRouter.runRouter();
|
2021-04-03 16:39:26 -04:00
|
|
|
}
|
|
|
|
|
2021-08-02 14:17:02 -04:00
|
|
|
private static File selectHome() { //throws Exception {
|
2021-05-25 13:46:37 -04:00
|
|
|
if (SystemVersion.isWindows()) {
|
|
|
|
File home = new File(System.getProperty("user.home"));
|
|
|
|
File appData = new File(home, "AppData");
|
|
|
|
File local = new File(appData, "Local");
|
2021-07-01 16:55:29 -04:00
|
|
|
File i2p;
|
2021-05-25 13:46:37 -04:00
|
|
|
i2p = new File(local, "I2P");
|
2021-08-02 14:17:02 -04:00
|
|
|
System.out.println("Windows jpackage wrapper started, using: " + i2p + "as config");
|
2021-05-25 13:46:37 -04:00
|
|
|
return i2p.getAbsoluteFile();
|
|
|
|
} else {
|
|
|
|
File jrehome = new File(System.getProperty("java.home"));
|
|
|
|
File programs = new File(jrehome.getParentFile().getParentFile(), ".i2p");
|
2021-08-02 14:17:02 -04:00
|
|
|
System.out.println("Linux portable jpackage wrapper started, using: " + programs + "as config");
|
2021-05-25 13:46:37 -04:00
|
|
|
return programs.getAbsoluteFile();
|
|
|
|
}
|
2021-04-03 18:08:44 -04:00
|
|
|
}
|
2021-04-03 16:39:26 -04:00
|
|
|
|
2021-08-02 14:17:02 -04:00
|
|
|
private static UpdateManager updateManagerClient() {
|
|
|
|
ClientAppManager clmgr = wupp.i2pRouter.getContext().getCurrentContext().clientAppManager();
|
2021-07-01 19:52:21 -04:00
|
|
|
if (clmgr == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdateManager upmgr = (UpdateManager) clmgr.getRegisteredApp(UpdateManager.APP_NAME);
|
|
|
|
if (upmgr == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return upmgr;
|
|
|
|
}
|
|
|
|
|
2021-04-03 16:39:26 -04:00
|
|
|
}
|