Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function findMainClass(lib: string) {
const zip = await Unzip.open(lib, { lazyEntries: true });
const [manifest] = await zip.filterEntries(["META-INF/MANIFEST.MF"]);
let mainClass: string | undefined;
if (manifest) {
const content = await zip.readEntry(manifest).then((b) => b.toString());
const mainClassPair = content.split("\n").map((l) => l.split(": ")).filter((arr) => arr[0] === "Main-Class")[0];
if (mainClassPair) {
mainClass = mainClassPair[1].trim();
}
}
zip.close();
return mainClass;
}
await context.execute(async function installForgeJson() {
const zip = await Unzip.open(jarPath, { lazyEntries: true });
const [versionEntry] = await zip.filterEntries(["version.json"]);
if (versionEntry) {
const buf = await zip.readEntry(versionEntry);
const raw = JSON.parse(buf.toString());
const id = raw.id;
fullVersion = id;
const rootPath = mc.getVersionRoot(fullVersion);
realJarPath = mc.getLibraryByPath(Version.getLibraryInfo(raw.libraries.find((l: any) => l.name.startsWith("net.minecraftforge:forge"))).path);
await vfs.ensureDir(rootPath);
const jsonPath = join(rootPath, `${id}.json`);
if (await vfs.missing(jsonPath)) {
await vfs.writeFile(jsonPath, buf);
}
} else {