2018-03-25 15:59:43 +00:00
|
|
|
/*
|
|
|
|
* Minecraft Forge
|
2019-02-10 22:57:03 +00:00
|
|
|
* Copyright (c) 2016-2019.
|
2018-03-25 15:59:43 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation version 2.1
|
|
|
|
* of the License.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2018-06-11 01:12:46 +00:00
|
|
|
package net.minecraftforge.fml.loading;
|
2018-03-25 15:59:43 +00:00
|
|
|
|
2018-08-27 17:10:07 +00:00
|
|
|
import com.electronwill.nightconfig.core.ConfigSpec;
|
|
|
|
import com.electronwill.nightconfig.core.file.CommentedFileConfig;
|
|
|
|
import com.electronwill.nightconfig.core.io.WritingMode;
|
|
|
|
import net.minecraftforge.api.distmarker.Dist;
|
|
|
|
import org.apache.logging.log4j.LogManager;
|
2019-01-06 20:46:29 +00:00
|
|
|
import org.apache.logging.log4j.Logger;
|
2018-03-25 15:59:43 +00:00
|
|
|
|
|
|
|
import java.nio.file.Path;
|
2018-08-27 17:10:07 +00:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.stream.Collectors;
|
2018-03-25 15:59:43 +00:00
|
|
|
|
2018-12-31 21:33:54 +00:00
|
|
|
import static net.minecraftforge.fml.loading.LogMarkers.CORE;
|
2018-03-25 15:59:43 +00:00
|
|
|
|
|
|
|
public class FMLConfig
|
|
|
|
{
|
2019-01-06 20:46:29 +00:00
|
|
|
private static final Logger LOGGER = LogManager.getLogger();
|
2018-08-27 17:10:07 +00:00
|
|
|
private static FMLConfig INSTANCE = new FMLConfig();
|
|
|
|
private static ConfigSpec configSpec = new ConfigSpec();
|
|
|
|
static {
|
|
|
|
configSpec.define("splashscreen", Boolean.TRUE);
|
2019-02-10 16:44:22 +00:00
|
|
|
configSpec.define("maxThreads", -1);
|
2019-02-10 21:38:14 +00:00
|
|
|
configSpec.define("versionCheck", Boolean.TRUE);
|
2018-03-25 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
2018-08-27 17:10:07 +00:00
|
|
|
private CommentedFileConfig configData;
|
2018-03-25 15:59:43 +00:00
|
|
|
|
2018-08-27 17:10:07 +00:00
|
|
|
private void loadFrom(final Path configFile)
|
2018-03-25 15:59:43 +00:00
|
|
|
{
|
2018-08-27 17:10:07 +00:00
|
|
|
configData = CommentedFileConfig.builder(configFile).sync().
|
|
|
|
defaultResource("/META-INF/defaultfmlconfig.toml").
|
|
|
|
autosave().autoreload().
|
|
|
|
writingMode(WritingMode.REPLACE).
|
|
|
|
build();
|
|
|
|
configData.load();
|
|
|
|
if (!configSpec.isCorrect(configData)) {
|
2019-01-06 20:46:29 +00:00
|
|
|
LOGGER.warn(CORE, "Configuration file {} is not correct. Correcting", configFile);
|
2018-08-27 17:10:07 +00:00
|
|
|
configSpec.correct(configData, (action, path, incorrectValue, correctedValue) ->
|
2019-01-06 20:46:29 +00:00
|
|
|
LOGGER.warn(CORE, "Incorrect key {} was corrected from {} to {}", path, incorrectValue, correctedValue));
|
2018-08-27 17:10:07 +00:00
|
|
|
}
|
|
|
|
configData.save();
|
2018-03-25 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void load()
|
|
|
|
{
|
|
|
|
final Path configFile = FMLPaths.FMLCONFIG.get();
|
2018-08-27 17:10:07 +00:00
|
|
|
INSTANCE.loadFrom(configFile);
|
2019-02-10 21:38:14 +00:00
|
|
|
LOGGER.trace(CORE, "Loaded FML config from {}", FMLPaths.FMLCONFIG.get());
|
|
|
|
LOGGER.trace(CORE, "Splash screen is {}", FMLConfig::splashScreenEnabled);
|
|
|
|
LOGGER.trace(CORE, "Max threads for mod loading computed at {}", FMLConfig::loadingThreadCount);
|
|
|
|
LOGGER.trace(CORE, "Version check is {}", FMLConfig::runVersionCheck);
|
2018-08-27 17:10:07 +00:00
|
|
|
}
|
|
|
|
|
2019-02-10 16:44:22 +00:00
|
|
|
public static boolean splashScreenEnabled() {
|
|
|
|
return INSTANCE.configData.<Boolean>getOptional("splashscreen").orElse(Boolean.FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int loadingThreadCount() {
|
2019-02-10 21:38:14 +00:00
|
|
|
int val = INSTANCE.configData.<Integer>getOptional("maxThreads").orElse(-1);
|
2019-02-10 16:44:22 +00:00
|
|
|
if (val <= 0) return Runtime.getRuntime().availableProcessors();
|
|
|
|
return val;
|
2018-03-25 15:59:43 +00:00
|
|
|
}
|
2019-02-10 21:38:14 +00:00
|
|
|
|
|
|
|
public static boolean runVersionCheck() {
|
|
|
|
return INSTANCE.configData.<Boolean>getOptional("versionCheck").orElse(Boolean.TRUE);
|
|
|
|
}
|
2018-03-25 15:59:43 +00:00
|
|
|
}
|