feat:添加Eula
This commit is contained in:
116
src/main.ts
116
src/main.ts
@@ -1,27 +1,27 @@
|
|||||||
import inquirer from "inquirer";
|
import inquirer from "inquirer";
|
||||||
import yauzl from "yauzl";
|
import yauzl from "yauzl";
|
||||||
import process from "node:process";
|
import process from "node:process";
|
||||||
import fs from "node:fs"
|
import fs from "node:fs";
|
||||||
import fse from "fs-extra";
|
import fse from "fs-extra";
|
||||||
import { join, basename, dirname } from "node:path";
|
import { join, basename, dirname } from "node:path";
|
||||||
import { platform, what_platform } from "./platform/index.js";
|
import { platform, what_platform } from "./platform/index.js";
|
||||||
import { isDevelopment, readzipentry } from "./utils/utils.js";
|
import { isDevelopment, readzipentry } from "./utils/utils.js";
|
||||||
import fabric from "./ml_install/fabric.js"
|
import fabric from "./ml_install/fabric.js";
|
||||||
import forge from "./ml_install/forge.js"
|
import forge from "./ml_install/forge.js";
|
||||||
import neoforge from "./ml_install/neoforge.js"
|
import neoforge from "./ml_install/neoforge.js";
|
||||||
import { DeEarthMain } from "./utils/DeEarth.js";
|
import { DeEarthMain } from "./utils/DeEarth.js";
|
||||||
import { LOGGER } from "./utils/logger.js";
|
import { LOGGER } from "./utils/logger.js";
|
||||||
import { fileURLToPath } from "node:url";
|
import { fileURLToPath } from "node:url";
|
||||||
interface Answers {
|
interface Answers {
|
||||||
modpack_path: string | undefined;
|
modpack_path: string | undefined;
|
||||||
}
|
}
|
||||||
let unzip_path:string = ""
|
let unzip_path: string = "";
|
||||||
if(isDevelopment){
|
if (isDevelopment) {
|
||||||
unzip_path = join("./","instance/")
|
unzip_path = join("./", "instance/");
|
||||||
}else{
|
} else {
|
||||||
unzip_path = join(getCurrnetDir().replace("dist",""),"instance")
|
unzip_path = join(getCurrnetDir().replace("dist", ""), "instance");
|
||||||
}
|
}
|
||||||
let zipnamew: string = ""
|
let zipnamew: string = "";
|
||||||
const argv = process.argv.slice(2)[0];
|
const argv = process.argv.slice(2)[0];
|
||||||
|
|
||||||
if (!argv) {
|
if (!argv) {
|
||||||
@@ -29,25 +29,25 @@ if (!argv) {
|
|||||||
{ type: "input", name: "modpack_path", message: "请输入整合包路径" },
|
{ type: "input", name: "modpack_path", message: "请输入整合包路径" },
|
||||||
]);
|
]);
|
||||||
if (answer.modpack_path) {
|
if (answer.modpack_path) {
|
||||||
initdir()
|
initdir();
|
||||||
await main(answer.modpack_path);
|
await main(answer.modpack_path);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
initdir()
|
initdir();
|
||||||
await main(argv);
|
await main(argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
function initdir(){
|
function initdir() {
|
||||||
if(!fs.existsSync(unzip_path)){
|
if (!fs.existsSync(unzip_path)) {
|
||||||
fse.ensureDirSync(join(unzip_path,"rubbish"))
|
fse.ensureDirSync(join(unzip_path, "rubbish"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function main(modpack_path: string) {
|
async function main(modpack_path: string) {
|
||||||
const zipname= basename(modpack_path)
|
const zipname = basename(modpack_path)
|
||||||
.replace(".zip", "")
|
.replace(".zip", "")
|
||||||
.replace(".mrpack", "");
|
.replace(".mrpack", "");
|
||||||
zipnamew=zipname
|
zipnamew = zipname;
|
||||||
let dud_files: Array<string> = [];
|
let dud_files: Array<string> = [];
|
||||||
let pack_info: object;
|
let pack_info: object;
|
||||||
//unzip
|
//unzip
|
||||||
@@ -56,16 +56,21 @@ async function main(modpack_path: string) {
|
|||||||
zipfile.on("entry", async (entry) => {
|
zipfile.on("entry", async (entry) => {
|
||||||
if (/\/$/.test(entry.fileName)) {
|
if (/\/$/.test(entry.fileName)) {
|
||||||
} else if (entry.fileName.includes("overrides/")) {
|
} else if (entry.fileName.includes("overrides/")) {
|
||||||
const zipfilex = join(unzip_path, zipname,entry.fileName.replace("overrides/",""))
|
const zipfilex = join(
|
||||||
if(!fs.existsSync(zipfilex)){
|
unzip_path,
|
||||||
zipfile.openReadStream(entry,(err,stream)=>{ //读取overrides文件夹下的所有文件和文件夹
|
zipname,
|
||||||
const dir = dirname(zipfilex)
|
entry.fileName.replace("overrides/", "")
|
||||||
fse.ensureDirSync(dir);
|
);
|
||||||
console.log(zipfilex)
|
if (!fs.existsSync(zipfilex)) {
|
||||||
stream.pipe(fse.createWriteStream(zipfilex))
|
zipfile.openReadStream(entry, (err, stream) => {
|
||||||
})
|
//读取overrides文件夹下的所有文件和文件夹
|
||||||
//console.log(entry.fileName)
|
const dir = dirname(zipfilex);
|
||||||
}
|
fse.ensureDirSync(dir);
|
||||||
|
console.log(zipfilex);
|
||||||
|
stream.pipe(fse.createWriteStream(zipfilex));
|
||||||
|
});
|
||||||
|
//console.log(entry.fileName)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
const name: string = entry.fileName;
|
const name: string = entry.fileName;
|
||||||
dud_files.push(name);
|
dud_files.push(name);
|
||||||
@@ -80,36 +85,45 @@ async function main(modpack_path: string) {
|
|||||||
});
|
});
|
||||||
zipfile.on("end", async () => {
|
zipfile.on("end", async () => {
|
||||||
//zip
|
//zip
|
||||||
const dirx = join(unzip_path,zipname)
|
const dirx = join(unzip_path, zipname);
|
||||||
const plat = platform(what_platform(dud_files))
|
const plat = platform(what_platform(dud_files));
|
||||||
const info = await plat.getinfo(pack_info);
|
const info = await plat.getinfo(pack_info);
|
||||||
await plat.downloadfile(pack_info,dirx)
|
await plat.downloadfile(pack_info, dirx);
|
||||||
await DeEarthMain(join(dirx,"mods"),join(unzip_path,"rubbish"))
|
await DeEarthMain(join(dirx, "mods"), join(unzip_path, "rubbish"));
|
||||||
await install(info.loader,info.minecraft,info.loader_version,dirx)
|
await install(info.loader, info.minecraft, info.loader_version, dirx);
|
||||||
|
fs.writeFileSync(
|
||||||
|
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"
|
||||||
|
);
|
||||||
LOGGER.info("DeEarthX已将服务端制作完成!");
|
LOGGER.info("DeEarthX已将服务端制作完成!");
|
||||||
zipfile.close();
|
zipfile.close();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function install(type: string,minecraft:string,loaderver:string,path:string){
|
async function install(
|
||||||
switch(type){
|
type: string,
|
||||||
case "fabric":
|
minecraft: string,
|
||||||
await fabric(minecraft,loaderver,path)
|
loaderver: string,
|
||||||
break;
|
path: string
|
||||||
case "fabric-loader":
|
) {
|
||||||
await fabric(minecraft,loaderver,path)
|
switch (type) {
|
||||||
break;
|
case "fabric":
|
||||||
case "forge":
|
await fabric(minecraft, loaderver, path);
|
||||||
await forge(minecraft,loaderver,path)
|
break;
|
||||||
break;
|
case "fabric-loader":
|
||||||
case "neoforge":
|
await fabric(minecraft, loaderver, path);
|
||||||
await neoforge(minecraft,loaderver,path)
|
break;
|
||||||
break;
|
case "forge":
|
||||||
}
|
await forge(minecraft, loaderver, path);
|
||||||
|
break;
|
||||||
|
case "neoforge":
|
||||||
|
await neoforge(minecraft, loaderver, path);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCurrnetDir () {
|
function getCurrnetDir() {
|
||||||
const url = new URL(".", import.meta.url);
|
const url = new URL(".", import.meta.url);
|
||||||
return fileURLToPath(url);
|
return fileURLToPath(url);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user