Search in sources :

Example 1 with FileSizeVerifier

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));
        }
    }
}
Also used : EnsureFileTask(net.technicpack.launchercore.install.tasks.EnsureFileTask) MojangVersion(net.technicpack.minecraftcore.mojang.version.MojangVersion) JsonObject(com.google.gson.JsonObject) CopyFileTask(net.technicpack.launchercore.install.tasks.CopyFileTask) JsonElement(com.google.gson.JsonElement) DownloadException(net.technicpack.launchercore.exception.DownloadException) FileSizeVerifier(net.technicpack.launchercore.install.verifiers.FileSizeVerifier) Map(java.util.Map) File(java.io.File)

Aggregations

JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 File (java.io.File)1 Map (java.util.Map)1 DownloadException (net.technicpack.launchercore.exception.DownloadException)1 CopyFileTask (net.technicpack.launchercore.install.tasks.CopyFileTask)1 EnsureFileTask (net.technicpack.launchercore.install.tasks.EnsureFileTask)1 FileSizeVerifier (net.technicpack.launchercore.install.verifiers.FileSizeVerifier)1 MojangVersion (net.technicpack.minecraftcore.mojang.version.MojangVersion)1