Fix cannot launch a game multiple times
This commit is contained in:
@@ -217,7 +217,7 @@ public class DefaultLauncher extends Launcher {
|
||||
|
||||
public void decompressNatives(File destination) throws NotDecompressingNativesException {
|
||||
try {
|
||||
FileUtils.cleanDirectory(destination);
|
||||
FileUtils.cleanDirectoryQuietly(destination);
|
||||
for (Library library : version.getLibraries())
|
||||
if (library.isNative())
|
||||
new Unzipper(repository.getLibraryFile(version, library), destination)
|
||||
@@ -229,7 +229,7 @@ public class DefaultLauncher extends Launcher {
|
||||
return false;
|
||||
return library.getExtract().shouldExtract(path);
|
||||
})
|
||||
.setReplaceExistentFile(true).unzip();
|
||||
.setReplaceExistentFile(false).unzip();
|
||||
} catch (IOException e) {
|
||||
throw new NotDecompressingNativesException(e);
|
||||
}
|
||||
|
||||
@@ -277,6 +277,15 @@ public final class FileUtils {
|
||||
throw exception;
|
||||
}
|
||||
|
||||
public static boolean cleanDirectoryQuietly(File directory) {
|
||||
try {
|
||||
cleanDirectory(directory);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void forceDelete(File file)
|
||||
throws IOException {
|
||||
if (file.isDirectory()) {
|
||||
|
||||
@@ -117,8 +117,12 @@ public class Unzipper {
|
||||
Path destFile = dest.resolve(relativePath);
|
||||
if (filter != null && !filter.accept(file, false, destFile, relativePath))
|
||||
return FileVisitResult.CONTINUE;
|
||||
if (replaceExistentFile || Files.notExists(destFile))
|
||||
Files.copy(file, destFile, StandardCopyOption.REPLACE_EXISTING);
|
||||
try {
|
||||
Files.copy(file, destFile, replaceExistentFile ? new CopyOption[]{StandardCopyOption.REPLACE_EXISTING} : new CopyOption[]{});
|
||||
} catch (FileAlreadyExistsException e) {
|
||||
if (replaceExistentFile)
|
||||
throw e;
|
||||
}
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
||||
@@ -129,9 +133,7 @@ public class Unzipper {
|
||||
Path dirToCreate = dest.resolve(relativePath);
|
||||
if (filter != null && !filter.accept(dir, true, dirToCreate, relativePath))
|
||||
return FileVisitResult.SKIP_SUBTREE;
|
||||
if (Files.notExists(dirToCreate)) {
|
||||
Files.createDirectory(dirToCreate);
|
||||
}
|
||||
Files.createDirectories(dirToCreate);
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user