refactor:优化

This commit is contained in:
Tianpao
2025-07-09 19:15:59 +08:00
parent 1e35fac53b
commit 2f518e4487

View File

@@ -54,12 +54,13 @@ async function main(modpack_path: string) {
yauzl.open(modpack_path, { lazyEntries: true }, (err, zipfile) => { yauzl.open(modpack_path, { lazyEntries: true }, (err, zipfile) => {
zipfile.readEntry(); //首次读取 zipfile.readEntry(); //首次读取
zipfile.on("entry", async (entry) => { zipfile.on("entry", async (entry) => {
if (/\/$/.test(entry.fileName)) { const name: string = entry.fileName;
} else if (entry.fileName.includes("overrides/")) { if (/\/$/.test(name)) {
} else if (name.includes("overrides/")) {
const zipfilex = join( const zipfilex = join(
unzip_path, unzip_path,
zipname, zipname,
entry.fileName.replace("overrides/", "") name.replace("overrides/", "")
); );
if (!fs.existsSync(zipfilex)) { if (!fs.existsSync(zipfilex)) {
zipfile.openReadStream(entry, (err, stream) => { zipfile.openReadStream(entry, (err, stream) => {
@@ -69,18 +70,14 @@ async function main(modpack_path: string) {
console.log(zipfilex); console.log(zipfilex);
stream.pipe(fse.createWriteStream(zipfilex)); stream.pipe(fse.createWriteStream(zipfilex));
}); });
//console.log(entry.fileName)
} }
} else { } else if (name.endsWith(".json")||name.includes("mcbbs.packmeta")) {
const name: string = entry.fileName; dud_files.push(name);
dud_files.push(name);
if (name.endsWith(".json")) {
//console.log((await readzipentry(zipfile, entry))) //console.log((await readzipentry(zipfile, entry)))
pack_info = JSON.parse( pack_info = JSON.parse(
(await readzipentry(zipfile, entry)).toString() (await readzipentry(zipfile, entry)).toString()
); );
} }
}
zipfile.readEntry(); zipfile.readEntry();
}); });
zipfile.on("end", async () => { zipfile.on("end", async () => {
@@ -93,7 +90,7 @@ async function main(modpack_path: string) {
await install(info.loader, info.minecraft, info.loader_version, dirx); await install(info.loader, info.minecraft, info.loader_version, dirx);
fs.writeFileSync( fs.writeFileSync(
join(dirx, "instance.zip"), join(dirx, "instance.zip"),
"#By changing the setting below to TRUE you are indicating your agreement to our EULA (https://aka.ms/MinecraftEULA).\n#This serverpack created by DeEarthX\neula=true" "#By changing the setting below to TRUE you are indicating your agreement to our EULA (https://aka.ms/MinecraftEULA).\n#This serverpack created by DeEarthX(QQ_Group:559349662)\neula=true"
); );
LOGGER.info("DeEarthX已将服务端制作完成"); LOGGER.info("DeEarthX已将服务端制作完成");
zipfile.close(); zipfile.close();