use of net.technicpack.launchercore.install.verifiers.FileSizeVerifier in project LauncherV3 by TechnicPack.
the class InstallMinecraftAssetsTask method runTask.
@Override
public void runTask(InstallTasksQueue queue) throws IOException {
String json = FileUtils.readFileToString(assetsIndex, StandardCharsets.UTF_8);
JsonObject obj = MojangUtils.getGson().fromJson(json, JsonObject.class);
if (obj == null) {
throw new DownloadException("The assets json file was invalid.");
}
boolean isVirtual = false;
if (obj.get(virtualField) != null)
isVirtual = obj.get(virtualField).getAsBoolean();
boolean mapToResources = false;
if (obj.get(mapToResourcesField) != null)
mapToResources = obj.get(mapToResourcesField).getAsBoolean();
((InstallTasksQueue<MojangVersion>) queue).getMetadata().setAreAssetsVirtual(isVirtual);
((InstallTasksQueue<MojangVersion>) queue).getMetadata().setAssetsMapToResources(mapToResources);
JsonObject allObjects = obj.get(objectsField).getAsJsonObject();
if (allObjects == null) {
throw new DownloadException("The assets json file was invalid.");
}
String assetsKey = ((InstallTasksQueue<MojangVersion>) queue).getMetadata().getAssetsKey();
if (assetsKey == null || assetsKey.isEmpty())
assetsKey = "legacy";
for (Map.Entry<String, JsonElement> field : allObjects.entrySet()) {
String friendlyName = field.getKey();
JsonObject file = field.getValue().getAsJsonObject();
String hash = file.get(hashField).getAsString();
long size = file.get(sizeField).getAsLong();
File location = new File(assetsDirectory + "/objects/" + hash.substring(0, 2), hash);
String url = MojangUtils.getResourceUrl(hash);
(new File(location.getParent())).mkdirs();
File target = null;
if (isVirtual)
target = new File(assetsDirectory + "/virtual/" + assetsKey + '/' + friendlyName);
else if (mapToResources)
target = new File(modpack.getResourcesDir(), friendlyName);
checkAssetsQueue.addTask(new EnsureFileTask(location, new FileSizeVerifier(size), null, url, hash, downloadAssetsQueue, copyAssetsQueue));
if (target != null && !target.exists()) {
(new File(target.getParent())).mkdirs();
copyAssetsQueue.addTask(new CopyFileTask(location, target));
}
}
}
Aggregations