2018-03-25 15:59:43 +00:00
|
|
|
/*
|
|
|
|
* Minecraft Forge
|
|
|
|
* Copyright (c) 2018.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
package net.minecraftforge.fml.common;
|
|
|
|
|
|
|
|
import cpw.mods.modlauncher.api.IEnvironment;
|
|
|
|
import net.minecraftforge.fml.FileUtils;
|
2018-08-27 17:10:07 +00:00
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
|
import org.apache.logging.log4j.Logger;
|
2018-03-25 15:59:43 +00:00
|
|
|
|
|
|
|
import java.nio.file.Path;
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
2018-04-07 03:58:48 +00:00
|
|
|
import static net.minecraftforge.fml.Logging.CORE;
|
2018-03-25 15:59:43 +00:00
|
|
|
|
|
|
|
public enum FMLPaths
|
|
|
|
{
|
|
|
|
GAMEDIR(),
|
|
|
|
MODSDIR("mods"),
|
|
|
|
CONFIGDIR("config"),
|
2018-08-27 17:10:07 +00:00
|
|
|
FMLCONFIG(false, CONFIGDIR, "fml.toml");
|
2018-03-25 15:59:43 +00:00
|
|
|
|
2018-08-27 17:10:07 +00:00
|
|
|
private static final Logger LOGGER = LogManager.getLogger();
|
2018-03-25 15:59:43 +00:00
|
|
|
private final Path relativePath;
|
|
|
|
private final boolean isDirectory;
|
|
|
|
private Path absolutePath;
|
|
|
|
|
|
|
|
FMLPaths() {
|
|
|
|
this("");
|
|
|
|
}
|
|
|
|
|
|
|
|
FMLPaths(String... path) {
|
|
|
|
relativePath = computePath(path);
|
|
|
|
this.isDirectory = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private Path computePath(String... path)
|
|
|
|
{
|
|
|
|
return Paths.get(path[0], Arrays.copyOfRange(path, 1, path.length));
|
|
|
|
}
|
|
|
|
|
|
|
|
FMLPaths(boolean isDir, FMLPaths parent, String... path) {
|
|
|
|
this.relativePath = parent.relativePath.resolve(computePath(path));
|
|
|
|
this.isDirectory = isDir;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setup(IEnvironment env) {
|
|
|
|
final Path rootPath = env.getProperty(IEnvironment.Keys.GAMEDIR.get()).orElseThrow(() -> new RuntimeException("No game path found"));
|
|
|
|
|
|
|
|
loadAbsolutePaths(rootPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void loadAbsolutePaths(Path rootPath)
|
|
|
|
{
|
|
|
|
for (FMLPaths path : FMLPaths.values())
|
|
|
|
{
|
|
|
|
path.absolutePath = rootPath.resolve(path.relativePath).toAbsolutePath();
|
2018-08-27 17:10:07 +00:00
|
|
|
LOGGER.debug(CORE,"Path {} is {}", ()-> path, ()-> path.absolutePath);
|
2018-03-25 15:59:43 +00:00
|
|
|
if (path.isDirectory)
|
|
|
|
{
|
|
|
|
FileUtils.getOrCreateDirectory(path.absolutePath, path.name());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Path get() {
|
|
|
|
return absolutePath;
|
|
|
|
}
|
|
|
|
}
|