Rev | Line | |
---|
[734] | 1 | package net.oni2.aeinstaller.updater.backend;
|
---|
| 2 |
|
---|
| 3 | import java.io.File;
|
---|
| 4 | import java.io.UnsupportedEncodingException;
|
---|
| 5 | import java.net.URLDecoder;
|
---|
| 6 |
|
---|
| 7 | /**
|
---|
| 8 | * @author Christian Illy
|
---|
| 9 | */
|
---|
| 10 | public class Paths {
|
---|
| 11 |
|
---|
| 12 | /**
|
---|
[777] | 13 | * Use the wd instead of the jar path
|
---|
| 14 | */
|
---|
| 15 | public static boolean useWorkingDirectory = false;
|
---|
| 16 |
|
---|
| 17 | /**
|
---|
[734] | 18 | * Get the Jar path
|
---|
| 19 | *
|
---|
| 20 | * @return Path
|
---|
| 21 | */
|
---|
| 22 | public static File getInstallerPath() {
|
---|
| 23 | String jarPath = Paths.class.getProtectionDomain().getCodeSource()
|
---|
| 24 | .getLocation().getPath();
|
---|
| 25 | String decodedPath = null;
|
---|
| 26 | try {
|
---|
| 27 | decodedPath = URLDecoder.decode(jarPath, "UTF-8");
|
---|
| 28 | } catch (UnsupportedEncodingException e) {
|
---|
| 29 | e.printStackTrace();
|
---|
| 30 | }
|
---|
| 31 | return new File(decodedPath).getParentFile();
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | /**
|
---|
| 35 | * Get the preferences path
|
---|
| 36 | *
|
---|
| 37 | * @return Path
|
---|
| 38 | */
|
---|
| 39 | public static File getPrefsPath() {
|
---|
[777] | 40 | if (useWorkingDirectory) {
|
---|
| 41 | String wd = System.getProperty("user.dir");
|
---|
| 42 | return new File(wd);
|
---|
| 43 | } else
|
---|
| 44 | return getInstallerPath();
|
---|
[734] | 45 | }
|
---|
| 46 |
|
---|
| 47 | /**
|
---|
| 48 | * Get the path to store downloaded files
|
---|
| 49 | *
|
---|
| 50 | * @return Download path
|
---|
| 51 | */
|
---|
| 52 | public static File getDownloadPath() {
|
---|
| 53 | return new File(getTempPath(), "downloads");
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | /**
|
---|
| 57 | * Get the systems temp-path
|
---|
| 58 | *
|
---|
| 59 | * @return Path
|
---|
| 60 | */
|
---|
| 61 | public static File getTempPath() {
|
---|
| 62 | return new File(System.getProperty("java.io.tmpdir"), "oni_aei");
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.