Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static void init() {}
// config v5 adds caching hooks and changes debug hud comment
// config v6 only changes comments

if(!ctx.fromExistingFile() || ver < CURRENT_CONFIG_VER) {
if(!ctx.fromExistingFile() || ver < CURRENT_CONFIG_VER || ctx.hasMissingOptions) {
try {
writeConfig();
} catch(Exception e) {
Expand Down Expand Up @@ -126,6 +126,6 @@ public static void writeConfig() throws Exception {
CURRENT_CONFIG_VER
);

Files.writeString(FILE, data, StandardOpenOption.CREATE, StandardOpenOption.WRITE);
Files.writeString(FILE, data, StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public final class ConfigLoadContext {
public final ModIncompatibilities incompats = new ModIncompatibilities();
public final int version;
@Nullable public final Properties properties;
public boolean hasMissingOptions = false;

public ConfigLoadContext() {
if(Files.exists(FILE)) {
Expand All @@ -32,10 +33,7 @@ private Properties loadProp() {
return prop;
}
} catch(Exception e) {
// TODO: does passing Exception as object still log the stack trace?
LOGGER.error("Failed to load config from " + FILE + ". " +
"If you need to, you can delete the file to generate a new one.", e);
System.exit(1);
LOGGER.error("Failed to load config from " + FILE + ". Config will be regenerated with default values.", e);
return null;
}
}
Expand Down Expand Up @@ -74,7 +72,8 @@ private String str(String name) {

String str = properties.getProperty(name);
if(str == null) {
throw new IllegalStateException("Config option " + name + " not found");
LOGGER.warn("Config option {} not found - using default value. Config will be regenerated.", name);
hasMissingOptions = true;
}
return str;
}
Expand Down