use of org.orecruncher.dsurround.registry.config.Profiles.ProfileScript in project DynamicSurroundings by OreCruncher.
the class ConfigData method load.
public static ConfigData load() {
final FastByteArrayOutputStream bits = new FastByteArrayOutputStream(16 * 1024);
try (final OutputStreamWriter output = new OutputStreamWriter(new GZIPOutputStream(bits))) {
// We are writing a Json array of objects so start with the open
output.write("[");
boolean prependComma = false;
// Collect the locations where DS data is configured
final List<IMyResourcePack> packs = ResourcePacks.findResourcePacks();
final List<ModContainer> activeMods = Loader.instance().getActiveModList();
// files from the dsurround jar.
for (final ModContainer mod : activeMods) {
final ResourceLocation rl = new ResourceLocation(ModInfo.MOD_ID, "data/" + mod.getModId().toLowerCase() + ".json");
for (final IMyResourcePack p : packs) {
if (p.resourceExists(rl))
prependComma = copy(p, rl, output, "[" + rl.toString() + "] from [" + p.getModName() + "]", prependComma);
}
}
// Get config data from our JAR.
final ResourceLocation rl = ResourcePacks.CONFIGURE_RESOURCE;
for (final IMyResourcePack p : packs) {
if (p.resourceExists(rl))
prependComma = copy(p, rl, output, "[" + rl.toString() + "] from [" + p.getModName() + "]", prependComma);
}
// Built in toggle profiles for turning feature sets on/off
final List<ProfileScript> resources = Profiles.getProfileStreams();
for (final ProfileScript script : resources) {
try (final InputStreamReader reader = new InputStreamReader(script.stream)) {
prependComma = copy(reader, output, script.packName, prependComma);
} catch (@Nonnull final Throwable t) {
ModBase.log().error("Error reading profile script", t);
}
}
// by players or pack makers.
for (final String cfg : ModOptions.general.externalScriptFiles) {
final File file = getFileReference(cfg);
if (file.exists()) {
ModBase.log().info("Loading external configuration script '%s'", cfg);
try (final InputStream stream = new FileInputStream(file)) {
try (final InputStreamReader input = new InputStreamReader(stream)) {
prependComma = copy(input, output, cfg, prependComma);
} catch (final Throwable t) {
ModBase.log().error(String.format("Unable to load configuration script '%s'", cfg), t);
}
} catch (final Throwable t) {
ModBase.log().error(String.format("Unable to load configuration script '%s'", cfg), t);
}
}
}
// The tap - need to close out the json array and flush
// the stream to make sure.
output.write("]");
output.flush();
} catch (@Nonnull final Throwable t) {
ModBase.log().error("Something went horribly wrong", t);
}
// dump(bits.toByteArray());
bits.trim();
return new ConfigData(bits.array);
}
Aggregations