add: copy instance. Closes #687

This commit is contained in:
huanghongxun
2020-03-19 13:12:51 +08:00
parent 3e2bb9678d
commit b2f6ef72c3
19 changed files with 370 additions and 59 deletions

View File

@@ -45,7 +45,7 @@ public interface ModAdviser {
"regex:(.*?)\\.log",
"usernamecache.json", "usercache.json", // Minecraft
"launcher_profiles.json", "launcher.pack.lzma", // Minecraft Launcher
"pack.json", "launcher.jar", "cache", "modpack.cfg", // HMCL
"backup", "pack.json", "launcher.jar", "cache", "modpack.cfg", // HMCL
"manifest.json", "minecraftinstance.json", ".curseclient", // Curse
".fabric", ".mixin.out", // Fabric
"jars", "logs", "versions", "assets", "libraries", "crash-reports", "NVIDIA", "AMD", "screenshots", "natives", "native", "$native", "server-resource-packs", // Minecraft

View File

@@ -93,6 +93,8 @@ public final class Modpack {
for (String s : blackList)
if (path.equals(s))
return false;
if (whiteList == null || whiteList.isEmpty())
return true;
for (String s : whiteList)
if (path.equals(s))
return true;

View File

@@ -21,5 +21,14 @@ import java.util.function.Consumer;
@FunctionalInterface
public interface FutureCallback<T> {
void call(T obj, Runnable resolve, Consumer<String> reject);
/**
* Callback of future, called after future finishes.
* This callback gives the feedback whether the result of future is acceptable or not,
* if not, giving the reason, and future will be relaunched when necessary.
* @param result result of the future
* @param resolve accept the result
* @param reject reject the result with failure reason
*/
void call(T result, Runnable resolve, Consumer<String> reject);
}

View File

@@ -30,6 +30,7 @@ import java.nio.file.attribute.BasicFileAttributes;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;
import static java.nio.charset.StandardCharsets.UTF_8;
@@ -196,20 +197,30 @@ public final class FileUtils {
* @throws IOException if an I/O error occurs.
*/
public static void copyDirectory(Path src, Path dest) throws IOException {
copyDirectory(src, dest, path -> true);
}
public static void copyDirectory(Path src, Path dest, Predicate<String> filePredicate) throws IOException {
Files.walkFileTree(src, new SimpleFileVisitor<Path>(){
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (!filePredicate.test(src.relativize(file).toString())) {
return FileVisitResult.SKIP_SUBTREE;
}
Path destFile = dest.resolve(src.relativize(file).toString());
Files.copy(file, destFile, StandardCopyOption.REPLACE_EXISTING);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
if (!filePredicate.test(src.relativize(dir).toString())) {
return FileVisitResult.SKIP_SUBTREE;
}
Path destDir = dest.resolve(src.relativize(dir).toString());
Files.createDirectories(destDir);
return FileVisitResult.CONTINUE;
}
});