Browse Source

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 years ago
parent
commit
961bf642ac

+ 6
- 16
src/com/dmdirc/updater/components/ClientComponent.java View File

22
 
22
 
23
 package com.dmdirc.updater.components;
23
 package com.dmdirc.updater.components;
24
 
24
 
25
+import com.dmdirc.Main;
25
 import com.dmdirc.interfaces.config.IdentityController;
26
 import com.dmdirc.interfaces.config.IdentityController;
26
 import com.dmdirc.ui.StatusMessage;
27
 import com.dmdirc.ui.StatusMessage;
27
 import com.dmdirc.ui.core.components.StatusBarManager;
28
 import com.dmdirc.ui.core.components.StatusBarManager;
28
 import com.dmdirc.updater.UpdateComponent;
29
 import com.dmdirc.updater.UpdateComponent;
29
 import com.dmdirc.updater.Version;
30
 import com.dmdirc.updater.Version;
31
+import com.dmdirc.util.io.FileUtils;
30
 
32
 
31
 import java.io.File;
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
 import javax.inject.Inject;
35
 import javax.inject.Inject;
37
 
36
 
90
                 + File.separator + ".DMDirc.jar");
89
                 + File.separator + ".DMDirc.jar");
91
 
90
 
92
         if (requiresManualInstall()) {
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
                 return "A new version of DMDirc has been downloaded, but as you\n"
93
                 return "A new version of DMDirc has been downloaded, but as you\n"
105
                         + "do not seem to be using the DMDirc launcher, it will\n"
94
                         + "do not seem to be using the DMDirc launcher, it will\n"
106
                         + "not be installed automatically.\n\n"
95
                         + "not be installed automatically.\n\n"
107
                         + "To install this update manually, please replace the\n"
96
                         + "To install this update manually, please replace the\n"
108
                         + "existing DMDirc.jar file, located at:\n"
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
                         + targetFile.getAbsolutePath();
100
                         + targetFile.getAbsolutePath();
111
             } else {
101
             } else {
112
                 return "A new version of DMDirc has been downloaded, but as you\n"
102
                 return "A new version of DMDirc has been downloaded, but as you\n"
116
                         + "new DMDirc.jar file, located at:\n"
106
                         + "new DMDirc.jar file, located at:\n"
117
                         + " " + targetFile.getAbsolutePath() + "\n"
107
                         + " " + targetFile.getAbsolutePath() + "\n"
118
                         + "over your existing DMDirc install located in:\n"
108
                         + "over your existing DMDirc install located in:\n"
119
-                        + "  " + appDir;
109
+                        + "  " + FileUtils.getApplicationPath(Main.class);
120
             }
110
             }
121
         }
111
         }
122
         return "";
112
         return "";

+ 7
- 9
src/com/dmdirc/util/resourcemanager/ResourceManager.java View File

25
 import com.dmdirc.Main;
25
 import com.dmdirc.Main;
26
 import com.dmdirc.logger.ErrorLevel;
26
 import com.dmdirc.logger.ErrorLevel;
27
 import com.dmdirc.logger.Logger;
27
 import com.dmdirc.logger.Logger;
28
+import com.dmdirc.util.io.FileUtils;
28
 
29
 
29
 import java.io.File;
30
 import java.io.File;
30
 import java.io.FileOutputStream;
31
 import java.io.FileOutputStream;
31
 import java.io.IOException;
32
 import java.io.IOException;
32
 import java.io.InputStream;
33
 import java.io.InputStream;
33
 import java.net.MalformedURLException;
34
 import java.net.MalformedURLException;
34
-import java.net.URISyntaxException;
35
 import java.net.URL;
35
 import java.net.URL;
36
-import java.nio.file.Path;
37
-import java.nio.file.Paths;
38
 import java.util.List;
36
 import java.util.List;
39
 import java.util.Map;
37
 import java.util.Map;
40
 import java.util.Map.Entry;
38
 import java.util.Map.Entry;
55
     public static synchronized ResourceManager getResourceManager() {
53
     public static synchronized ResourceManager getResourceManager() {
56
         if (me == null) {
54
         if (me == null) {
57
             try {
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
                 } else {
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
                 Logger.appError(ErrorLevel.MEDIUM,
65
                 Logger.appError(ErrorLevel.MEDIUM,
68
                         "Unable to determine how DMDirc has been executed", ex);
66
                         "Unable to determine how DMDirc has been executed", ex);
69
             }
67
             }

Loading…
Cancel
Save