diff --git a/src/main/java/me/cortex/voxy/client/config/VoxyConfigScreenFactory.java b/src/main/java/me/cortex/voxy/client/config/VoxyConfigScreenFactory.java index c3c54df2..17c297c3 100644 --- a/src/main/java/me/cortex/voxy/client/config/VoxyConfigScreenFactory.java +++ b/src/main/java/me/cortex/voxy/client/config/VoxyConfigScreenFactory.java @@ -48,6 +48,7 @@ public class VoxyConfigScreenFactory implements ModMenuApi { ConfigCategory category = builder.getOrCreateCategory(Text.translatable("voxy.config.general")); ConfigEntryBuilder entryBuilder = builder.entryBuilder(); + /* category.addEntry(entryBuilder.startSubCategory(Text.translatable("aaa"), List.of(entryBuilder.startBooleanToggle(Text.translatable("voxy.config.general.enabled"), config.enabled) .setTooltip(Text.translatable("voxy.config.general.enabled.tooltip")) .setSaveConsumer(val -> config.enabled = val) @@ -58,7 +59,7 @@ public class VoxyConfigScreenFactory implements ModMenuApi { .setDefaultValue(DEFAULT.geometryBufferSize) .build())).build() )).build()); - + */ category.addEntry(entryBuilder.startBooleanToggle(Text.translatable("voxy.config.general.enabled"), config.enabled) .setTooltip(Text.translatable("voxy.config.general.enabled.tooltip")) diff --git a/src/main/java/me/cortex/voxy/client/saver/ContextSelectionSystem.java b/src/main/java/me/cortex/voxy/client/saver/ContextSelectionSystem.java index b3f7aa34..cebf08da 100644 --- a/src/main/java/me/cortex/voxy/client/saver/ContextSelectionSystem.java +++ b/src/main/java/me/cortex/voxy/client/saver/ContextSelectionSystem.java @@ -42,24 +42,26 @@ public class ContextSelectionSystem { if (Files.exists(json)) { try { this.storageConfig = Serialization.GSON.fromJson(Files.readString(json), StorageConfig.class); - } catch (IOException e) { - throw new RuntimeException(e); + return; + } catch (Exception e) { + System.err.println("Failed to load the storage configuration file, resetting it to default"); + e.printStackTrace(); } - } else { - //Load the default config - var baseDB = new RocksDBStorageBackend.Config(); - - var compressor = new ZSTDCompressor.Config(); - compressor.compressionLevel = 7; - - var compression = new CompressionStorageAdaptor.Config(); - compression.delegate = baseDB; - compression.compressor = compressor; - - this.storageConfig = compression; - - this.save(); } + + //Load the default config + var baseDB = new RocksDBStorageBackend.Config(); + + var compressor = new ZSTDCompressor.Config(); + compressor.compressionLevel = 7; + + var compression = new CompressionStorageAdaptor.Config(); + compression.delegate = baseDB; + compression.compressor = compressor; + + this.storageConfig = compression; + + this.save(); } public StorageBackend createStorageBackend() { diff --git a/src/main/java/me/cortex/voxy/common/storage/config/Serialization.java b/src/main/java/me/cortex/voxy/common/storage/config/Serialization.java index 4b963ee0..110a3af9 100644 --- a/src/main/java/me/cortex/voxy/common/storage/config/Serialization.java +++ b/src/main/java/me/cortex/voxy/common/storage/config/Serialization.java @@ -6,6 +6,7 @@ import com.google.gson.reflect.TypeToken; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonToken; import com.google.gson.stream.JsonWriter; +import net.fabricmc.loader.api.FabricLoader; import java.io.BufferedReader; import java.io.IOException; @@ -13,9 +14,13 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.lang.reflect.Method; import java.lang.reflect.Type; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.*; +import java.util.jar.JarFile; import java.util.stream.Collectors; import java.util.stream.Stream; +import java.util.zip.ZipEntry; public class Serialization { public static final Set> CONFIG_TYPES = new HashSet<>(); @@ -89,8 +94,14 @@ public class Serialization { static { Map, GsonConfigSerialization> serializers = new HashMap<>(); + + Set clazzs = new LinkedHashSet<>(); + var path = FabricLoader.getInstance().getModContainer("voxy").get().getRootPaths().get(0); + clazzs.addAll(collectAllClasses(path, "me.cortex.voxy.common.storage")); + clazzs.addAll(collectAllClasses("me.cortex.voxy.common.storage")); + outer: - for (var clzName : collectAllClasses("me.cortex.voxy.common.storage")) { + for (var clzName : clazzs) { if (clzName.equals(Serialization.class.getName())) { continue;//Dont want to load ourselves } @@ -144,6 +155,22 @@ public class Serialization { } }).collect(Collectors.toList()); } + private static List collectAllClasses(Path base, String pack) { + try { + return Files.list(base.resolve(pack.replaceAll("[.]", "/"))).flatMap(inner -> { + if (inner.getFileName().toString().endsWith(".class")) { + return Stream.of(pack + "." + inner.getFileName().toString().replace(".class", "")); + } else if (Files.isDirectory(inner)) { + return collectAllClasses(base, pack + "." + inner.getFileName()).stream(); + } else { + return Stream.of(); + } + }).collect(Collectors.toList()); + } catch ( + IOException e) { + throw new RuntimeException(e); + } + } public static void init() {} }