Inceptum/src/main/java/io/gitlab/jfronny/inceptum/install/steps/DownloadAssetsStep.java

28 lines
1.1 KiB
Java

package io.gitlab.jfronny.inceptum.install.steps;
import io.gitlab.jfronny.inceptum.Inceptum;
import io.gitlab.jfronny.inceptum.install.SetupStepInfo;
import io.gitlab.jfronny.inceptum.install.Step;
import io.gitlab.jfronny.inceptum.model.mojang.AssetIndex;
import io.gitlab.jfronny.inceptum.util.McApi;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
public class DownloadAssetsStep implements Step {
@Override
public void execute(SetupStepInfo info) throws IOException {
Path o = Inceptum.ASSETS_DIR.resolve("objects");
for (Map.Entry<String, AssetIndex.Asset> entry : McApi.getAssetIndex(info.version()).objects.entrySet()) {
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)) return;
Inceptum.LOGGER.info("Downloading asset: " + entry.getKey());
McApi.downloadAsset(entry.getValue(), fPath);
}
}
}