Fix config file path

This commit is contained in:
Johannes Frohnmeyer 2022-08-28 20:52:27 +02:00
parent a7379d1405
commit 657730e8a4
Signed by: Johannes
GPG Key ID: E76429612C2929F4
4 changed files with 38 additions and 32 deletions

View File

@ -49,7 +49,7 @@ public abstract class ResourcePackEntryMixin {
info.setReturnValue(true);
MinecraftClient c = MinecraftClient.getInstance();
String id = MetaCache.getId(dataLocation);
c.setScreen(ConfigScreen.create(DSL.create(id).config(builder -> MetaCache.getBranch(dataLocation).buildConfig(builder, id)), c.currentScreen));
c.setScreen(ConfigScreen.create(DSL.create(id).config(builder -> MetaCache.getBranch(dataLocation).buildConfig(builder, id, dataLocation.dataLocation())), c.currentScreen));
}
}
}

View File

@ -24,7 +24,7 @@ public class RespackoptsConfig implements JfCustomConfig {
.referenceConfig(() -> {
List<ConfigInstance> instances = new LinkedList<>();
MetaCache.forEach((key, state) -> instances.add(DSL.create(state.packId())
.config(cb -> state.configBranch().buildConfig(cb, state.packId()))
.config(cb -> state.configBranch().buildConfig(cb, state.packId(), key.dataLocation()))
));
return instances;
})

View File

@ -31,34 +31,7 @@ public class ResourcePackManagerMixin {
dataLocations.clear();
profiles.forEach((s, v) -> {
try (ResourcePack rpi = v.createResourcePack()) {
Path dataLocation = null;
if (rpi instanceof AbstractFileResourcePack arr) {
Path pack = arr.getBase().toPath();
dataLocation = pack.getParent().resolve(pack.getFileName().toString() + Respackopts.FILE_EXTENSION);
}
try (InputStream is = rpi.openRoot(Respackopts.ID + ".json5")) {
readConfiguration(is, dataLocation, rpi.getName(), v.getDisplayName().getString(), toRemove);
return;
} catch (ResourceNotFoundException ignored) {
} catch (IOException e) {
Respackopts.LOGGER.error("Could not read respackopts config in root");
}
ResourceType packConfType = null;
for (ResourceType type : ResourceType.values()) {
if (rpi.contains(type, Respackopts.CONF_ID)) {
packConfType = type;
}
}
if (packConfType != null) {
try (InputStream is = rpi.open(packConfType, Respackopts.CONF_ID)) {
readConfiguration(is, dataLocation, rpi.getName(), v.getDisplayName().getString(), toRemove);
} catch (Throwable e) {
Respackopts.LOGGER.error("Could not initialize pack meta for " + s, e);
}
}
rpo$checkProfile(s, v.getDisplayName().getString(), rpi, toRemove);
}
});
for (Path s : toRemove) {
@ -68,7 +41,38 @@ public class ResourcePackManagerMixin {
MetaCache.save(SaveHook.Arguments.DO_NOTHING);
}
private void readConfiguration(InputStream is, Path dataLocation, String packName, String displayName, Set<Path> toRemove) throws IOException {
private void rpo$checkProfile(String profileName, String displayName, ResourcePack rpi, Set<Path> toRemove) {
Path dataLocation = null;
if (rpi instanceof AbstractFileResourcePack arr) {
Path pack = arr.getBase().toPath();
dataLocation = pack.getParent().resolve(pack.getFileName().toString() + Respackopts.FILE_EXTENSION);
}
try (InputStream is = rpi.openRoot(Respackopts.ID + ".json5")) {
rpo$readConfiguration(is, dataLocation, rpi.getName(), displayName, toRemove);
return;
} catch (ResourceNotFoundException ignored) {
} catch (IOException e) {
Respackopts.LOGGER.error("Could not read respackopts config in root for " + profileName, e);
}
ResourceType packConfType = null;
for (ResourceType type : ResourceType.values()) {
if (rpi.contains(type, Respackopts.CONF_ID)) {
packConfType = type;
}
}
if (packConfType != null) {
try (InputStream is = rpi.open(packConfType, Respackopts.CONF_ID)) {
rpo$readConfiguration(is, dataLocation, rpi.getName(), displayName, toRemove);
} catch (Throwable e) {
Respackopts.LOGGER.error("Could not initialize pack meta for " + profileName, e);
}
}
}
private void rpo$readConfiguration(InputStream is, Path dataLocation, String packName, String displayName, Set<Path> toRemove) throws IOException {
try (InputStreamReader isr = new InputStreamReader(is)) {
PackMeta conf = Respackopts.GSON.fromJson(isr, PackMeta.class);
if (RespackoptsConfig.debugLogs)

View File

@ -13,6 +13,7 @@ import io.gitlab.jfronny.respackopts.model.enums.PackReloadType;
import io.gitlab.jfronny.respackopts.util.IndentingStringBuilder;
import io.gitlab.jfronny.respackopts.util.MetaCache;
import java.nio.file.Path;
import java.util.*;
public class ConfigBranch extends ConfigEntry<Map<String, ConfigEntry<?>>> {
@ -105,7 +106,7 @@ public class ConfigBranch extends ConfigEntry<Map<String, ConfigEntry<?>>> {
});
}
public <T extends ConfigBuilder<?>> T buildConfig(T builder, String packId) {
public <T extends ConfigBuilder<?>> T buildConfig(T builder, String packId, Path dataLocation) {
builder.setTranslationPrefix("rpo." + packId + ".");
PackReloadType.Aggregator agg = new PackReloadType.Aggregator();
for (Map.Entry<String, ConfigEntry<?>> e : getValue().entrySet()) {
@ -119,6 +120,7 @@ public class ConfigBranch extends ConfigEntry<Map<String, ConfigEntry<?>>> {
if (RespackoptsConfig.debugLogs) Respackopts.LOGGER.info("GuiFactory SavingRunnable " + agg.get());
MetaCache.save(new SaveHook.Arguments(agg.get() == PackReloadType.Resource, false, true));
});
builder.setPath(dataLocation);
return builder;
}