Skip to content

Commit

Permalink
Remove beacon, add config option to disable global dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGlitch76 committed Aug 14, 2023
1 parent c72e173 commit 3a5f04e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 136 deletions.
127 changes: 0 additions & 127 deletions src/main/java/org/quiltmc/loader/impl/ActiveUserBeacon.java

This file was deleted.

9 changes: 9 additions & 0 deletions src/main/java/org/quiltmc/loader/impl/QuiltLoaderConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Properties;

import org.jetbrains.annotations.VisibleForTesting;
import org.quiltmc.loader.api.QuiltLoader;
import org.quiltmc.loader.impl.util.QuiltLoaderInternal;
import org.quiltmc.loader.impl.util.QuiltLoaderInternalType;
import org.quiltmc.loader.impl.util.log.Log;
Expand Down Expand Up @@ -59,6 +60,12 @@ public final class QuiltLoaderConfig {
* quilt-loader, or tasks submitted by plugins. */
public final boolean singleThreadedLoading;

/**
* If false, then quilt loader will create a subfolder named {@code global} in the normal config and cache folders, and
* {@link QuiltLoader#getGlobalConfigDir()} and {@link QuiltLoader#getGlobalCacheDir()} will link there.
*/
public final boolean enableGlobalDirs;

public QuiltLoaderConfig(Path from) {
// Multi-threaded doesn't work yet, so hardcode this
singleThreadedLoading = true;
Expand All @@ -81,6 +88,7 @@ public QuiltLoaderConfig(Path from) {
loadSubFolders = getBool(props, "load_sub_folders", true);
restrictGameVersions = getBool(props, "restrict_game_versions", true);
alwaysShowModStateWindow = getBool(props, "always_show_mod_state_window", false);
enableGlobalDirs = getBool(props, "enable_global_dirs", false);

if (!original.equals(props)) {
try (OutputStream out = Files.newOutputStream(from)) {
Expand All @@ -97,6 +105,7 @@ public QuiltLoaderConfig(Path from) {
this.alwaysShowModStateWindow = false;
this.loadSubFolders = true;
this.restrictGameVersions = true;
this.enableGlobalDirs = false;
}

private static boolean getBool(Properties props, String key, boolean _default) {
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/org/quiltmc/loader/impl/QuiltLoaderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public final class QuiltLoaderImpl {
public static final char FLAG_DEPS_CHANGED = 'o';
public static final char FLAG_DEPS_REMOVED = 'R';

private QuiltLoaderConfig config;
protected final Map<String, ModContainerExt> modMap = new HashMap<>();

protected List<ModContainerExt> mods = new ArrayList<>();
Expand Down Expand Up @@ -202,19 +203,24 @@ public void setGameProvider(GameProvider provider) {

setGameDir(provider.getLaunchDirectory());
argumentModsList = provider.getArguments().remove(Arguments.ADD_MODS);

ActiveUserBeacon.run();
}

public void setGameDir(Path gameDir) {
this.gameDir = gameDir;

this.cacheDir = gameDir.resolve(System.getProperty(SystemProperties.CACHE_DIRECTORY, DEFAULT_CACHE_DIR));
this.configDir = gameDir.resolve(System.getProperty(SystemProperties.CONFIG_DIRECTORY, DEFAULT_CONFIG_DIR));

this.config = new QuiltLoaderConfig(getConfigDir().resolve("quilt-loader.txt"));
initializeModsDir(gameDir);
}

public QuiltLoaderConfig getConfig() {
if (this.config == null) {
throw new IllegalStateException("getConfig called too early!");
}

return this.config;
}
private void initializeModsDir(Path gameDir) {
String modsDir = System.getProperty(SystemProperties.MODS_DIRECTORY);
this.modsDir = gameDir.resolve((modsDir == null || modsDir.isEmpty()) ? DEFAULT_MODS_DIR : modsDir);
Expand Down Expand Up @@ -538,7 +544,6 @@ private Path copyToJar(Path transformCacheFolder, ModLoadOption modOption, final
}

private ModSolveResult runPlugins() {
QuiltLoaderConfig config = new QuiltLoaderConfig(getConfigDir().resolve("quilt-loader.txt"));
QuiltPluginManagerImpl plugins = new QuiltPluginManagerImpl(getGameDir(), getConfigDir(), getModsDir(), getCacheDir(), provider, config);

Path crashReportFile = null;
Expand Down
25 changes: 20 additions & 5 deletions src/main/java/org/quiltmc/loader/impl/util/GlobalPaths.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Locale;

import org.quiltmc.loader.api.QuiltLoader;
import org.quiltmc.loader.impl.QuiltLoaderConfig;
import org.quiltmc.loader.impl.QuiltLoaderImpl;
import org.quiltmc.loader.impl.util.log.Log;
import org.quiltmc.loader.impl.util.log.LogCategory;
Expand All @@ -32,6 +33,16 @@ public class GlobalPaths {
private static boolean actuallyGlobal = true;

static {
init();
}

// TODO: This works by pure luck; a guard should be added like in QuiltLoaderImpl#getConfig
static void init() {
if (!QuiltLoaderImpl.INSTANCE.getConfig().enableGlobalDirs) {
fallback();
return;
}

try {
String os = System.getProperty("os.name").toLowerCase(Locale.ROOT);

Expand Down Expand Up @@ -65,14 +76,18 @@ public class GlobalPaths {
QuiltLoaderImpl.ensureDirExists(config, "global config");
} catch (Throwable throwable) {
Log.warn(LogCategory.GENERAL, "Unable to create global config and cache directories. Falling back to per-instance directories.", throwable);
actuallyGlobal = false;
config = QuiltLoader.getConfigDir().resolve("global");
cache = QuiltLoader.getCacheDir().resolve("global");
QuiltLoaderImpl.ensureDirExists(config, "fake global config");
QuiltLoaderImpl.ensureDirExists(config, "fake global cache");
fallback();
}
}

static void fallback() {
actuallyGlobal = false;
config = QuiltLoader.getConfigDir().resolve("global");
cache = QuiltLoader.getCacheDir().resolve("global");
QuiltLoaderImpl.ensureDirExists(config, "fake global config");
QuiltLoaderImpl.ensureDirExists(config, "fake global cache");
}

public static Path getConfigDir() {
return config;
}
Expand Down

0 comments on commit 3a5f04e

Please sign in to comment.