diff --git a/docs/User-Guide.md b/docs/User-Guide.md index 5cb8a8afba5..01147d9f891 100644 --- a/docs/User-Guide.md +++ b/docs/User-Guide.md @@ -106,6 +106,9 @@ If you are using the Mac OS X version of Forge then you will find the forge.prof /Contents/Resources/Java/ and you will find the file. +The userDir's location may be changed by setting the environment variable "FORGE_USER_DIR" to the desired path. Likewise, the cache dir can be changed using the +"FORGE_CACHE_DIR" environment variable. + ## Import Data If you have a directory full of deck files, you can use the Import Data dialog to copy or move them to the appropriate directory. The dialog gives you a full listing of all file copy/move operations, so you can see what will happen before you click 'Start Import'. diff --git a/forge-gui/src/main/java/forge/localinstance/properties/ForgeProfileProperties.java b/forge-gui/src/main/java/forge/localinstance/properties/ForgeProfileProperties.java index 6416190bf61..231704e5c3a 100644 --- a/forge-gui/src/main/java/forge/localinstance/properties/ForgeProfileProperties.java +++ b/forge-gui/src/main/java/forge/localinstance/properties/ForgeProfileProperties.java @@ -172,29 +172,52 @@ private static Pair getDefaultDirs() { final String fallbackDataDir = TextUtil.concatNoSpace(homeDir, "/.forge"); - if (StringUtils.containsIgnoreCase(osName, "windows")) { - // the split between appdata and localappdata on windows is relatively recent. If - // localappdata is not defined, use appdata for both. and if appdata is not defined, - // fall back to a linux-style dot dir in the home directory + // Data Dir + String dataDir = null; + if (System.getenv().containsKey("FORGE_USER_DIR")) { + dataDir = System.getenv().get("FORGE_USER_DIR"); + } + else if (StringUtils.containsIgnoreCase(osName, "windows")) { + // If appdata is not defined, fall back to a linux-style dot dir in the home directory String appRoot = System.getenv().get("APPDATA"); if (StringUtils.isEmpty(appRoot)) { appRoot = fallbackDataDir; } + dataDir = appRoot + File.separator + "Forge"; + } + else if (StringUtils.containsIgnoreCase(osName, "mac os x")) { + dataDir = TextUtil.concatNoSpace(homeDir, "/Library/Application Support/Forge"); + } + else { + // Linux and everything else + dataDir = fallbackDataDir; + } + + // Cache Dir + String cacheDir = null; + if (System.getenv().containsKey("FORGE_CACHE_DIR")) { + cacheDir = System.getenv().get("FORGE_CACHE_DIR"); + } + else if (StringUtils.containsIgnoreCase(osName, "windows")) { + // the split between appdata and localappdata on windows is relatively recent. If + // localappdata is not defined, use a subdirectory of the data dir String cacheRoot = System.getenv().get("LOCALAPPDATA"); if (StringUtils.isEmpty(cacheRoot)) { - cacheRoot = appRoot; + cacheDir = dataDir + File.separator + "Cache"; + } + else { + cacheDir = cacheRoot + File.separator + "Forge" + File.separator + "Cache"; } - // the cache dir is Forge/Cache instead of just Forge since appRoot and cacheRoot might be the - // same directory on windows and we need to distinguish them. - return Pair.of(appRoot + File.separator + "Forge", cacheRoot + File.separator + "Forge" + File.separator + "Cache"); } else if (StringUtils.containsIgnoreCase(osName, "mac os x")) { - return Pair.of(TextUtil.concatNoSpace(homeDir, "/Library/Application Support/Forge"), - TextUtil.concatNoSpace(homeDir, "/Library/Caches/Forge")); + cacheDir = TextUtil.concatNoSpace(homeDir, "/Library/Caches/Forge"); + } + else { + // Linux and everything else + cacheDir = TextUtil.concatNoSpace(homeDir, "/.cache/forge"); } - // Linux and everything else - return Pair.of(fallbackDataDir, TextUtil.concatNoSpace(homeDir, "/.cache/forge")); + return Pair.of(dataDir, cacheDir); } private static void save() {