Pārlūkot izejas kodu

Use new FileUtils methods for in the client.

Change-Id: I8dd7ba2f57c43ca64d7ea978a34e00749396a035
Depends-On: I20d3a7b908bbeae833ffffe0598b99bde47021c7
Reviewed-on: http://gerrit.dmdirc.com/4074
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Chris Smith <chris@dmdirc.com>
pull/1/head
Greg Holmes 9 gadus atpakaļ
vecāks
revīzija
961bf642ac

+ 6
- 16
src/com/dmdirc/updater/components/ClientComponent.java Parādīt failu

@@ -22,16 +22,15 @@
22 22
 
23 23
 package com.dmdirc.updater.components;
24 24
 
25
+import com.dmdirc.Main;
25 26
 import com.dmdirc.interfaces.config.IdentityController;
26 27
 import com.dmdirc.ui.StatusMessage;
27 28
 import com.dmdirc.ui.core.components.StatusBarManager;
28 29
 import com.dmdirc.updater.UpdateComponent;
29 30
 import com.dmdirc.updater.Version;
31
+import com.dmdirc.util.io.FileUtils;
30 32
 
31 33
 import java.io.File;
32
-import java.net.URISyntaxException;
33
-import java.nio.file.Path;
34
-import java.nio.file.Paths;
35 34
 
36 35
 import javax.inject.Inject;
37 36
 
@@ -90,23 +89,14 @@ public class ClientComponent implements UpdateComponent {
90 89
                 + File.separator + ".DMDirc.jar");
91 90
 
92 91
         if (requiresManualInstall()) {
93
-            Path appPath;
94
-            String appDir;
95
-            try {
96
-                appPath = Paths.get(getClass().getProtectionDomain().getCodeSource()
97
-                        .getLocation().toURI());
98
-                appDir = appPath.toAbsolutePath().toString();
99
-            } catch (URISyntaxException e) {
100
-                appPath = null;
101
-                appDir = "[Error getting path]";
102
-            }
103
-            if (appPath != null && appPath.getFileName().endsWith(".jar")) {
92
+            if (FileUtils.isRunningFromJar(Main.class)) {
104 93
                 return "A new version of DMDirc has been downloaded, but as you\n"
105 94
                         + "do not seem to be using the DMDirc launcher, it will\n"
106 95
                         + "not be installed automatically.\n\n"
107 96
                         + "To install this update manually, please replace the\n"
108 97
                         + "existing DMDirc.jar file, located at:\n"
109
-                        + " " + appDir + "\n with the following file:\n "
98
+                        + " " + FileUtils.getApplicationPath(Main.class)
99
+                        + "\n with the following file:\n "
110 100
                         + targetFile.getAbsolutePath();
111 101
             } else {
112 102
                 return "A new version of DMDirc has been downloaded, but as you\n"
@@ -116,7 +106,7 @@ public class ClientComponent implements UpdateComponent {
116 106
                         + "new DMDirc.jar file, located at:\n"
117 107
                         + " " + targetFile.getAbsolutePath() + "\n"
118 108
                         + "over your existing DMDirc install located in:\n"
119
-                        + "  " + appDir;
109
+                        + "  " + FileUtils.getApplicationPath(Main.class);
120 110
             }
121 111
         }
122 112
         return "";

+ 7
- 9
src/com/dmdirc/util/resourcemanager/ResourceManager.java Parādīt failu

@@ -25,16 +25,14 @@ package com.dmdirc.util.resourcemanager;
25 25
 import com.dmdirc.Main;
26 26
 import com.dmdirc.logger.ErrorLevel;
27 27
 import com.dmdirc.logger.Logger;
28
+import com.dmdirc.util.io.FileUtils;
28 29
 
29 30
 import java.io.File;
30 31
 import java.io.FileOutputStream;
31 32
 import java.io.IOException;
32 33
 import java.io.InputStream;
33 34
 import java.net.MalformedURLException;
34
-import java.net.URISyntaxException;
35 35
 import java.net.URL;
36
-import java.nio.file.Path;
37
-import java.nio.file.Paths;
38 36
 import java.util.List;
39 37
 import java.util.Map;
40 38
 import java.util.Map.Entry;
@@ -55,15 +53,15 @@ public abstract class ResourceManager {
55 53
     public static synchronized ResourceManager getResourceManager() {
56 54
         if (me == null) {
57 55
             try {
58
-                final Path path = Paths.get(
59
-                        Main.class.getProtectionDomain().getCodeSource().getLocation().toURI());
60
-                if (path.getFileName().endsWith(".jar")) {
61
-                    me = new ZipResourceManager(path.toAbsolutePath().toString());
56
+                if (FileUtils.isRunningFromJar(Main.class)) {
57
+                    me = new ZipResourceManager(FileUtils.getApplicationPath(Main.class)
58
+                            .toAbsolutePath().toString());
62 59
                 } else {
63
-                    me = new FileResourceManager(path.toAbsolutePath().toString());
60
+                    me = new FileResourceManager(FileUtils.getApplicationPath(Main.class)
61
+                            .toAbsolutePath().toString());
64 62
 
65 63
                 }
66
-            } catch (URISyntaxException | IOException ex) {
64
+            } catch (IllegalStateException | IOException ex) {
67 65
                 Logger.appError(ErrorLevel.MEDIUM,
68 66
                         "Unable to determine how DMDirc has been executed", ex);
69 67
             }

Notiek ielāde…
Atcelt
Saglabāt