Skip to content

Commit e30a7fc

Browse files
committed
Add global properties file
Not populated by default. User must create `global/modernfix-global-mixins.properties` in the standard global .minecraft folder for their OS
1 parent 12a0414 commit e30a7fc

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

common/src/main/java/org/embeddedt/modernfix/core/config/ModernFixEarlyConfig.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.google.gson.*;
66
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
77
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
8+
import org.apache.commons.lang3.SystemUtils;
89
import org.apache.logging.log4j.LogManager;
910
import org.apache.logging.log4j.Logger;
1011
import org.embeddedt.modernfix.annotation.ClientOnlyMixin;
@@ -21,6 +22,9 @@
2122
import java.io.*;
2223
import java.net.URL;
2324
import java.nio.charset.StandardCharsets;
25+
import java.nio.file.Files;
26+
import java.nio.file.Path;
27+
import java.nio.file.Paths;
2428
import java.util.*;
2529
import java.util.function.BooleanSupplier;
2630
import java.util.regex.Pattern;
@@ -313,6 +317,32 @@ private void readJVMProperties() {
313317
}
314318
}
315319

320+
private void readGlobalProperties() {
321+
Path minecraftFolder;
322+
if (SystemUtils.IS_OS_MAC) {
323+
minecraftFolder = Paths.get(System.getProperty("user.home"), "Library", "Application Support", "minecraft");
324+
} else if (SystemUtils.IS_OS_WINDOWS) {
325+
minecraftFolder = Paths.get(System.getenv("APPDATA"), ".minecraft");
326+
} else {
327+
minecraftFolder = Paths.get(System.getProperty("user.home"), ".minecraft");
328+
}
329+
Path globalPropsFile = minecraftFolder.resolve("global").resolve("modernfix-global-mixins.properties");
330+
try {
331+
if (Files.exists(globalPropsFile)) {
332+
Properties properties = new Properties();
333+
try (var is = Files.newInputStream(globalPropsFile)) {
334+
properties.load(is);
335+
}
336+
if (!properties.isEmpty()) {
337+
LOGGER.info("Global properties specified: [{}]", properties.entrySet().stream().map(e -> e.getKey() + "=" + e.getValue()).collect(Collectors.joining(", ")));
338+
readProperties(properties);
339+
}
340+
}
341+
} catch (Exception e) {
342+
LOGGER.error("Error reading global properties file", e);
343+
}
344+
}
345+
316346
private void readProperties(Properties props) {
317347
if(ALLOW_OVERRIDE_OVERRIDES)
318348
LOGGER.fatal("JVM argument given to override mod overrides. Issues opened with this option present will be ignored unless they can be reproduced without.");
@@ -402,6 +432,7 @@ public static ModernFixEarlyConfig load(File file) {
402432
LOGGER.warn("Could not write configuration file", e);
403433
}
404434

435+
config.readGlobalProperties();
405436
config.readJVMProperties();
406437
}
407438

0 commit comments

Comments
 (0)