mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-10 12:26:16 -04:00
fix: #737
This commit is contained in:
parent
55d78aeba7
commit
00c350cd82
@ -40,6 +40,7 @@ import java.nio.file.Paths;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import static org.jackhuang.hmcl.ui.FXUtils.runInFX;
|
import static org.jackhuang.hmcl.ui.FXUtils.runInFX;
|
||||||
import static org.jackhuang.hmcl.util.Logging.LOG;
|
import static org.jackhuang.hmcl.util.Logging.LOG;
|
||||||
@ -55,6 +56,7 @@ public final class Launcher extends Application {
|
|||||||
try {
|
try {
|
||||||
ConfigHolder.init();
|
ConfigHolder.init();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
LOG.log(Level.SEVERE, "Failed to load config", e);
|
||||||
Main.showErrorAndExit(i18n("fatal.config_loading_failure", Paths.get("").toAbsolutePath().normalize()));
|
Main.showErrorAndExit(i18n("fatal.config_loading_failure", Paths.get("").toAbsolutePath().normalize()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,6 +62,9 @@ public final class ConfigHolder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
configLocation = locateConfig();
|
configLocation = locateConfig();
|
||||||
|
|
||||||
|
LOG.log(Level.INFO, "Config location: " + configLocation);
|
||||||
|
|
||||||
configInstance = loadConfig();
|
configInstance = loadConfig();
|
||||||
configInstance.addListener(source -> markConfigDirty());
|
configInstance.addListener(source -> markConfigDirty());
|
||||||
|
|
||||||
@ -88,6 +91,26 @@ public final class ConfigHolder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Path locateConfig() {
|
private static Path locateConfig() {
|
||||||
|
Path exePath = Paths.get("");
|
||||||
|
try {
|
||||||
|
Path jarPath = Paths.get(ConfigHolder.class.getProtectionDomain().getCodeSource().getLocation()
|
||||||
|
.toURI()).toAbsolutePath();
|
||||||
|
if (Files.isRegularFile(jarPath)) {
|
||||||
|
jarPath = jarPath.getParent();
|
||||||
|
exePath = jarPath;
|
||||||
|
|
||||||
|
Path config = jarPath.resolve(CONFIG_FILENAME);
|
||||||
|
if (Files.isRegularFile(config))
|
||||||
|
return config;
|
||||||
|
|
||||||
|
Path dotConfig = jarPath.resolve(CONFIG_FILENAME_LINUX);
|
||||||
|
if (Files.isRegularFile(dotConfig))
|
||||||
|
return dotConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Throwable ignore) {
|
||||||
|
}
|
||||||
|
|
||||||
Path config = Paths.get(CONFIG_FILENAME);
|
Path config = Paths.get(CONFIG_FILENAME);
|
||||||
if (Files.isRegularFile(config))
|
if (Files.isRegularFile(config))
|
||||||
return config;
|
return config;
|
||||||
@ -97,7 +120,7 @@ public final class ConfigHolder {
|
|||||||
return dotConfig;
|
return dotConfig;
|
||||||
|
|
||||||
// create new
|
// create new
|
||||||
return OperatingSystem.CURRENT_OS == OperatingSystem.WINDOWS ? config : dotConfig;
|
return exePath.resolve(OperatingSystem.CURRENT_OS == OperatingSystem.WINDOWS ? CONFIG_FILENAME : CONFIG_FILENAME_LINUX);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Config loadConfig() throws IOException {
|
private static Config loadConfig() throws IOException {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user