mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-14 06:17:47 -04:00
Migrate HMCL_DIRECTORY to the user directory (#1785)
This commit is contained in:
parent
1b3c399335
commit
c113670cda
@ -18,11 +18,9 @@
|
|||||||
package org.jackhuang.hmcl;
|
package org.jackhuang.hmcl;
|
||||||
|
|
||||||
import org.jackhuang.hmcl.util.io.JarUtils;
|
import org.jackhuang.hmcl.util.io.JarUtils;
|
||||||
import org.jackhuang.hmcl.util.StringUtils;
|
|
||||||
import org.jackhuang.hmcl.util.platform.OperatingSystem;
|
import org.jackhuang.hmcl.util.platform.OperatingSystem;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores metadata about this application.
|
* Stores metadata about this application.
|
||||||
@ -47,20 +45,7 @@ public final class Metadata {
|
|||||||
public static final String BUILD_CHANNEL = JarUtils.thisJar().flatMap(JarUtils::getManifest).map(manifest -> manifest.getMainAttributes().getValue("Build-Channel")).orElse("nightly");
|
public static final String BUILD_CHANNEL = JarUtils.thisJar().flatMap(JarUtils::getManifest).map(manifest -> manifest.getMainAttributes().getValue("Build-Channel")).orElse("nightly");
|
||||||
|
|
||||||
public static final Path MINECRAFT_DIRECTORY = OperatingSystem.getWorkingDirectory("minecraft");
|
public static final Path MINECRAFT_DIRECTORY = OperatingSystem.getWorkingDirectory("minecraft");
|
||||||
public static final Path HMCL_DIRECTORY = getHMCLDirectory();
|
public static final Path HMCL_DIRECTORY = OperatingSystem.getWorkingDirectory("hmcl");
|
||||||
|
|
||||||
private static Path getHMCLDirectory() {
|
|
||||||
String home = System.getProperty("user.home", ".");
|
|
||||||
if (OperatingSystem.CURRENT_OS == OperatingSystem.LINUX) {
|
|
||||||
// to fulfill XDG standard.
|
|
||||||
String xdgCache = System.getenv("XDG_CACHE_HOME");
|
|
||||||
if (StringUtils.isNotBlank(xdgCache)) {
|
|
||||||
return Paths.get(xdgCache, "hmcl");
|
|
||||||
}
|
|
||||||
return Paths.get(home, ".cache", "hmcl");
|
|
||||||
}
|
|
||||||
return OperatingSystem.getWorkingDirectory("hmcl");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isStable() {
|
public static boolean isStable() {
|
||||||
return "stable".equals(BUILD_CHANNEL);
|
return "stable".equals(BUILD_CHANNEL);
|
||||||
|
@ -22,6 +22,7 @@ import com.google.gson.JsonParseException;
|
|||||||
import org.jackhuang.hmcl.Metadata;
|
import org.jackhuang.hmcl.Metadata;
|
||||||
import org.jackhuang.hmcl.util.InvocationDispatcher;
|
import org.jackhuang.hmcl.util.InvocationDispatcher;
|
||||||
import org.jackhuang.hmcl.util.Lang;
|
import org.jackhuang.hmcl.util.Lang;
|
||||||
|
import org.jackhuang.hmcl.util.StringUtils;
|
||||||
import org.jackhuang.hmcl.util.io.FileUtils;
|
import org.jackhuang.hmcl.util.io.FileUtils;
|
||||||
import org.jackhuang.hmcl.util.platform.OperatingSystem;
|
import org.jackhuang.hmcl.util.platform.OperatingSystem;
|
||||||
|
|
||||||
@ -189,6 +190,28 @@ public final class ConfigHolder {
|
|||||||
// Global Config
|
// Global Config
|
||||||
|
|
||||||
private static GlobalConfig loadGlobalConfig() throws IOException {
|
private static GlobalConfig loadGlobalConfig() throws IOException {
|
||||||
|
// Migrate from old directory
|
||||||
|
if (OperatingSystem.CURRENT_OS == OperatingSystem.LINUX && Files.notExists(GLOBAL_CONFIG_PATH)) {
|
||||||
|
Path oldHome;
|
||||||
|
String xdgCache = System.getenv("XDG_CACHE_HOME");
|
||||||
|
if (StringUtils.isNotBlank(xdgCache)) {
|
||||||
|
oldHome = Paths.get(xdgCache, "hmcl");
|
||||||
|
} else {
|
||||||
|
oldHome = Paths.get(System.getProperty("user.home", "."), ".cache", "hmcl");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Files.exists(oldHome)) {
|
||||||
|
Path oldConfigPath = oldHome.resolve("config.json");
|
||||||
|
if (Files.isRegularFile(oldConfigPath)) {
|
||||||
|
try {
|
||||||
|
Files.copy(oldConfigPath, GLOBAL_CONFIG_PATH);
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOG.log(Level.WARNING, "Failed to migrate global config", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (Files.exists(GLOBAL_CONFIG_PATH)) {
|
if (Files.exists(GLOBAL_CONFIG_PATH)) {
|
||||||
try {
|
try {
|
||||||
String content = FileUtils.readText(GLOBAL_CONFIG_PATH);
|
String content = FileUtils.readText(GLOBAL_CONFIG_PATH);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user