From f6ec3f66f8ea7fc32fb00e4c4e4f49693459a54f Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Fri, 24 Jul 2009 15:35:58 +0000
Subject: [PATCH]     * Router: Support i2p.dir.base and i2p.dir.config passed
 in via properties

---
 core/java/src/net/i2p/util/WorkingDir.java | 20 +++++++++++++++-----
 router/java/src/net/i2p/router/Router.java |  2 +-
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/core/java/src/net/i2p/util/WorkingDir.java b/core/java/src/net/i2p/util/WorkingDir.java
index a003d2b29e..ef037a6448 100644
--- a/core/java/src/net/i2p/util/WorkingDir.java
+++ b/core/java/src/net/i2p/util/WorkingDir.java
@@ -52,8 +52,12 @@ public class WorkingDir {
      * Only call this once on router invocation.
      * Caller should store the return value for future reference.
      */
-    public static String getWorkingDir(boolean migrateOldConfig) {
-        String dir = System.getProperty(PROP_WORKING_DIR);
+    public static String getWorkingDir(Properties envProps, boolean migrateOldConfig) {
+        String dir = null;
+        if (envProps != null)
+            dir = envProps.getProperty(PROP_WORKING_DIR);
+        if (dir == null)
+            dir = System.getProperty(PROP_WORKING_DIR);
         boolean isWindows = System.getProperty("os.name").startsWith("Win");
         File dirf = null;
         if (dir != null) {
@@ -69,10 +73,16 @@ public class WorkingDir {
                 dirf = new File(home, WORKING_DIR_DEFAULT);
             }
         }
+
         // where we are now
-        String cwd = System.getProperty(PROP_BASE_DIR);
-        if (cwd == null)
-            cwd = System.getProperty("user.dir");
+        String cwd = null;
+        if (envProps != null)
+            cwd = envProps.getProperty(PROP_BASE_DIR);
+        if (cwd == null) {
+            cwd = System.getProperty(PROP_BASE_DIR);
+            if (cwd == null)
+                cwd = System.getProperty("user.dir");
+        }
 
         // Check for a hosts.txt file, if it exists then I2P is there
         File oldDirf = new File(cwd);
diff --git a/router/java/src/net/i2p/router/Router.java b/router/java/src/net/i2p/router/Router.java
index 34e8f40dbf..118d903b9d 100644
--- a/router/java/src/net/i2p/router/Router.java
+++ b/router/java/src/net/i2p/router/Router.java
@@ -137,7 +137,7 @@ public class Router {
         // Do we copy all the data files to the new directory? default false
         String migrate = System.getProperty("i2p.dir.migrate");
         boolean migrateFiles = Boolean.valueOf(migrate).booleanValue();
-        String userDir = WorkingDir.getWorkingDir(migrateFiles);
+        String userDir = WorkingDir.getWorkingDir(envProps, migrateFiles);
 
         // Use the router.config file specified in the router.configLocation property
         // (default "router.config"),
-- 
GitLab