瀏覽代碼

Accept DMDIRC_HOME env var for config dir

Fixes issue 3634

Change-Id: I41717782a832e9e799123ff34ae464de60108a62
Reviewed-on: http://gerrit.dmdirc.com/643
Automatic-Compile: Shane Mc Cormack <shane@dmdirc.com>
Reviewed-by: Shane Mc Cormack <shane@dmdirc.com>
tags/0.6.3b1
Chris Smith 14 年之前
父節點
當前提交
4e56bd188a
共有 1 個檔案被更改,包括 33 行新增23 行删除
  1. 33
    23
      src/com/dmdirc/Main.java

+ 33
- 23
src/com/dmdirc/Main.java 查看文件

@@ -380,33 +380,43 @@ public final class Main {
380 380
      */
381 381
     public static String getConfigDir() {
382 382
         if (configdir == null) {
383
-            final String fs = System.getProperty("file.separator");
384
-            final String osName = System.getProperty("os.name");
385
-            if (osName.startsWith("Mac OS")) {
386
-                configdir = System.getProperty("user.home") + fs + "Library"
387
-                        + fs + "Preferences" + fs + "DMDirc" + fs;
388
-            } else if (osName.startsWith("Windows")) {
389
-                if (System.getenv("APPDATA") == null) {
390
-                    configdir = System.getProperty("user.home") + fs + "DMDirc" + fs;
391
-                } else {
392
-                    configdir = System.getenv("APPDATA") + fs + "DMDirc" + fs;
393
-                }
383
+            initialiseConfigDir();
384
+        }
385
+
386
+        return configdir;
387
+    }
388
+
389
+    /**
390
+     * Initialises the location of the configuration directory.
391
+     */
392
+    protected static void initialiseConfigDir() {
393
+        final String fs = System.getProperty("file.separator");
394
+        final String osName = System.getProperty("os.name");
395
+
396
+        if (System.getenv("DMDIRC_HOME") != null) {
397
+            configdir = System.getenv("DMDIRC_HOME");
398
+        } else if (osName.startsWith("Mac OS")) {
399
+            configdir = System.getProperty("user.home") + fs + "Library"
400
+                    + fs + "Preferences" + fs + "DMDirc" + fs;
401
+        } else if (osName.startsWith("Windows")) {
402
+            if (System.getenv("APPDATA") == null) {
403
+                configdir = System.getProperty("user.home") + fs + "DMDirc" + fs;
394 404
             } else {
395
-                configdir = System.getProperty("user.home") + fs + ".DMDirc" + fs;
396
-                final File testFile = new File(configdir);
397
-                if (!testFile.exists()) {
398
-                    final String configHome = System.getenv("XDG_CONFIG_HOME");
399
-                    configdir = (configHome == null || configHome.isEmpty()) ?
400
-                        System.getProperty("user.home") + fs + ".config" + fs :
401
-                        configHome;
402
-                    configdir += fs + "DMDirc" + fs;
403
-                }
405
+                configdir = System.getenv("APPDATA") + fs + "DMDirc" + fs;
406
+            }
407
+        } else {
408
+            configdir = System.getProperty("user.home") + fs + ".DMDirc" + fs;
409
+            final File testFile = new File(configdir);
410
+            if (!testFile.exists()) {
411
+                final String configHome = System.getenv("XDG_CONFIG_HOME");
412
+                configdir = (configHome == null || configHome.isEmpty()) ?
413
+                    System.getProperty("user.home") + fs + ".config" + fs :
414
+                    configHome;
415
+                configdir += fs + "DMDirc" + fs;
404 416
             }
405
-
406
-            configdir = new File(configdir).getAbsolutePath() + fs;
407 417
         }
408 418
 
409
-        return configdir;
419
+        configdir = new File(configdir).getAbsolutePath() + fs;
410 420
     }
411 421
 
412 422
     /**

Loading…
取消
儲存