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

35 lines
1.5 KiB
Java

package io.gitlab.jfronny.inceptum.launcher.system.setup.steps;
import io.gitlab.jfronny.inceptum.common.MetaHolder;
import io.gitlab.jfronny.inceptum.launcher.model.mojang.AssetIndex;
import io.gitlab.jfronny.inceptum.launcher.api.McApi;
import io.gitlab.jfronny.inceptum.launcher.system.setup.Step;
import io.gitlab.jfronny.inceptum.launcher.system.setup.SetupStepInfo;
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 (Map.Entry<String, AssetIndex.Asset> entry : McApi.getAssetIndex(info.version()).objects.entrySet()) {
if (stopThread.get()) return;
Path fPath = o.resolve(entry.getValue().hash.substring(0, 2));
if (!Files.exists(fPath)) Files.createDirectories(fPath);
fPath = fPath.resolve(entry.getValue().hash);
if (Files.exists(fPath)) continue;
info.setState("Downloading asset: " + entry.getKey());
McApi.downloadAsset(entry.getValue(), fPath);
}
} catch (URISyntaxException e) {
throw new IOException("Could not download assets", e);
}
}
}