import { BearMetalStore } from "@bearmetal/store"; import { ZipReader } from "@zip.js/zip.js"; import { ensureFile } from "@std/fs"; export async function unzipResources(mcVersion?: string) { using store = new BearMetalStore(); mcVersion = mcVersion || await currentVersion(store); console.log("mcVersion", mcVersion); if (!mcVersion) return; const blob = await Deno.open( store.get("mcPath") + "/versions/" + mcVersion + "/" + mcVersion + ".jar", ); const zip = new ZipReader(blob); for (const entry of await zip.getEntries()) { if ( entry.filename.startsWith("assets/") || entry.filename.startsWith("data/") ) { // console.log("entry", entry); await ensureFile(`./resources/${mcVersion}/${entry.filename}`); const writer = await Deno.open( `./resources/${mcVersion}/${entry.filename}`, { write: true }, ); await entry.getData?.(writer); } } } async function currentVersion(store: BearMetalStore) { const mcPath = store.get("mcPath"); if (!mcPath) return; const versions = Array.from(Deno.readDirSync(mcPath + "/versions")).filter( (d) => d.isDirectory, ).map((d) => d.name).sort(); let version = versions.pop(); let found = false; versionC: while (!found) { for await (const file of Deno.readDir(mcPath + "/versions/" + version)) { if (file.name.endsWith(".jar")) { found = true; break versionC; } } version = versions.pop(); } return version; } if (import.meta.main) { unzipResources(); }