UNPKG

dmclc

Version:

Dolphin Minecraft Launcher Core

84 lines (83 loc) 2.62 kB
import fs from 'fs'; import fsPromises from 'fs/promises'; import StreamZip from 'node-stream-zip'; import { downloadAll } from '../../../utils/downloads.js'; export class CurseForgeModpack { zipFile; manifest; launcher; unzipDir; constructor(zipFile, manifest, launcher) { this.zipFile = zipFile; this.manifest = manifest; this.launcher = launcher; } async downloadMods(mcdir) { const map = new Map(); for (const i of this.manifest.files) { if (!i.required) { continue; } const cf = this.launcher.contentServices.get("curseforge"); const version = await cf.getContentVersion(i.projectID, i.fileID); if (!(typeof await version.getVersionFileURL() == "string")) continue; map.set(await version.getVersionFileURL(), `${mcdir}/mods/${await version.getVersionFileName()}`); } return await downloadAll(map, this.launcher); } async getOverrideDirs() { if (this.unzipDir === undefined) { this.unzipDir = await fsPromises.mkdtemp(this.manifest.name); this.zipFile.extract(null, this.unzipDir); } const ret = []; if (fs.existsSync(`${this.unzipDir}/overrides`)) { ret.push(`${this.unzipDir}/overrides`); } if (fs.existsSync(`${this.unzipDir}/client-overrides`)) { ret.push(`${this.unzipDir}/client-overrides`); } return ret; } getName() { return this.manifest.name; } getSummary() { return "Loerm ipusm..."; } getVersion() { return this.manifest.version; } getLoaders() { const loaders = this.manifest.minecraft.modLoaders; return loaders.map(v => { return { name: v.id.split('-')[0], version: v.id.split('-')[1] }; }); } getMinecraftVersion() { return this.manifest.minecraft.version; } } export class CurseForgeModpackFormat { async readModpack(file, launcher) { const zip = new StreamZip.async({ file }); const index = JSON.parse((await zip.entryData("manifest.json")).toString()); return new CurseForgeModpack(zip, index, launcher); } async checkModpack(file, launcher) { const zip = new StreamZip.async({ file }); for (let key in (await zip.entries())) { if (key === "manifest.json") return true; } return false; } }