2018-03-25 15:59:43 +00:00
|
|
|
/*
|
|
|
|
* Minecraft Forge
|
2018-09-21 09:17:20 +00:00
|
|
|
* Copyright (c) 2016-2018.
|
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
|
|
|
|
*/
|
|
|
|
|
|
|
|
package net.minecraftforge.fml.loading.moddiscovery;
|
|
|
|
|
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.io.IOException;
|
|
|
|
import java.nio.file.FileSystems;
|
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.nio.file.Path;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
2018-04-07 03:58:48 +00:00
|
|
|
import java.util.Optional;
|
2018-03-25 15:59:43 +00:00
|
|
|
import java.util.function.Consumer;
|
2018-04-07 03:58:48 +00:00
|
|
|
import java.util.jar.Manifest;
|
2018-03-25 15:59:43 +00:00
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
2018-04-07 03:58:48 +00:00
|
|
|
import static net.minecraftforge.fml.Logging.LOADING;
|
|
|
|
import static net.minecraftforge.fml.Logging.SCAN;
|
2018-03-25 15:59:43 +00:00
|
|
|
|
|
|
|
public class ExplodedDirectoryLocator implements IModLocator {
|
|
|
|
private static final String DIR = System.getProperty("fml.explodedDir", "modclasses");
|
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 rootDir;
|
|
|
|
|
2018-04-07 03:58:48 +00:00
|
|
|
public ExplodedDirectoryLocator() {
|
2018-03-25 15:59:43 +00:00
|
|
|
this.rootDir = FileSystems.getDefault().getPath(DIR);
|
2018-04-07 03:58:48 +00:00
|
|
|
if (!Files.exists(this.rootDir)) {
|
2018-08-27 17:10:07 +00:00
|
|
|
LOGGER.debug(LOADING,"Creating directory {}" + this.rootDir);
|
2018-04-07 03:58:48 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
Files.createDirectory(this.rootDir);
|
|
|
|
}
|
|
|
|
catch (IOException e)
|
|
|
|
{
|
2018-08-27 17:10:07 +00:00
|
|
|
LOGGER.error(LOADING,"Error creating {}", this.rootDir, e);
|
2018-04-07 03:58:48 +00:00
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
2018-03-25 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<ModFile> scanMods() {
|
|
|
|
return Collections.singletonList(new ModFile(rootDir, this));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String name() {
|
|
|
|
return "exploded directory";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Path findPath(final ModFile modFile, final String... path) {
|
|
|
|
if (path.length < 1) {
|
|
|
|
throw new IllegalArgumentException("Missing path");
|
|
|
|
}
|
|
|
|
return rootDir.resolve(FileSystems.getDefault().getPath(path[0], Arrays.copyOfRange(path, 1, path.length)));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void scanFile(final ModFile modFile, final Consumer<Path> pathConsumer) {
|
2018-08-27 17:10:07 +00:00
|
|
|
LOGGER.debug(SCAN,"Scanning directory {}", rootDir);
|
2018-03-25 15:59:43 +00:00
|
|
|
try (Stream<Path> files = Files.find(rootDir, Integer.MAX_VALUE, (p, a) -> p.getNameCount() > 0 && p.getFileName().toString().endsWith(".class"))) {
|
|
|
|
files.forEach(pathConsumer);
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2018-08-27 17:10:07 +00:00
|
|
|
LOGGER.debug(SCAN,"Directory scan complete {}", rootDir);
|
2018-04-07 03:58:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString()
|
|
|
|
{
|
|
|
|
return "{ExplodedDir locator at "+this.rootDir+"}";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Optional<Manifest> findManifest(Path file)
|
|
|
|
{
|
|
|
|
return Optional.empty();
|
2018-03-25 15:59:43 +00:00
|
|
|
}
|
|
|
|
}
|