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:13:27 -04:00
parent f9a7f8ab2d
commit 079ef87c8f

View File

@@ -1,5 +1,7 @@
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;
@@ -8,19 +10,15 @@ import java.util.*;
import java.util.logging.FileHandler; import java.util.logging.FileHandler;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.logging.SimpleFormatter; import java.util.logging.SimpleFormatter;
import net.i2p.crypto.*;
import net.i2p.app.ClientAppManager; import net.i2p.app.ClientAppManager;
import net.i2p.router.RouterLaunch; import net.i2p.crypto.*;
import net.i2p.i2pfirefox.*;
import net.i2p.router.Router; import net.i2p.router.Router;
import net.i2p.router.RouterLaunch;
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.util.SystemVersion; import net.i2p.util.SystemVersion;
import net.i2p.update.*;
import net.i2p.i2pfirefox.*;
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
@@ -54,11 +52,13 @@ public class WinLauncher {
boolean usabilityMode = false; boolean usabilityMode = false;
boolean chromiumFirst = false; boolean chromiumFirst = false;
if (args != null && args.length > 0) { if (args != null) {
if (args.length > 0) {
logger.info("checking for private browsing"); logger.info("checking for private browsing");
if (args[0].equals("-private")) { if (args[0].equals("-private")) {
privateBrowsing = true; privateBrowsing = true;
logger.info("Private browsing is true, profile will be discarded at end of session."); logger.info(
"Private browsing is true, profile will be discarded at end of session.");
} }
if (args[0].equals("-chromium")) { if (args[0].equals("-chromium")) {
chromiumFirst = true; chromiumFirst = true;
@@ -66,7 +66,9 @@ public class WinLauncher {
} }
if (args[0].equals("-usability")) { if (args[0].equals("-usability")) {
usabilityMode = true; usabilityMode = true;
logger.info("Usability mode is true, using alternate extensions loadout."); logger.info(
"Usability mode is true, using alternate extensions loadout.");
}
} }
} }
@@ -74,7 +76,9 @@ public class WinLauncher {
if (!programs.exists()) if (!programs.exists())
programs.mkdirs(); programs.mkdirs();
else if (!programs.isDirectory()) { else if (!programs.isDirectory()) {
logger.warning(programs + " exists but is not a directory. Please get it out of the way"); logger.warning(
programs +
" exists but is not a directory. Please get it out of the way");
System.exit(1); System.exit(1);
} }
@@ -82,7 +86,9 @@ public class WinLauncher {
if (!home.exists()) if (!home.exists())
home.mkdirs(); home.mkdirs();
else if (!home.isDirectory()) { else if (!home.isDirectory()) {
logger.warning(home + " exists but is not a directory. Please get it out of the way"); logger.warning(
home +
" exists but is not a directory. Please get it out of the way");
System.exit(1); System.exit(1);
} }
@@ -98,9 +104,11 @@ public class WinLauncher {
System.setProperty("i2p.dir.base", programs.getAbsolutePath()); System.setProperty("i2p.dir.base", programs.getAbsolutePath());
System.setProperty("i2p.dir.config", home.getAbsolutePath()); System.setProperty("i2p.dir.config", home.getAbsolutePath());
System.setProperty("router.pid", String.valueOf(ProcessHandle.current().pid())); System.setProperty("router.pid",
logger.info("\t" + System.getProperty("i2p.dir.base") + "\n\t" + System.getProperty("i2p.dir.config") String.valueOf(ProcessHandle.current().pid()));
+ "\n\t" + System.getProperty("router.pid")); logger.info("\t" + System.getProperty("i2p.dir.base") + "\n\t" +
System.getProperty("i2p.dir.config") + "\n\t" +
System.getProperty("router.pid"));
System.setProperty("user.dir", programs.getAbsolutePath()); System.setProperty("user.dir", programs.getAbsolutePath());
// wupp.i2pRouter = new Router(System.getProperties()); // wupp.i2pRouter = new Router(System.getProperties());
@@ -115,7 +123,8 @@ public class WinLauncher {
RouterLaunch.main(args); RouterLaunch.main(args);
} }
// see https://stackoverflow.com/questions/434718/sockets-discover-port-availability-using-java // see
// https://stackoverflow.com/questions/434718/sockets-discover-port-availability-using-java
public static boolean isAvailable(int portNr) { public static boolean isAvailable(int portNr) {
boolean portFree; boolean portFree;
try (var ignored = new ServerSocket(portNr)) { try (var ignored = new ServerSocket(portNr)) {
@@ -136,14 +145,15 @@ public class WinLauncher {
if (!isAvailable(7654)) { if (!isAvailable(7654)) {
return true; return true;
} }
// check for the existence of router.ping file, if it's less then 2 minutes old, // check for the existence of router.ping file, if it's less then 2 minutes
// exit // old, exit
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()) {
long diff = System.currentTimeMillis() - ping.lastModified(); long diff = System.currentTimeMillis() - ping.lastModified();
if (diff < 60 * 1000) { if (diff < 60 * 1000) {
logger.info("router.ping exists and is less than 1 minute old, I2P appears to be running already."); logger.info(
"router.ping exists and is less than 1 minute old, I2P appears to be running already.");
logger.info("If I2P is not running, wait 60 seconds and try again."); logger.info("If I2P is not running, wait 60 seconds and try again.");
return true; return true;
} }
@@ -155,7 +165,7 @@ public class WinLauncher {
// first wait for the RouterContext to appear // first wait for the RouterContext to appear
RouterContext ctx; RouterContext ctx;
while ((ctx = (RouterContext) RouterContext.getCurrentContext()) == null) { while ((ctx = (RouterContext)RouterContext.getCurrentContext()) == null) {
sleep(1000); sleep(1000);
} }
@@ -167,7 +177,8 @@ public class WinLauncher {
} }
UpdateManager um; UpdateManager um;
while ((um = (UpdateManager) cam.getRegisteredApp(UpdateManager.APP_NAME)) == null) { while ((um = (UpdateManager)cam.getRegisteredApp(UpdateManager.APP_NAME)) ==
null) {
sleep(1000); sleep(1000);
} }
@@ -202,12 +213,14 @@ public class WinLauncher {
File local = new File(appData, "Local"); File local = new File(appData, "Local");
File i2p; File i2p;
i2p = new File(local, "I2P"); i2p = new File(local, "I2P");
logger.info("Windows jpackage wrapper started, using: " + i2p + " as base config"); logger.info("Windows jpackage wrapper started, using: " + i2p +
" as base config");
return i2p.getAbsoluteFile(); return i2p.getAbsoluteFile();
} else { } else {
File jrehome = new File(System.getProperty("java.home")); File jrehome = new File(System.getProperty("java.home"));
File programs = new File(jrehome.getParentFile().getParentFile(), ".i2p"); File programs = new File(jrehome.getParentFile().getParentFile(), ".i2p");
logger.info("Linux portable jpackage wrapper started, using: " + programs + " as base config"); logger.info("Linux portable jpackage wrapper started, using: " +
programs + " as base config");
return programs.getAbsoluteFile(); return programs.getAbsoluteFile();
} }
} }
@@ -226,12 +239,14 @@ public class WinLauncher {
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();
logger.info("Windows portable jpackage wrapper found, using: " + programs + " as working config"); logger.info("Windows portable jpackage wrapper found, using: " +
programs + " as working config");
return programs.getAbsoluteFile(); return programs.getAbsoluteFile();
} else { } else {
File jrehome = new File(System.getProperty("java.home")); File jrehome = new File(System.getProperty("java.home"));
File programs = new File(jrehome.getParentFile().getParentFile(), "i2p"); File programs = new File(jrehome.getParentFile().getParentFile(), "i2p");
logger.info("Linux portable jpackage wrapper found, using: " + programs + " as working config"); logger.info("Linux portable jpackage wrapper found, using: " + programs +
" as working config");
return programs.getAbsoluteFile(); return programs.getAbsoluteFile();
} }
} }