Inceptum/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/importer/Importers.java

33 lines
1.3 KiB
Java

package io.gitlab.jfronny.inceptum.launcher.system.importer;
import io.gitlab.jfronny.inceptum.common.Utils;
import io.gitlab.jfronny.inceptum.launcher.system.setup.Steps;
import io.gitlab.jfronny.inceptum.launcher.util.ProcessState;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.FileSystem;
import java.nio.file.Path;
import java.util.List;
public class Importers {
public static final int MAX_STEPS = Steps.STEPS.size() + 3;
public static final CurseForgeImporter CURSE_FORGE = new CurseForgeImporter();
public static final ModrinthImporter MODRINTH = new ModrinthImporter();
public static final MultiMCImporter MULTI_MC = new MultiMCImporter();
public static final List<Importer<?>> IMPORTERS = List.of(CURSE_FORGE, MODRINTH, MULTI_MC);
public static Path importPack(Path zipPath, ProcessState state) throws IOException {
try (FileSystem fs = Utils.openZipFile(zipPath, false)) {
for (Importer<?> importer : IMPORTERS) {
if (importer.canImport(fs.getPath("."))) {
return importer.importPack(fs.getPath("."), state);
}
}
} catch (URISyntaxException e) {
throw new IOException("Could not open zip", e);
}
throw new IOException("Could not import pack: unsupported format");
}
}