fix: game crashes when asset index file is empty
This commit is contained in:
@@ -93,44 +93,43 @@ public final class GameAssetDownloadTask extends Task<Void> {
|
|||||||
public void execute() throws Exception {
|
public void execute() throws Exception {
|
||||||
AssetIndex index;
|
AssetIndex index;
|
||||||
try {
|
try {
|
||||||
index = JsonUtils.GSON.fromJson(FileUtils.readText(assetIndexFile), AssetIndex.class);
|
index = JsonUtils.fromNonNullJson(FileUtils.readText(assetIndexFile), AssetIndex.class);
|
||||||
} catch (IOException | JsonSyntaxException e) {
|
} catch (IOException | JsonParseException e) {
|
||||||
throw new GameAssetIndexDownloadTask.GameAssetIndexMalformedException();
|
throw new GameAssetIndexDownloadTask.GameAssetIndexMalformedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
int progress = 0;
|
int progress = 0;
|
||||||
if (index != null)
|
for (AssetObject assetObject : index.getObjects().values()) {
|
||||||
for (AssetObject assetObject : index.getObjects().values()) {
|
if (isCancelled())
|
||||||
if (isCancelled())
|
throw new InterruptedException();
|
||||||
throw new InterruptedException();
|
|
||||||
|
|
||||||
File file = dependencyManager.getGameRepository().getAssetObject(version.getId(), assetIndexInfo.getId(), assetObject);
|
File file = dependencyManager.getGameRepository().getAssetObject(version.getId(), assetIndexInfo.getId(), assetObject);
|
||||||
boolean download = !file.isFile();
|
boolean download = !file.isFile();
|
||||||
try {
|
try {
|
||||||
if (!download && integrityCheck && !assetObject.validateChecksum(file.toPath(), true))
|
if (!download && integrityCheck && !assetObject.validateChecksum(file.toPath(), true))
|
||||||
download = true;
|
download = true;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Logging.LOG.log(Level.WARNING, "Unable to calc hash value of file " + file.toPath(), e);
|
Logging.LOG.log(Level.WARNING, "Unable to calc hash value of file " + file.toPath(), e);
|
||||||
}
|
|
||||||
if (download) {
|
|
||||||
List<URL> urls = dependencyManager.getPreferredDownloadProviders().stream()
|
|
||||||
.map(downloadProvider -> downloadProvider.getAssetBaseURL() + assetObject.getLocation())
|
|
||||||
.map(NetworkUtils::toURL)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
FileDownloadTask task = new FileDownloadTask(urls, file, new FileDownloadTask.IntegrityCheck("SHA-1", assetObject.getHash()));
|
|
||||||
task.setName(assetObject.getHash());
|
|
||||||
dependencies.add(task
|
|
||||||
.setCacheRepository(dependencyManager.getCacheRepository())
|
|
||||||
.setCaching(true)
|
|
||||||
.setCandidate(dependencyManager.getCacheRepository().getCommonDirectory()
|
|
||||||
.resolve("assets").resolve("objects").resolve(assetObject.getLocation())));
|
|
||||||
} else {
|
|
||||||
dependencyManager.getCacheRepository().tryCacheFile(file.toPath(), CacheRepository.SHA1, assetObject.getHash());
|
|
||||||
}
|
|
||||||
|
|
||||||
updateProgress(++progress, index.getObjects().size());
|
|
||||||
}
|
}
|
||||||
|
if (download) {
|
||||||
|
List<URL> urls = dependencyManager.getPreferredDownloadProviders().stream()
|
||||||
|
.map(downloadProvider -> downloadProvider.getAssetBaseURL() + assetObject.getLocation())
|
||||||
|
.map(NetworkUtils::toURL)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
FileDownloadTask task = new FileDownloadTask(urls, file, new FileDownloadTask.IntegrityCheck("SHA-1", assetObject.getHash()));
|
||||||
|
task.setName(assetObject.getHash());
|
||||||
|
dependencies.add(task
|
||||||
|
.setCacheRepository(dependencyManager.getCacheRepository())
|
||||||
|
.setCaching(true)
|
||||||
|
.setCandidate(dependencyManager.getCacheRepository().getCommonDirectory()
|
||||||
|
.resolve("assets").resolve("objects").resolve(assetObject.getLocation())));
|
||||||
|
} else {
|
||||||
|
dependencyManager.getCacheRepository().tryCacheFile(file.toPath(), CacheRepository.SHA1, assetObject.getHash());
|
||||||
|
}
|
||||||
|
|
||||||
|
updateProgress(++progress, index.getObjects().size());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final boolean DOWNLOAD_INDEX_FORCIBLY = true;
|
public static final boolean DOWNLOAD_INDEX_FORCIBLY = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user