use of org.spongepowered.configurate.transformation.ConfigurationTransformation in project SpongeCommon by SpongePowered.
the class SpongeConfigs method splitFiles.
private static void splitFiles() {
final Path commonFile = SpongeConfigs.getDirectory().resolve(CommonConfig.FILE_NAME);
final Path metricsFile = SpongeConfigs.getDirectory().resolve(SpongeConfigs.METRICS_NAME);
final Path oldGlobalFile = SpongeConfigs.getDirectory().resolve(SpongeConfigs.GLOBAL_NAME);
// Is this migration unnecessary?
if (!Files.exists(oldGlobalFile) || Files.exists(commonFile) || Files.exists(metricsFile)) {
return;
}
try {
final ConfigurationTransformation xform = ConfigurationTransformation.chain(new FileMovingConfigurationTransformation(SpongeConfigs.MIGRATE_SPONGE_PATHS, SpongeConfigs.createLoader(commonFile), true), new FileMovingConfigurationTransformation(SpongeConfigs.MIGRATE_METRICS_PATHS, SpongeConfigs.createLoader(metricsFile), true));
final ConfigurationLoader<CommentedConfigurationNode> globalLoader = SpongeConfigs.createLoader(oldGlobalFile);
Files.copy(oldGlobalFile, oldGlobalFile.resolveSibling(SpongeConfigs.GLOBAL_NAME + ".old-backup"));
final CommentedConfigurationNode source = globalLoader.load();
xform.apply(source);
globalLoader.save(source);
SpongeConfigs.LOGGER.info("Migrated Sponge configuration to 1.15+ split-file layout");
} catch (final IOException ex) {
SpongeConfigs.LOGGER.error("An error occurred while trying to migrate to a split-file configuration layout", ex);
}
}
Aggregations