package io.gitlab.jfronny.inceptum.launcher.system.instance; import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.inceptum.ModMeta.GC_ModMeta; import io.gitlab.jfronny.inceptum.launcher.model.inceptum.ModMeta; import io.gitlab.jfronny.inceptum.launcher.system.mds.ModsDirScanner; import io.gitlab.jfronny.inceptum.launcher.system.source.ModDownload; import io.gitlab.jfronny.inceptum.launcher.system.source.ModSource; import java.io.IOException; import java.nio.file.Path; public class ModManager { public static DownloadMeta download(ModSource ms, Path metaFile, ModsDirScanner mds) throws IOException { for (Mod value : mds.mods) { for (ModSource source : value.metadata.sources.keySet()) { if (ms.equals(source)) { return new DownloadMeta(new ModDownload(value.metadata.sha1, value.metadata.murmur2, value.jarPath), value.metadata, source, metaFile); } } } ModDownload md = ms.download(); ModMeta manifest = ModMeta.of(md.sha1, md.murmur2, ms, mds.gameVersion); for (ModSource depSrc : ms.getDependencies(mds.gameVersion)) { DownloadMeta depMeta = download(depSrc, metaFile.parent.resolve(depSrc.shortName + ModPath.EXT_IMOD), mds); depMeta.meta.dependents.add(metaFile.fileName.toString()); manifest.dependencies.add(depMeta.metaFile.fileName.toString()); depMeta.write(); } return new DownloadMeta(md, manifest, ms, metaFile); } public record DownloadMeta(ModDownload download, ModMeta meta, ModSource source, Path metaFile) { public void write() throws IOException { GC_ModMeta.write(meta, metaFile); } } }