Search in sources :

Example 1 with FileConfig

use of com.electronwill.nightconfig.core.file.FileConfig in project SpongeCommon by SpongePowered.

the class ModFileParsers method dummySpongeModParser.

public static IModFileInfo dummySpongeModParser(final IModFile realModFile, final String fileName, final IModFile iModFile) {
    final ModFile modFile = (ModFile) iModFile;
    AppLaunch.logger().debug("Considering sponge platform candidate {}", modFile.getFilePath());
    final Path modsjson = modFile.getLocator().findPath(realModFile, fileName + ".toml");
    if (!Files.exists(modsjson)) {
        AppLaunch.logger().warn("Sponge platform file '{}' is missing the '{}' file", modFile, fileName + ".toml");
        return null;
    } else {
        final FileConfig fileConfig = FileConfig.builder(modsjson).build();
        fileConfig.load();
        fileConfig.close();
        final NightConfigWrapper configWrapper = new NightConfigWrapper(fileConfig);
        try {
            return ModFileParsers.generateModFileMetadata(modFile, configWrapper);
        } catch (final Exception e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : Path(java.nio.file.Path) FileConfig(com.electronwill.nightconfig.core.file.FileConfig) ModFile(net.minecraftforge.fml.loading.moddiscovery.ModFile) IModFile(net.minecraftforge.forgespi.locating.IModFile) NightConfigWrapper(net.minecraftforge.fml.loading.moddiscovery.NightConfigWrapper)

Example 2 with FileConfig

use of com.electronwill.nightconfig.core.file.FileConfig in project MinecraftForge by MinecraftForge.

the class ModFileParser method modsTomlParser.

public static IModFileInfo modsTomlParser(final IModFile imodFile) {
    ModFile modFile = (ModFile) imodFile;
    LOGGER.debug(LogMarkers.LOADING, "Considering mod file candidate {}", modFile.getFilePath());
    final Path modsjson = modFile.findResource("META-INF", "mods.toml");
    if (!Files.exists(modsjson)) {
        LOGGER.warn(LogMarkers.LOADING, "Mod file {} is missing mods.toml file", modFile.getFilePath());
        return null;
    }
    final FileConfig fileConfig = FileConfig.builder(modsjson).build();
    fileConfig.load();
    fileConfig.close();
    final NightConfigWrapper configWrapper = new NightConfigWrapper(fileConfig);
    final ModFileInfo modFileInfo = new ModFileInfo(modFile, configWrapper);
    configWrapper.setFile(modFileInfo);
    return modFileInfo;
}
Also used : Path(java.nio.file.Path) FileConfig(com.electronwill.nightconfig.core.file.FileConfig) IModFile(net.minecraftforge.forgespi.locating.IModFile) IModFileInfo(net.minecraftforge.forgespi.language.IModFileInfo)

Aggregations

FileConfig (com.electronwill.nightconfig.core.file.FileConfig)2 Path (java.nio.file.Path)2 IModFile (net.minecraftforge.forgespi.locating.IModFile)2 ModFile (net.minecraftforge.fml.loading.moddiscovery.ModFile)1 NightConfigWrapper (net.minecraftforge.fml.loading.moddiscovery.NightConfigWrapper)1 IModFileInfo (net.minecraftforge.forgespi.language.IModFileInfo)1