feat:fabric启动脚本,垃圾回收,rubbish改名 fix:json解析失败崩溃
This commit is contained in:
28
src/main.ts
28
src/main.ts
@@ -5,7 +5,7 @@ import fs from "node:fs";
|
||||
import fse from "fs-extra";
|
||||
import { join, basename, dirname } from "node:path";
|
||||
import { platform, what_platform } from "./platform/index.js";
|
||||
import { isDevelopment, isInstallJava, readzipentry } from "./utils/utils.js";
|
||||
import { type ForgeInfo, isDevelopment, isInstallJava, readzipentry } from "./utils/utils.js";
|
||||
import fabric from "./ml_install/fabric.js";
|
||||
import forge from "./ml_install/forge.js";
|
||||
import neoforge from "./ml_install/neoforge.js";
|
||||
@@ -39,7 +39,7 @@ if (!argv) {
|
||||
|
||||
function initdir() {
|
||||
if (!fs.existsSync(unzip_path)) {
|
||||
fse.ensureDirSync(join(unzip_path, "rubbish"));
|
||||
fse.ensureDirSync(join(unzip_path, ".rubbish"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,12 +88,13 @@ async function main(modpack_path: string) {
|
||||
const plat = platform(what_platform(dud_files));
|
||||
const info = await plat.getinfo(pack_info);
|
||||
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);
|
||||
fs.writeFileSync(
|
||||
join(dirx, "eula.txt"),
|
||||
"#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"
|
||||
);
|
||||
await garcol(dirx,{minecraft_verison: info.minecraft, forge_verison: info.loader_version}).catch((e)=>{});
|
||||
LOGGER.info("DeEarthX已将服务端制作完成!");
|
||||
zipfile.close();
|
||||
});
|
||||
@@ -116,6 +117,9 @@ async function install(
|
||||
break;
|
||||
case "fabric-loader":
|
||||
await fabric(minecraft, loaderver, path);
|
||||
const com = "java -jar fabric-server-launch.jar"
|
||||
fs.writeFileSync(join(path,'run.bat'),com)
|
||||
fs.writeFileSync(join(path,'run.sh'),com)
|
||||
break;
|
||||
case "forge":
|
||||
await forge(minecraft, loaderver, path);
|
||||
@@ -126,6 +130,24 @@ async function install(
|
||||
}
|
||||
}
|
||||
|
||||
async function garcol(p:string,fi:ForgeInfo): Promise<void> {
|
||||
return new Promise((resolve,reject)=>{
|
||||
try{
|
||||
LOGGER.info("正在删除垃圾文件......")
|
||||
const x = [`Forge-${fi.minecraft_verison}-${fi.forge_verison}.jar`,`installer.log`,`installer.jar`,`fabric-installer-1.0.3.jar`,`options.txt`,`shaderpacks/`,`resourcepacks/`]
|
||||
for (let i=0;i<x.length;i++){
|
||||
try{
|
||||
fs.rmSync(join(p, x[i]),{recursive: true, force: true})
|
||||
}catch(e){}
|
||||
}
|
||||
resolve()
|
||||
}catch(err){
|
||||
reject(err)
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
function getCurrnetDir() {
|
||||
const url = new URL(".", import.meta.url);
|
||||
return fileURLToPath(url);
|
||||
|
||||
@@ -12,9 +12,9 @@ export default async function install(
|
||||
`https://maven.fabricmc.net/net/fabricmc/fabric-installer/1.0.3/fabric-installer-1.0.3.jar`
|
||||
)
|
||||
).rawBody;
|
||||
fsExtra.outputFileSync(path+"/fabric-installer-1.0.1.jar", data);
|
||||
fsExtra.outputFileSync(path+"/fabric-installer-1.0.3.jar", data);
|
||||
cp.execSync(
|
||||
`java -jar fabric-installer-1.0.1.jar server -mcver ${mcver} -loader ${fabricver}`,
|
||||
`java -jar fabric-installer-1.0.3.jar server -mcver ${mcver} -loader ${fabricver}`,
|
||||
{ cwd: path, stdio: "ignore" }
|
||||
);
|
||||
}
|
||||
@@ -19,7 +19,7 @@ export async function DeEarthMain(modspath: string, movepath: any) {
|
||||
}
|
||||
LOGGER.info(`DeEarth V1.0.0`)
|
||||
LOGGER.info(`如有无法筛选的mods,请前往 https://dearth.0771010.xyz/ 提交未成功筛选的模组的modid`)
|
||||
LOGGER.info(`Probejs 7.0.0以上版本为非客户端mod,如rubbish中有请自行添加回去`)
|
||||
LOGGER.info(`Probejs 7.0.0以上版本为非客户端mod,如.rubbish中有请自行添加回去`)
|
||||
const resaddr = fs.readdirSync(modspath)
|
||||
LOGGER.info(`获取目录列表,一共${resaddr.length}个jar文件。`)
|
||||
const totalBar = multibar.create(resaddr.length, 0, { filename: '总文件数' })
|
||||
@@ -138,6 +138,7 @@ export async function DeEarth(modpath: string, movepath: string) {
|
||||
export async function DeEarth(modpath: string, movepath: string) {
|
||||
const zipinfo = ZipInfo(modpath)
|
||||
let modid:string = ""
|
||||
if(zipinfo){
|
||||
if(zipinfo.modinfo.type === "forge"){
|
||||
modid = zipinfo.modinfo.data.mods[0].modId
|
||||
}else if(zipinfo.modinfo.type === "fabric"){
|
||||
@@ -192,6 +193,7 @@ export async function DeEarth(modpath: string, movepath: string) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function ZipInfo(modpath: string) {
|
||||
@@ -199,6 +201,7 @@ function ZipInfo(modpath: string) {
|
||||
mixins: { filename: string, info: string }[]
|
||||
modinfo: {type:string,data:any};
|
||||
}
|
||||
try{
|
||||
let zipinfo: ZipInfo = { mixins: [], modinfo: {type: "",data: {}} }
|
||||
const zip = new AdmZip(modpath).getEntries();
|
||||
for (let i = 0; i < zip.length; i++) {
|
||||
@@ -214,6 +217,9 @@ function ZipInfo(modpath: string) {
|
||||
}
|
||||
}
|
||||
return zipinfo;
|
||||
}catch(error){
|
||||
LOGGER.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
async function FastGot(url: string) {
|
||||
|
||||
@@ -10,6 +10,11 @@ import { URL, fileURLToPath } from "node:url";
|
||||
import { LOGGER } from "./logger.js";
|
||||
import { exec } from "node:child_process";
|
||||
|
||||
export interface ForgeInfo{
|
||||
minecraft_verison: string,
|
||||
forge_verison: string
|
||||
}
|
||||
|
||||
export async function readzipentry(
|
||||
zipfile: yauzl.ZipFile,
|
||||
entry: yauzl.Entry
|
||||
|
||||
Reference in New Issue
Block a user