Fix cannot launch a game multiple times

This commit is contained in:
huanghongxun
2019-03-24 12:14:13 +08:00
parent 23e2df5e58
commit 3f4364c67c
3 changed files with 18 additions and 7 deletions

View File

@@ -217,7 +217,7 @@ public class DefaultLauncher extends Launcher {
public void decompressNatives(File destination) throws NotDecompressingNativesException { public void decompressNatives(File destination) throws NotDecompressingNativesException {
try { try {
FileUtils.cleanDirectory(destination); FileUtils.cleanDirectoryQuietly(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)
@@ -229,7 +229,7 @@ public class DefaultLauncher extends Launcher {
return false; return false;
return library.getExtract().shouldExtract(path); return library.getExtract().shouldExtract(path);
}) })
.setReplaceExistentFile(true).unzip(); .setReplaceExistentFile(false).unzip();
} catch (IOException e) { } catch (IOException e) {
throw new NotDecompressingNativesException(e); throw new NotDecompressingNativesException(e);
} }

View File

@@ -277,6 +277,15 @@ public final class FileUtils {
throw exception; throw exception;
} }
public static boolean cleanDirectoryQuietly(File directory) {
try {
cleanDirectory(directory);
return true;
} catch (IOException e) {
return false;
}
}
public static void forceDelete(File file) public static void forceDelete(File file)
throws IOException { throws IOException {
if (file.isDirectory()) { if (file.isDirectory()) {

View File

@@ -117,8 +117,12 @@ public class Unzipper {
Path destFile = dest.resolve(relativePath); Path destFile = dest.resolve(relativePath);
if (filter != null && !filter.accept(file, false, destFile, relativePath)) if (filter != null && !filter.accept(file, false, destFile, relativePath))
return FileVisitResult.CONTINUE; return FileVisitResult.CONTINUE;
if (replaceExistentFile || Files.notExists(destFile)) try {
Files.copy(file, destFile, StandardCopyOption.REPLACE_EXISTING); Files.copy(file, destFile, replaceExistentFile ? new CopyOption[]{StandardCopyOption.REPLACE_EXISTING} : new CopyOption[]{});
} catch (FileAlreadyExistsException e) {
if (replaceExistentFile)
throw e;
}
return FileVisitResult.CONTINUE; return FileVisitResult.CONTINUE;
} }
@@ -129,9 +133,7 @@ public class Unzipper {
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.SKIP_SUBTREE; return FileVisitResult.SKIP_SUBTREE;
if (Files.notExists(dirToCreate)) { Files.createDirectories(dirToCreate);
Files.createDirectory(dirToCreate);
}
return FileVisitResult.CONTINUE; return FileVisitResult.CONTINUE;
} }
}); });