Split the Makefile up into a bunch of categorized sub-files.
This commit is contained in:
@@ -17,15 +17,17 @@ import static net.i2p.update.UpdateType.*;
|
||||
|
||||
/**
|
||||
* Launches a router from %PROGRAMFILES%/I2P using configuration data in
|
||||
* %LOCALAPPDATA%/I2P.. Uses Java 9 APIs.
|
||||
|
||||
* %LOCALAPPDATA%/I2P.. Uses Java 9 APIs.
|
||||
*
|
||||
* Sets the following properties:
|
||||
* i2p.dir.base - this points to the (read-only) resources inside the bundle
|
||||
* i2p.dir.config this points to the (read-write) config directory in local appdata
|
||||
* i2p.dir.config this points to the (read-write) config directory in local
|
||||
* appdata
|
||||
* router.pid - the pid of the java process.
|
||||
*/
|
||||
public class WinLauncher {
|
||||
private static WindowsUpdatePostProcessor wupp = new WindowsUpdatePostProcessor();
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
File programs = wupp.selectProgramFile();
|
||||
if (!programs.exists())
|
||||
@@ -46,7 +48,8 @@ public class WinLauncher {
|
||||
System.setProperty("i2p.dir.base", programs.getAbsolutePath());
|
||||
System.setProperty("i2p.dir.config", home.getAbsolutePath());
|
||||
System.setProperty("router.pid", String.valueOf(ProcessHandle.current().pid()));
|
||||
System.out.println("\t"+System.getProperty("i2p.dir.base") +"\n\t"+System.getProperty("i2p.dir.config")+"\n\t"+ System.getProperty("router.pid"));
|
||||
System.out.println("\t" + System.getProperty("i2p.dir.base") + "\n\t" + System.getProperty("i2p.dir.config")
|
||||
+ "\n\t" + System.getProperty("router.pid"));
|
||||
|
||||
wupp.i2pRouter = new Router(System.getProperties());
|
||||
System.out.println("Router is configured");
|
||||
@@ -63,7 +66,7 @@ public class WinLauncher {
|
||||
|
||||
// first wait for the RouterContext to appear
|
||||
RouterContext ctx;
|
||||
while ((ctx = (RouterContext) wupp.i2pRouter.getContext().getCurrentContext()) == null) {
|
||||
while ((ctx = (RouterContext) RouterContext.getCurrentContext()) == null) {
|
||||
sleep(1000);
|
||||
}
|
||||
|
||||
@@ -88,7 +91,7 @@ public class WinLauncher {
|
||||
}
|
||||
}
|
||||
|
||||
private static File selectHome() { //throws Exception {
|
||||
private static File selectHome() { // throws Exception {
|
||||
if (SystemVersion.isWindows()) {
|
||||
File home = new File(System.getProperty("user.home"));
|
||||
File appData = new File(home, "AppData");
|
||||
|
||||
@@ -11,20 +11,20 @@ class WinUpdateProcess implements Runnable {
|
||||
private final RouterContext ctx;
|
||||
private final Supplier<String> versionSupplier;
|
||||
private final Supplier<File> fileSupplier;
|
||||
|
||||
|
||||
WinUpdateProcess(RouterContext ctx, Supplier<String> versionSupplier, Supplier<File> fileSupplier) {
|
||||
this.ctx = ctx;
|
||||
this.versionSupplier = versionSupplier;
|
||||
this.fileSupplier = fileSupplier;
|
||||
}
|
||||
|
||||
private File workDir() throws IOException{
|
||||
|
||||
private File workDir() throws IOException {
|
||||
if (ctx != null) {
|
||||
File workDir = new File(ctx.getConfigDir().getAbsolutePath(), "i2p_update_win");
|
||||
if (workDir.exists()) {
|
||||
if (workDir.isFile())
|
||||
throw new IOException(workDir + " exists but is a file, get it out of the way");
|
||||
return null;
|
||||
return null;
|
||||
} else {
|
||||
workDir.mkdirs();
|
||||
}
|
||||
@@ -35,9 +35,9 @@ class WinUpdateProcess implements Runnable {
|
||||
|
||||
private void runUpdateInstaller() throws IOException {
|
||||
String version = versionSupplier.get();
|
||||
File file = fileSupplier.get();
|
||||
if (file == null)
|
||||
return;
|
||||
File file = fileSupplier.get();
|
||||
if (file == null)
|
||||
return;
|
||||
|
||||
var workingDir = workDir();
|
||||
var logFile = new File(workingDir, "log-" + version + ".txt");
|
||||
@@ -52,12 +52,9 @@ class WinUpdateProcess implements Runnable {
|
||||
env.put("RESTART_I2P", "true");
|
||||
|
||||
try {
|
||||
pb.directory(workingDir).
|
||||
redirectErrorStream(true).
|
||||
redirectOutput(logFile).
|
||||
start();
|
||||
pb.directory(workingDir).redirectErrorStream(true).redirectOutput(logFile).start();
|
||||
} catch (IOException ex) {
|
||||
System.out.println("Unable to run update-program in background. Update will fail.");
|
||||
System.out.println("Unable to run update-program in background. Update will fail.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +62,7 @@ class WinUpdateProcess implements Runnable {
|
||||
public void run() {
|
||||
try {
|
||||
runUpdateInstaller();
|
||||
} catch(IOException ioe) {
|
||||
} catch (IOException ioe) {
|
||||
System.out.println("Error running updater, update may fail." + ioe);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.*;
|
||||
|
||||
|
||||
import net.i2p.crypto.*;
|
||||
import static net.i2p.update.UpdateType.*;
|
||||
import net.i2p.I2PAppContext;
|
||||
@@ -18,12 +17,11 @@ import java.lang.ProcessBuilder;
|
||||
import java.lang.Process;
|
||||
import java.lang.InterruptedException;
|
||||
|
||||
|
||||
public class WindowsUpdatePostProcessor implements UpdatePostProcessor {
|
||||
private final Log _log = I2PAppContext.getGlobalContext().logManager().getLog(WindowsUpdatePostProcessor.class);
|
||||
private final RouterContext ctx;
|
||||
protected static Router i2pRouter = null;
|
||||
|
||||
|
||||
private final AtomicBoolean hook = new AtomicBoolean();
|
||||
|
||||
private volatile String version;
|
||||
@@ -32,7 +30,7 @@ public class WindowsUpdatePostProcessor implements UpdatePostProcessor {
|
||||
private final String fileName = "i2p-jpackage-update.exe";
|
||||
|
||||
WindowsUpdatePostProcessor() {
|
||||
this.ctx = null;
|
||||
this.ctx = null;
|
||||
}
|
||||
|
||||
WindowsUpdatePostProcessor(RouterContext ctx) {
|
||||
@@ -42,12 +40,13 @@ public class WindowsUpdatePostProcessor implements UpdatePostProcessor {
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
|
||||
public File getFile() {
|
||||
return positionedFile;
|
||||
}
|
||||
|
||||
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 {
|
||||
_log.info("Got an update to post-process");
|
||||
|
||||
if (type != UpdateType.ROUTER_SIGNED_SU3 && type != UpdateType.ROUTER_DEV_SU3) {
|
||||
@@ -59,11 +58,11 @@ public class WindowsUpdatePostProcessor implements UpdatePostProcessor {
|
||||
_log.warn("Unsupported file type " + fileType);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
this.positionedFile = moveUpdateInstaller(file);
|
||||
this.version = version;
|
||||
|
||||
if (!hook.compareAndSet(false,true)) {
|
||||
|
||||
if (!hook.compareAndSet(false, true)) {
|
||||
_log.info("shutdown hook was already set");
|
||||
return;
|
||||
}
|
||||
@@ -72,28 +71,30 @@ public class WindowsUpdatePostProcessor implements UpdatePostProcessor {
|
||||
ctx.addFinalShutdownTask(new WinUpdateProcess(ctx, this::getVersion, this::getFile));
|
||||
|
||||
}
|
||||
|
||||
|
||||
private File moveUpdateInstaller(File file) throws IOException {
|
||||
RouterContext i2pContext = i2pRouter.getContext();
|
||||
if (i2pContext != null) {
|
||||
File newFile = new File(workDir(), fileName);
|
||||
boolean renamedStatus = file.renameTo(newFile);
|
||||
if (renamedStatus)
|
||||
return newFile;
|
||||
return newFile;
|
||||
else
|
||||
throw new IOException("WindowsUpdatePostProcesssor unable to move file to working directory, update will fail");
|
||||
throw new IOException(
|
||||
"WindowsUpdatePostProcesssor unable to move file to working directory, update will fail");
|
||||
}
|
||||
throw new IOException("Router context not available to WindowsUpdatePostProcesssor, unable to find working directory, update will fail");
|
||||
throw new IOException(
|
||||
"Router context not available to WindowsUpdatePostProcesssor, unable to find working directory, update will fail");
|
||||
}
|
||||
|
||||
private File workDir() throws IOException{
|
||||
private File workDir() throws IOException {
|
||||
RouterContext i2pContext = i2pRouter.getContext();
|
||||
if (i2pContext != null) {
|
||||
File workDir = new File(i2pContext.getConfigDir().getAbsolutePath(), "i2p_update_win");
|
||||
if (workDir.exists()) {
|
||||
if (workDir.isFile())
|
||||
throw new IOException(workDir + " exists but is a file, get it out of the way");
|
||||
return null;
|
||||
return null;
|
||||
} else {
|
||||
workDir.mkdirs();
|
||||
}
|
||||
@@ -106,12 +107,12 @@ public class WindowsUpdatePostProcessor implements UpdatePostProcessor {
|
||||
if (SystemVersion.isWindows()) {
|
||||
File jrehome = new File(System.getProperty("java.home"));
|
||||
File programs = jrehome.getParentFile();
|
||||
System.out.println("Windows portable jpackage wrapper found, using: " + programs + " as working config");
|
||||
System.out.println("Windows portable jpackage wrapper found, using: " + programs + " as working config");
|
||||
return programs.getAbsoluteFile();
|
||||
} else {
|
||||
File jrehome = new File(System.getProperty("java.home"));
|
||||
File programs = new File(jrehome.getParentFile().getParentFile(), "i2p");
|
||||
System.out.println("Linux portable jpackage wrapper found, using: " + programs + " as working config");
|
||||
System.out.println("Linux portable jpackage wrapper found, using: " + programs + " as working config");
|
||||
return programs.getAbsoluteFile();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user