From 335409f1d268f245d70103eb9e7c5160655b8ad4 Mon Sep 17 00:00:00 2001
From: idk <hankhill19580@gmail.com>
Date: Mon, 18 Jan 2021 00:26:33 -0500
Subject: [PATCH] Find and fix the bug which appears in
 'https://old.reddit.com/r/i2p/search?q=console&restrict_sr=on&sort=relevance&t=all'
 a bunch of Reddit posts, due to a mistake in the Firefox Profile Installer
 which expected router.config to be in the (deprecated)Roaming application
 data, even though it was in the Local Application Data, and if it did not
 exist, created it. If the (deprecated)Roaming application data directory had
 a router.config file, then I2P attempted to use the Roaming application
 directory, and the user could end up with a router that had no client apps
 configured, resulting in a poor UX

---
 .../net/i2p/router/startup/WorkingDir.java    | 21 ++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/router/java/src/net/i2p/router/startup/WorkingDir.java b/router/java/src/net/i2p/router/startup/WorkingDir.java
index cbd5444633..cce533aaeb 100644
--- a/router/java/src/net/i2p/router/startup/WorkingDir.java
+++ b/router/java/src/net/i2p/router/startup/WorkingDir.java
@@ -81,22 +81,33 @@ public class WorkingDir {
             String home = System.getProperty("user.home");
             if (isWindows) {
                 String appdata = System.getenv("LOCALAPPDATA");
-                if (appdata != null)
+                if (appdata != null) {
                     home = appdata;
+                }
                 // Don't mess with existing Roaming Application Data installs,
                 // in case somebody is using roaming appdata for a reason
                 // already. In new installs, use local appdata by default. -idk
                 appdata = System.getenv("APPDATA");
                 if (appdata != null) {
                     File checkOld = new File(appdata, WORKING_DIR_DEFAULT_WINDOWS);
-                    if (checkOld.exists() && checkOld.isDirectory())
-                        home = appdata;
+                    if (checkOld.exists() && checkOld.isDirectory()){
+                        File routerConfig = new File(checkOld.getAbsolutePath(), "router.config");
+                        // The Firefox profile installer was mistakenly using the Roaming application data
+                        // which is synced between devices on some Windows machines using MS cloud services,
+                        // instead of the local application data which is used by default.
+                        // It would create the router.config file in an empty directory, which the router would
+                        // then attempt to use, resulting in a router with no client applications. Checking
+                        // for clients.config.d determines if the directory is "Real" or not.
+                        File clientAppsConfig = new File(checkOld.getAbsolutePath(), "clients.config.d");
+                        if (routerConfig.exists() && clientAppsConfig.exists() && clientAppsConfig.isDirectory())
+                            home = appdata;
+                    }
                 }
                 dirf = new SecureDirectory(home, WORKING_DIR_DEFAULT_WINDOWS);
             } else if (SystemVersion.isMac()) {
                 String appdata = "/Library/Application Support/";
-		File old = new File(home,WORKING_DIR_DEFAULT);
-		if (old.exists() && old.isDirectory())
+                File old = new File(home,WORKING_DIR_DEFAULT);
+                if (old.exists() && old.isDirectory())
                     dirf = new SecureDirectory(home, WORKING_DIR_DEFAULT);
                 else {
                     home = home+appdata;
-- 
GitLab