Inceptum/common/src/main/java/io/gitlab/jfronny/inceptum/common/MetaHolder.java

57 lines
2.2 KiB
Java
Raw Normal View History

2022-09-04 21:21:24 +02:00
package io.gitlab.jfronny.inceptum.common;
2021-11-02 13:43:18 +01:00
2022-09-04 21:21:24 +02:00
import io.gitlab.jfronny.commons.OSUtils;
2021-11-02 13:43:18 +01:00
2022-06-05 16:45:22 +02:00
import java.nio.file.*;
2021-11-02 13:43:18 +01:00
public class MetaHolder {
public static final Path BASE_PATH;
static {
2022-09-04 21:21:24 +02:00
if (System.getProperty("inceptum.base") == null) {
2022-09-18 15:15:30 +02:00
Path runDir = getPath("run");
2022-09-06 14:55:36 +02:00
if (!BuildMetadata.IS_RELEASE) BASE_PATH = runDir;
else if (Files.exists(runDir)) BASE_PATH = runDir;
else {
Path configsDir = switch (OSUtils.TYPE) {
case WINDOWS -> getPath(System.getenv("APPDATA"));
case MAC_OS -> getPath(System.getProperty("user.home")).resolve("Library").resolve("Application Support");
case LINUX -> {
String s = System.getenv("XDG_CONFIG_HOME");
if (s == null)
yield getPath(System.getProperty("user.home")).resolve(".config");
else
yield getPath(s);
}
};
BASE_PATH = configsDir.resolve("Inceptum");
}
2022-09-04 21:21:24 +02:00
} else {
2022-09-06 14:55:36 +02:00
BASE_PATH = getPath(System.getProperty("inceptum.base"));
2021-11-02 13:43:18 +01:00
}
}
2022-09-04 21:21:24 +02:00
public static final Path ACCOUNTS_PATH = BASE_PATH.resolve("accounts.json");
public static final Path CONFIG_PATH = BASE_PATH.resolve("inceptum.json5");
2022-09-06 11:15:21 +02:00
public static final Path WRAPPER_CONFIG_PATH = BASE_PATH.resolve("wrapper.json");
public static final Path NATIVES_DIR = BASE_PATH.resolve("natives");
public static final Path FORCE_LOAD_PATH = NATIVES_DIR.resolve("forceload");
public static final Path LIBRARIES_DIR = BASE_PATH.resolve("libraries");
public static final Path ASSETS_DIR = BASE_PATH.resolve("assets");
public static final Path INSTANCE_DIR = BASE_PATH.resolve("instances");
public static final Path CACHE_DIR = BASE_PATH.resolve("cache");
2022-09-06 14:55:36 +02:00
private static boolean isWrapper = false;
2021-11-02 13:43:18 +01:00
2022-09-06 14:55:36 +02:00
private static Path getPath(String text) {
2022-09-18 15:15:30 +02:00
return Paths.get(text).toAbsolutePath().normalize();
2021-11-02 13:43:18 +01:00
}
public static void setWrapperFlag() {
isWrapper = true;
}
public static boolean isWrapper() {
return isWrapper;
}
2021-11-02 13:43:18 +01:00
}