From 3654a450f861c46d4ad73d53b68ca5b62c9f41a2 Mon Sep 17 00:00:00 2001 From: Gravit Date: Thu, 20 Dec 2018 15:35:04 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B0=D0=BF=D0=BA=D0=B0=20=D0=BB=D0=B0?= =?UTF-8?q?=D1=83=D0=BD=D1=87=D0=B5=D1=80=D0=B0=20=D0=BF=D0=B5=D1=80=D0=B5?= =?UTF-8?q?=D0=BC=D0=B5=D1=89=D0=B5=D0=BD=D0=B0=20=D0=B2=20AppData(Windows?= =?UTF-8?q?)=20.minecraftlauncher(Linux)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Launcher/runtime/config.js | 2 +- .../ru/gravit/launcher/client/DirBridge.java | 58 +++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/Launcher/runtime/config.js b/Launcher/runtime/config.js index cd0b7f2e..2acf6dba 100644 --- a/Launcher/runtime/config.js +++ b/Launcher/runtime/config.js @@ -20,7 +20,7 @@ var config = { // ====== DON'T TOUCH! ====== // -DirBridge.dir = IOHelper.HOME_DIR.resolve(config.dir); +DirBridge.dir = DirBridge.getLauncherDir(config.dir); if (!IOHelper.isDir(DirBridge.dir)) { java.nio.file.Files.createDirectory(DirBridge.dir); } diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/DirBridge.java b/Launcher/src/main/java/ru/gravit/launcher/client/DirBridge.java index c105b10b..acf9f8d1 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/DirBridge.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/DirBridge.java @@ -1,10 +1,13 @@ package ru.gravit.launcher.client; import java.io.IOException; +import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; import ru.gravit.launcher.LauncherAPI; import ru.gravit.utils.helper.IOHelper; +import ru.gravit.utils.helper.JVMHelper; public class DirBridge { @LauncherAPI @@ -14,9 +17,64 @@ public class DirBridge { @LauncherAPI public static Path defaultUpdatesDir; @LauncherAPI + public static boolean useLegacyDir; + @LauncherAPI public static void move(Path newDir) throws IOException { IOHelper.move(dirUpdates,newDir); dirUpdates = newDir; } + @LauncherAPI + public static Path getAppDataDir() throws IOException { + Boolean isCustomDir = Boolean.getBoolean(System.getProperty("launcher.usecustomdir","false")); + if(isCustomDir) + { + return Paths.get(System.getProperty("launcher.customdir")); + } + if(JVMHelper.OS_TYPE == JVMHelper.OS.LINUX) + { + Boolean isOpt = Boolean.getBoolean(System.getProperty("launcher.useoptdir","false")); + if(isOpt) + { + Path opt = Paths.get("/").resolve("opt"); + if(!IOHelper.isDir(opt)) Files.createDirectories(opt); + return opt; + } + else + { + Path local = IOHelper.HOME_DIR.resolve(".minecraftlauncher"); + if(!IOHelper.isDir(local)) Files.createDirectories(local); + return local; + } + } + else if(JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) + { + Path appdata = IOHelper.HOME_DIR.resolve("AppData").resolve("Roaming"); + if(!IOHelper.isDir(appdata)) Files.createDirectories(appdata); + return appdata; + } + else if(JVMHelper.OS_TYPE == JVMHelper.OS.MACOSX) + { + Path minecraft = IOHelper.HOME_DIR.resolve("minecraft"); + if(!IOHelper.isDir(minecraft)) Files.createDirectories(minecraft); + return minecraft; + } + else + { + return IOHelper.HOME_DIR; + } + } + @LauncherAPI + public static Path getLauncherDir(String projectname) throws IOException { + return getAppDataDir().resolve(projectname); + } + @LauncherAPI + public static Path getLegacyLauncherDir(String projectname) throws IOException { + return IOHelper.HOME_DIR.resolve(projectname); + } + @LauncherAPI + public static void setUseLegacyDir(boolean b) + { + useLegacyDir = b; + } }