feat:首次提交(无法使用)
This commit is contained in:
59
src/main.ts
Normal file
59
src/main.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import inquirer from "inquirer";
|
||||
import yauzl from "yauzl";
|
||||
import process from "node:process";
|
||||
import { join, basename } from "node:path";
|
||||
import { platform, what_platform } from "./platform/index.js";
|
||||
import { readzipentry } from "./utils/utils.js";
|
||||
interface Answers {
|
||||
modpack_path: string | undefined;
|
||||
}
|
||||
const unzip_path = "./instance";
|
||||
const argv = process.argv.slice(2)[0];
|
||||
|
||||
if (!argv) {
|
||||
const answer: Answers = await inquirer.prompt([
|
||||
{ type: "input", name: "modpack_path", message: "请输入整合包路径" },
|
||||
]);
|
||||
if (answer.modpack_path) {
|
||||
await main(answer.modpack_path);
|
||||
}
|
||||
} else {
|
||||
await main(argv);
|
||||
}
|
||||
|
||||
async function main(modpack_path: string) {
|
||||
const zipname = basename(modpack_path)
|
||||
.replace(".zip", "")
|
||||
.replace(".mrpack", "");
|
||||
let dud_files: Array<string> = [];
|
||||
let pack_info: object;
|
||||
//unzip
|
||||
yauzl.open(modpack_path, { lazyEntries: true }, (err, zipfile) => {
|
||||
zipfile.readEntry(); //首次读取
|
||||
zipfile.on("entry", async (entry) => {
|
||||
if (/\/$/.test(entry.fileName)) {
|
||||
} else if (entry.fileName.includes("overrides/")) {
|
||||
/*zipfile.openReadStream(entry,(err,stream)=>{ //读取overrides文件夹下的所有文件和文件夹
|
||||
|
||||
})*/
|
||||
//console.log(entry.fileName)
|
||||
} else {
|
||||
const name: string = entry.fileName;
|
||||
dud_files.push(name);
|
||||
if (name && name.endsWith(".json")) {
|
||||
pack_info = JSON.parse(
|
||||
(await readzipentry(zipfile, entry)).toString()
|
||||
);
|
||||
}
|
||||
console.log(name);
|
||||
}
|
||||
zipfile.readEntry();
|
||||
});
|
||||
zipfile.on("end", () => {
|
||||
//zip
|
||||
platform(what_platform(dud_files));
|
||||
//console.log(dud_files)
|
||||
zipfile.close();
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user