2022-10-27 20:54:55 +02:00
|
|
|
package io.gitlab.jfronny.inceptum.launcher.system.setup.steps;
|
2022-01-18 18:43:39 +01:00
|
|
|
|
2022-09-04 21:21:24 +02:00
|
|
|
import io.gitlab.jfronny.inceptum.common.MetaHolder;
|
|
|
|
import io.gitlab.jfronny.inceptum.launcher.api.McApi;
|
2022-11-04 17:02:24 +01:00
|
|
|
import io.gitlab.jfronny.inceptum.launcher.model.mojang.AssetIndex;
|
2022-10-27 20:54:55 +02:00
|
|
|
import io.gitlab.jfronny.inceptum.launcher.system.setup.SetupStepInfo;
|
2022-11-04 17:02:24 +01:00
|
|
|
import io.gitlab.jfronny.inceptum.launcher.system.setup.Step;
|
2022-01-18 18:43:39 +01:00
|
|
|
|
|
|
|
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 {
|
2022-11-18 21:58:40 +01:00
|
|
|
for (var entry : McApi.getAssetIndex(info.version).objects) {
|
2022-01-18 18:43:39 +01:00
|
|
|
if (stopThread.get()) return;
|
2022-11-18 21:58:40 +01:00
|
|
|
Path fPath = o.resolve(entry.value.hash.substring(0, 2));
|
2022-01-18 18:43:39 +01:00
|
|
|
if (!Files.exists(fPath)) Files.createDirectories(fPath);
|
2022-11-18 21:58:40 +01:00
|
|
|
fPath = fPath.resolve(entry.value.hash);
|
2022-01-18 18:43:39 +01:00
|
|
|
if (Files.exists(fPath)) continue;
|
2022-11-18 21:58:40 +01:00
|
|
|
info.setState("Downloading asset: " + entry.key);
|
|
|
|
McApi.downloadAsset(entry.value, fPath);
|
2022-01-18 18:43:39 +01:00
|
|
|
}
|
2022-12-17 21:53:21 +01:00
|
|
|
} catch (Throwable e) {
|
2022-01-18 18:43:39 +01:00
|
|
|
throw new IOException("Could not download assets", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|