Inceptum/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/setup/steps/DownloadAssetsStep.java

35 lines
1.4 KiB
Java

package io.gitlab.jfronny.inceptum.launcher.system.setup.steps;
import io.gitlab.jfronny.inceptum.common.MetaHolder;
import io.gitlab.jfronny.inceptum.launcher.api.McApi;
import io.gitlab.jfronny.inceptum.launcher.model.mojang.AssetIndex;
import io.gitlab.jfronny.inceptum.launcher.system.setup.SetupStepInfo;
import io.gitlab.jfronny.inceptum.launcher.system.setup.Step;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
public class DownloadAssetsStep implements Step {
@Override
public void execute(SetupStepInfo info, AtomicBoolean stopThread) throws IOException {
Path o = MetaHolder.ASSETS_DIR.resolve("objects");
try {
for (var entry : McApi.getAssetIndex(info.version).objects) {
if (stopThread.get()) return;
Path fPath = o.resolve(entry.value.hash.substring(0, 2));
if (!Files.exists(fPath)) Files.createDirectories(fPath);
fPath = fPath.resolve(entry.value.hash);
if (Files.exists(fPath)) continue;
info.setState("Downloading asset: " + entry.key);
McApi.downloadAsset(entry.value, fPath);
}
} catch (Throwable e) {
throw new IOException("Could not download assets", e);
}
}
}