Unzip natives to /versions/ reducing trashes in temp

This commit is contained in:
huanghongxun
2019-03-21 11:08:00 +08:00
parent 79136db162
commit 23e2df5e58
3 changed files with 14 additions and 6 deletions

View File

@@ -73,9 +73,9 @@ public final class ModpackFileSelectionPage extends StackPane implements WizardP
ModAdviser.ModSuggestion state = ModAdviser.ModSuggestion.SUGGESTED;
if (basePath.length() > "minecraft/".length()) {
state = adviser.advise(StringUtils.substringAfter(basePath, "minecraft/") + (file.isDirectory() ? "/" : ""), file.isDirectory());
if (file.isFile() && Objects.equals(FileUtils.getNameWithoutExtension(file), version))
if (file.isFile() && Objects.equals(FileUtils.getNameWithoutExtension(file), version)) // Ignore <version>.json, <version>.jar
state = ModAdviser.ModSuggestion.HIDDEN;
if (file.isDirectory() && Objects.equals(file.getName(), version + "-natives"))
if (file.isDirectory() && Objects.equals(file.getName(), version + "-natives")) // Ignore <version>-natives
state = ModAdviser.ModSuggestion.HIDDEN;
if (state == ModAdviser.ModSuggestion.HIDDEN)
return null;

View File

@@ -217,10 +217,18 @@ public class DefaultLauncher extends Launcher {
public void decompressNatives(File destination) throws NotDecompressingNativesException {
try {
FileUtils.cleanDirectory(destination);
for (Library library : version.getLibraries())
if (library.isNative())
new Unzipper(repository.getLibraryFile(version, library), destination)
.setFilter((destFile, isDirectory, zipEntry, path) -> library.getExtract().shouldExtract(path))
.setFilter((zipEntry, isDirectory, destFile, path) -> {
if (!isDirectory && Files.isRegularFile(destFile) && Files.size(destFile) == Files.size(zipEntry))
return false;
String ext = FileUtils.getExtension(destFile);
if (ext.equals("sha1") || ext.equals("git"))
return false;
return library.getExtract().shouldExtract(path);
})
.setReplaceExistentFile(true).unzip();
} catch (IOException e) {
throw new NotDecompressingNativesException(e);
@@ -247,7 +255,7 @@ public class DefaultLauncher extends Launcher {
@Override
public ManagedProcess launch() throws IOException, InterruptedException {
File nativeFolder = Files.createTempDirectory("minecraft").toFile();
File nativeFolder = repository.getNativeDirectory(versionId);
// To guarantee that when failed to generate launch command line, we will not call pre-launch command
List<String> rawCommandLine = generateCommandLine(nativeFolder).asList();

View File

@@ -128,7 +128,7 @@ public class Unzipper {
String relativePath = root.relativize(dir).toString();
Path dirToCreate = dest.resolve(relativePath);
if (filter != null && !filter.accept(dir, true, dirToCreate, relativePath))
return FileVisitResult.CONTINUE;
return FileVisitResult.SKIP_SUBTREE;
if (Files.notExists(dirToCreate)) {
Files.createDirectory(dirToCreate);
}
@@ -139,6 +139,6 @@ public class Unzipper {
}
public interface FileFilter {
boolean accept(Path destPath, boolean isDirectory, Path zipEntry, String entryPath) throws IOException;
boolean accept(Path zipEntry, boolean isDirectory, Path destFile, String entryPath) throws IOException;
}
}