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;
}
return async function downloadInstaller(ctx: Task.Context) {
await downloadFileIfAbsentWork({
url: installer,
destination: dest,
checksum: {
hash: version.installer.sha1,
algorithm: "sha1",
},
})(ctx);
return vfs.createReadStream(dest).pipe(Unzip.createParseStream({ lazyEntries: true })).wait();
};
}
async openFileSystem(basePath: string | Uint8Array): Promise {
if (typeof basePath === "string") {
const stat = await promises.stat(basePath);
if (stat.isDirectory()) {
return new DefaultFS(basePath);
} else {
const zip = await Unzip.open(basePath, { lazyEntries: false });
return new ZipFS(basePath, zip);
}
} else {
const zip = await Unzip.open(basePath as Buffer, { lazyEntries: false });
return new ZipFS("", zip);
}
}
decodeBase64(input: string): string {
async openFileSystem(basePath: string | Uint8Array): Promise {
if (typeof basePath === "string") {
const stat = await promises.stat(basePath);
if (stat.isDirectory()) {
return new DefaultFS(basePath);
} else {
const zip = await Unzip.open(basePath, { lazyEntries: false });
return new ZipFS(basePath, zip);
}
} else {
const zip = await Unzip.open(basePath as Buffer, { lazyEntries: false });
return new ZipFS("", zip);
}
}
decodeBase64(input: string): string {
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 {