Unzip natives to /versions/ reducing trashes in temp
This commit is contained in:
@@ -73,9 +73,9 @@ public final class ModpackFileSelectionPage extends StackPane implements WizardP
|
|||||||
ModAdviser.ModSuggestion state = ModAdviser.ModSuggestion.SUGGESTED;
|
ModAdviser.ModSuggestion state = ModAdviser.ModSuggestion.SUGGESTED;
|
||||||
if (basePath.length() > "minecraft/".length()) {
|
if (basePath.length() > "minecraft/".length()) {
|
||||||
state = adviser.advise(StringUtils.substringAfter(basePath, "minecraft/") + (file.isDirectory() ? "/" : ""), file.isDirectory());
|
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;
|
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;
|
state = ModAdviser.ModSuggestion.HIDDEN;
|
||||||
if (state == ModAdviser.ModSuggestion.HIDDEN)
|
if (state == ModAdviser.ModSuggestion.HIDDEN)
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -217,10 +217,18 @@ public class DefaultLauncher extends Launcher {
|
|||||||
|
|
||||||
public void decompressNatives(File destination) throws NotDecompressingNativesException {
|
public void decompressNatives(File destination) throws NotDecompressingNativesException {
|
||||||
try {
|
try {
|
||||||
|
FileUtils.cleanDirectory(destination);
|
||||||
for (Library library : version.getLibraries())
|
for (Library library : version.getLibraries())
|
||||||
if (library.isNative())
|
if (library.isNative())
|
||||||
new Unzipper(repository.getLibraryFile(version, library), destination)
|
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();
|
.setReplaceExistentFile(true).unzip();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new NotDecompressingNativesException(e);
|
throw new NotDecompressingNativesException(e);
|
||||||
@@ -247,7 +255,7 @@ public class DefaultLauncher extends Launcher {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ManagedProcess launch() throws IOException, InterruptedException {
|
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
|
// To guarantee that when failed to generate launch command line, we will not call pre-launch command
|
||||||
List<String> rawCommandLine = generateCommandLine(nativeFolder).asList();
|
List<String> rawCommandLine = generateCommandLine(nativeFolder).asList();
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ public class Unzipper {
|
|||||||
String relativePath = root.relativize(dir).toString();
|
String relativePath = root.relativize(dir).toString();
|
||||||
Path dirToCreate = dest.resolve(relativePath);
|
Path dirToCreate = dest.resolve(relativePath);
|
||||||
if (filter != null && !filter.accept(dir, true, dirToCreate, relativePath))
|
if (filter != null && !filter.accept(dir, true, dirToCreate, relativePath))
|
||||||
return FileVisitResult.CONTINUE;
|
return FileVisitResult.SKIP_SUBTREE;
|
||||||
if (Files.notExists(dirToCreate)) {
|
if (Files.notExists(dirToCreate)) {
|
||||||
Files.createDirectory(dirToCreate);
|
Files.createDirectory(dirToCreate);
|
||||||
}
|
}
|
||||||
@@ -139,6 +139,6 @@ public class Unzipper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public interface FileFilter {
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user