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-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.nio.file.Files;
|
|
|
|
import java.nio.file.Path;
|
|
|
|
|
|
|
|
public class DownloadAssetsStep implements Step {
|
|
|
|
@Override
|
2023-01-29 18:34:33 +01:00
|
|
|
public void execute(SetupStepInfo info) throws IOException {
|
2022-01-18 18:43:39 +01:00
|
|
|
Path o = MetaHolder.ASSETS_DIR.resolve("objects");
|
|
|
|
try {
|
2023-05-05 18:49:56 +02:00
|
|
|
for (var entry : McApi.getAssetIndex(info.version()).objects().entrySet()) {
|
|
|
|
if (info.isCancelled()) return;
|
|
|
|
Path fPath = o.resolve(entry.getValue().hash().substring(0, 2));
|
2022-01-18 18:43:39 +01:00
|
|
|
if (!Files.exists(fPath)) Files.createDirectories(fPath);
|
2023-05-05 18:49:56 +02:00
|
|
|
fPath = fPath.resolve(entry.getValue().hash());
|
2022-01-18 18:43:39 +01:00
|
|
|
if (Files.exists(fPath)) continue;
|
2023-05-05 18:49:56 +02:00
|
|
|
info.setState("Downloading asset: " + entry.getKey());
|
|
|
|
McApi.downloadAsset(entry.getValue(), 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);
|
|
|
|
}
|
|
|
|
}
|
2023-01-29 15:45:51 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getName() {
|
|
|
|
return "Downloading Assets";
|
|
|
|
}
|
2022-01-18 18:43:39 +01:00
|
|
|
}
|