| 1 | package net.oni2.aeinstaller.backend; | 
 
 
 
 
 | 2 |  | 
 
 
 
 
 | 3 | import java.io.File; | 
 
 
 
 
 | 4 | import java.io.UnsupportedEncodingException; | 
 
 
 
 
 | 5 | import java.net.URLDecoder; | 
 
 
 
 
 | 6 |  | 
 
 
 
 
 | 7 | import net.oni2.SettingsManager; | 
 
 
 
 
 | 8 |  | 
 
 
 
 
 | 9 | /** | 
 
 
 
 
 | 10 | * @author Christian Illy | 
 
 
 
 
 | 11 | */ | 
 
 
 
 
 | 12 | public class Paths { | 
 
 
 
 
 | 13 |  | 
 
 
 
 
 | 14 | /** | 
 
 
 
 
 | 15 | * @return Mod Depot cache filename | 
 
 
 
 
 | 16 | */ | 
 
 
 
 
 | 17 | public static File getDepotCacheFilename() { | 
 
 
 
 
 | 18 | return new File(getPrefsPath(), "ModDepotCache.xml"); | 
 
 
 
 
 | 19 | } | 
 
 
 
 
 | 20 |  | 
 
 
 
 
 | 21 | /** | 
 
 
 
 
 | 22 | * @return Settings filename of AEI | 
 
 
 
 
 | 23 | */ | 
 
 
 
 
 | 24 | public static File getSettingsFilename() { | 
 
 
 
 
 | 25 | return new File(getPrefsPath(), "AEI-Settings.xml"); | 
 
 
 
 
 | 26 | } | 
 
 
 
 
 | 27 |  | 
 
 
 
 
 | 28 | /** | 
 
 
 
 
 | 29 | * Get the Jar path | 
 
 
 
 
 | 30 | * | 
 
 
 
 
 | 31 | * @return Path | 
 
 
 
 
 | 32 | */ | 
 
 
 
 
 | 33 | public static File getInstallerPath() { | 
 
 
 
 
 | 34 | if (SettingsManager.isDebug() || SettingsManager.getUseWorkingDir()) { | 
 
 
 
 
 | 35 | String wd = System.getProperty("user.dir"); | 
 
 
 
 
 | 36 | return new File(wd); | 
 
 
 
 
 | 37 | } else { | 
 
 
 
 
 | 38 | String jarPath = Paths.class.getProtectionDomain().getCodeSource() | 
 
 
 
 
 | 39 | .getLocation().getPath(); | 
 
 
 
 
 | 40 | String decodedPath = null; | 
 
 
 
 
 | 41 | try { | 
 
 
 
 
 | 42 | decodedPath = URLDecoder.decode(jarPath, "UTF-8"); | 
 
 
 
 
 | 43 | } catch (UnsupportedEncodingException e) { | 
 
 
 
 
 | 44 | e.printStackTrace(); | 
 
 
 
 
 | 45 | } | 
 
 
 
 
 | 46 | return new File(decodedPath).getParentFile().getParentFile(); | 
 
 
 
 
 | 47 | } | 
 
 
 
 
 | 48 | } | 
 
 
 
 
 | 49 |  | 
 
 
 
 
 | 50 | /** | 
 
 
 
 
 | 51 | * @return Path of jar | 
 
 
 
 
 | 52 | */ | 
 
 
 
 
 | 53 | public static File getJarPath() { | 
 
 
 
 
 | 54 | return new File(getInstallerPath(), "bin"); | 
 
 
 
 
 | 55 | } | 
 
 
 
 
 | 56 |  | 
 
 
 
 
 | 57 | /** | 
 
 
 
 
 | 58 | * Get the preferences path | 
 
 
 
 
 | 59 | * | 
 
 
 
 
 | 60 | * @return Path | 
 
 
 
 
 | 61 | */ | 
 
 
 
 
 | 62 | public static File getPrefsPath() { | 
 
 
 
 
 | 63 | return getInstallerPath(); | 
 
 
 
 
 | 64 | } | 
 
 
 
 
 | 65 |  | 
 
 
 
 
 | 66 | /** | 
 
 
 
 
 | 67 | * Get the path to store downloaded files | 
 
 
 
 
 | 68 | * | 
 
 
 
 
 | 69 | * @return Download path | 
 
 
 
 
 | 70 | */ | 
 
 
 
 
 | 71 | public static File getDownloadPath() { | 
 
 
 
 
 | 72 | return new File(getTempPath(), "downloads"); | 
 
 
 
 
 | 73 | } | 
 
 
 
 
 | 74 |  | 
 
 
 
 
 | 75 | /** | 
 
 
 
 
 | 76 | * Get the path to store mods | 
 
 
 
 
 | 77 | * | 
 
 
 
 
 | 78 | * @return Data path | 
 
 
 
 
 | 79 | */ | 
 
 
 
 
 | 80 | public static File getModsPath() { | 
 
 
 
 
 | 81 | return new File(getInstallerPath(), "packages"); | 
 
 
 
 
 | 82 | } | 
 
 
 
 
 | 83 |  | 
 
 
 
 
 | 84 | /** | 
 
 
 
 
 | 85 | * Get the path where vanilla .oni-files are stored | 
 
 
 
 
 | 86 | * | 
 
 
 
 
 | 87 | * @return Vanilla .oni's path | 
 
 
 
 
 | 88 | */ | 
 
 
 
 
 | 89 | public static File getVanillaOnisPath() { | 
 
 
 
 
 | 90 | return new File(getInstallerPath(), "vanilla"); | 
 
 
 
 
 | 91 | } | 
 
 
 
 
 | 92 |  | 
 
 
 
 
 | 93 | /** | 
 
 
 
 
 | 94 | * Get the base path of Oni | 
 
 
 
 
 | 95 | * | 
 
 
 
 
 | 96 | * @return Vanilla Oni path | 
 
 
 
 
 | 97 | */ | 
 
 
 
 
 | 98 | public static File getOniBasePath() { | 
 
 
 
 
 | 99 | return getInstallerPath().getParentFile().getParentFile(); | 
 
 
 
 
 | 100 | } | 
 
 
 
 
 | 101 |  | 
 
 
 
 
 | 102 | /** | 
 
 
 
 
 | 103 | * Get the base path of the Edition | 
 
 
 
 
 | 104 | * | 
 
 
 
 
 | 105 | * @return Edition path | 
 
 
 
 
 | 106 | */ | 
 
 
 
 
 | 107 | public static File getEditionBasePath() { | 
 
 
 
 
 | 108 | return getInstallerPath().getParentFile(); | 
 
 
 
 
 | 109 | } | 
 
 
 
 
 | 110 |  | 
 
 
 
 
 | 111 | /** | 
 
 
 
 
 | 112 | * Get the path where the vanilla Oni GDF is located | 
 
 
 
 
 | 113 | * | 
 
 
 
 
 | 114 | * @return Vanilla Oni GDF | 
 
 
 
 
 | 115 | */ | 
 
 
 
 
 | 116 | public static File getVanillaGDF() { | 
 
 
 
 
 | 117 | return CaseInsensitiveFile.getCaseInsensitiveFile(getOniBasePath(), | 
 
 
 
 
 | 118 | "GameDataFolder"); | 
 
 
 
 
 | 119 | } | 
 
 
 
 
 | 120 |  | 
 
 
 
 
 | 121 | /** | 
 
 
 
 
 | 122 | * Get the path where the Edition GDF is located | 
 
 
 
 
 | 123 | * | 
 
 
 
 
 | 124 | * @return Edition GDF | 
 
 
 
 
 | 125 | */ | 
 
 
 
 
 | 126 | public static File getEditionGDF() { | 
 
 
 
 
 | 127 | return new File(getEditionBasePath(), "GameDataFolder"); | 
 
 
 
 
 | 128 | } | 
 
 
 
 
 | 129 |  | 
 
 
 
 
 | 130 | /** | 
 
 
 
 
 | 131 | * Get the systems temp-path | 
 
 
 
 
 | 132 | * | 
 
 
 
 
 | 133 | * @return Path | 
 
 
 
 
 | 134 | */ | 
 
 
 
 
 | 135 | public static File getTempPath() { | 
 
 
 
 
 | 136 | return new File(System.getProperty("java.io.tmpdir"), "oni_aei"); | 
 
 
 
 
 | 137 | } | 
 
 
 
 
 | 138 |  | 
 
 
 
 
 | 139 | } |