From ba8c21cd6c635fb39a7fa4b9b85a8b793edc5a10 Mon Sep 17 00:00:00 2001 From: Tianpao Date: Thu, 3 Jul 2025 12:29:09 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E6=9C=80=E7=BB=88=E6=88=90?= =?UTF-8?q?=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dex.ico | Bin 0 -> 6298 bytes package.json | 4 +-- src/main.ts | 9 ++--- src/ml_install/forge.ts | 1 - src/platform/curseforge.ts | 69 +++++++++++++++++++++++-------------- src/platform/index.ts | 2 ++ src/platform/mcbbs.ts | 7 ++-- src/platform/modrinth.ts | 6 ++-- src/utils/utils.ts | 4 +-- 9 files changed, 61 insertions(+), 41 deletions(-) create mode 100644 Dex.ico diff --git a/Dex.ico b/Dex.ico new file mode 100644 index 0000000000000000000000000000000000000000..80ec017d37db3bcca9e37cc78cbbca44ae0056ca GIT binary patch literal 6298 zcmV;L7-i>)P)Py2R7pfZRCr$PU3Xwq)zbgn-A#cclmMxe&_RlH2pt4OiU=qukboitL=he!yeFbG z<)bM|i#`=W5Kwv(A5B{5O%O;TEsy{Sq;2Y!`(^IdY&OZ3d+#p0%s-Ii)S2I%bIzPO zGYp=STXTSM>)Ah_Je~u<%|YPq09X!S6aZg$#eus6fYl1#ZTaA~6W0n}2LJ^CPj}P; z?hJr@03Jp{cS~Nl<)n?j{sCiv9p7=kc@@Aechdsy3V{9qcGh_j_}4Pvy{>w(yB$B= zZo*no=K%1YyAkLy6bLtP!R`3rb`v&M|1sJv;GQ+Wytlc(j0K=s5Zr{^5dbX!oG1C} z0H9U@9b}xu4*__|O=Qna(;Wfu1Aw=Wel~`{eeY0iz<4p7DxwB!CjUCcLP8gfbynazfRchxD2=(0L-d?9RT+H2+Vtj z`>6+jgYKXO+z9}*yFW1V2cWO!$Y++^O$)da080G&-E|pw4geE9aB?p&r7!o(6#(9M z^<}_a0MLz$JOjr8AFV1`r1`l(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d&8*kMFs&%qQaCv~CP>of({Q7&;C$p`?Hc|?<(USJZNd3FJyOBsM- z=W2t+%9^{Eg;0oI34R3 z0n0xsG;<2zCrHkAJNc`>Q>YRO?9`{)vbvKgAAM z3jp$#5%xqlcER2O_P<`^@;2TWa!~C zjZR+;yk-)E%;f-Jy#6nm0BofPVH%QCUyJkH?%0iEIq&_&+# Q;s5{u07*qoM6N<$f>#pT2LJ#7 literal 0 HcmV?d00001 diff --git a/package.json b/package.json index 5b05136..667e925 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,8 @@ "scripts": { "tsbuild": "tsc", "rollup": "rollup -c rollup.config.js", - "nexe": "nexe -i ./ndist/main.js --ico Dex.ico --build -t x86-22.13.0 --output ./ndist/main.exe", - "upx": ".\\.dist_modules\\upx.exe .\\ndist\\main.exe", + "nexe": "nexe -i ./ndist/bundle.js --ico Dex.ico --build -t x86-22.13.0 --output ./ndist/DeEarthX.exe", + "upx": ".\\dist_modules\\upx.exe .\\ndist\\DeEarthX.exe", "build": "npm run tsbuild&&npm run rollup&&npm run nexe&&npm run upx", "test": "tsc&&node dist/main.js" }, diff --git a/src/main.ts b/src/main.ts index 3658dab..e435f5e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -16,9 +16,9 @@ interface Answers { } let unzip_path:string = "" if(isDevelopment){ - unzip_path = join("./","instance") + unzip_path = join("./","instance/") }else{ - unzip_path = join(getCurrnetDir(),"instance") + unzip_path = join(getCurrnetDir().replace("ndist",""),"instance") } let zipnamew: string = "" const argv = process.argv.slice(2)[0]; @@ -60,6 +60,7 @@ async function main(modpack_path: string) { zipfile.openReadStream(entry,(err,stream)=>{ //读取overrides文件夹下的所有文件和文件夹 const dir = dirname(zipfilex) fse.ensureDirSync(dir); + console.log(zipfilex) stream.pipe(fse.createWriteStream(zipfilex)) }) //console.log(entry.fileName) @@ -67,7 +68,7 @@ async function main(modpack_path: string) { } else { const name: string = entry.fileName; dud_files.push(name); - if (name && name.endsWith(".json")) { + if (name.endsWith(".json")) { pack_info = JSON.parse( (await readzipentry(zipfile, entry)).toString() ); @@ -81,8 +82,8 @@ 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 install(info.loader,info.minecraft,info.loader_version,dirx) await DeEarthMain(join(dirx,"mods"),join(unzip_path,"rubbish")) + await install(info.loader,info.minecraft,info.loader_version,dirx) LOGGER.info("DeEarthX已将服务端制作完成!"); zipfile.close(); }); diff --git a/src/ml_install/forge.ts b/src/ml_install/forge.ts index c221a15..3f84c38 100644 --- a/src/ml_install/forge.ts +++ b/src/ml_install/forge.ts @@ -27,7 +27,6 @@ export default async function install( .get(`version/${minecraftversion}/json`) .json()) as mcinfoX; //获取Minecraft版本JSON const forgepath = path; - console.log(loaderversion) const forgedata = ( await gotx.get( `forge/download?mcversion=${minecraftversion}&version=${loaderversion}&category=installer&format=jar` diff --git a/src/platform/curseforge.ts b/src/platform/curseforge.ts index 29caaa7..04dd47e 100644 --- a/src/platform/curseforge.ts +++ b/src/platform/curseforge.ts @@ -1,8 +1,15 @@ import got from "got"; +import { join } from "node:path"; import { fastdownload, usemirror } from "../utils/utils.js"; import { modpack_info, XPlatform } from "./index.js"; -const cf_url = (()=>{if(usemirror){return "https://mod.mcimirror.top/curseforge"}else{return "https://api.curseforge.com"}})() +const cf_url = (() => { + if (usemirror) { + return "https://mod.mcimirror.top/curseforge"; + } else { + return "https://api.curseforge.com"; + } +})(); export interface CurseForgeManifest { minecraft: { version: string; @@ -17,39 +24,49 @@ export class CurseForge implements XPlatform { const local_manifest = manifest as CurseForgeManifest; if (result && local_manifest) result.minecraft = local_manifest.minecraft.version; - const id = local_manifest.minecraft.modLoaders[0].id; - const loader_all = id.match( - /(.*)-/ - ) as RegExpMatchArray; + const id = local_manifest.minecraft.modLoaders[0].id; + const loader_all = id.match(/(.*)-/) as RegExpMatchArray; result.loader = loader_all[1]; - result.loader_version = id.replace(loader_all[0],""); + result.loader_version = id.replace(loader_all[0], ""); return result; } - async downloadfile(manifest: object,path:string): Promise { + async downloadfile(manifest: object, path: string): Promise { const local_manifest = manifest as CurseForgeManifest; const FileID = JSON.stringify({ - fileIds: local_manifest.files.map((file: { fileID: number; }) => file.fileID), - }); + fileIds: local_manifest.files.map( + (file: { fileID: number }) => file.fileID + ), + }); let tmp: [string, string] | string[][] = []; - await got.post(cf_url+"/v1/mods/files",{ + await got + .post(cf_url + "/v1/mods/files", { body: FileID, headers: { - "Content-Type": "application/json", - "x-api-key":"$2a$10$ydk0TLDG/Gc6uPMdz7mad.iisj2TaMDytVcIW4gcVP231VKngLBKy" - } - }).json().then((res:any)=>{ - res.data.forEach((e: { fileName: string; downloadUrl: null|string; }) => { - if (e.fileName.endsWith(".zip")||e.downloadUrl == null) { - return; - } - if (usemirror){ - tmp.push(["https://mod.mcimirror.top"+new URL(e.downloadUrl).pathname,path+"/mods/" + e.fileName]) - }else{ - tmp.push([e.downloadUrl,path+"/mods/" + e.fileName]) - } - }); - }) - await fastdownload(tmp as unknown as [string, string]) //下载文件 + "Content-Type": "application/json", + "x-api-key": + "$2a$10$ydk0TLDG/Gc6uPMdz7mad.iisj2TaMDytVcIW4gcVP231VKngLBKy", + }, + }) + .json() + .then((res: any) => { + res.data.forEach( + (e: { fileName: string; downloadUrl: null | string }) => { + if (e.fileName.endsWith(".zip") || e.downloadUrl == null) { + return; + } + const unpath = join(path + "/mods/", e.fileName); + if (usemirror) { + tmp.push([ + "https://mod.mcimirror.top" + new URL(e.downloadUrl).pathname, + unpath, + ]); + } else { + tmp.push([e.downloadUrl, unpath]); + } + } + ); + }); + await fastdownload(tmp as unknown as [string, string]); //下载文件 } } diff --git a/src/platform/index.ts b/src/platform/index.ts index 54755f5..6e0a6d6 100644 --- a/src/platform/index.ts +++ b/src/platform/index.ts @@ -21,8 +21,10 @@ export function platform(plat: string | undefined): XPlatform { break; case "modrinth": platform = new Modrinth(); + break; case "mcbbs": platform = new MCBBS(); + break; } return platform; } diff --git a/src/platform/mcbbs.ts b/src/platform/mcbbs.ts index 2039d95..cb58a2a 100644 --- a/src/platform/mcbbs.ts +++ b/src/platform/mcbbs.ts @@ -9,11 +9,10 @@ export class MCBBS implements XPlatform { const local_manifest = manifest as MCBBSManifest; if (result && local_manifest) result.minecraft = local_manifest.minecraft.version; - const loader_all = local_manifest.minecraft.modLoaders[0].id.match( - /(.*)-/ - ) as RegExpMatchArray; + const id = local_manifest.minecraft.modLoaders[0].id; + const loader_all = id.match(/(.*)-/) as RegExpMatchArray; result.loader = loader_all[1]; - result.loader_version = loader_all[0]; + result.loader_version = id.replace(loader_all[0], ""); return result; } diff --git a/src/platform/modrinth.ts b/src/platform/modrinth.ts index 703dbb7..a8d8d7f 100644 --- a/src/platform/modrinth.ts +++ b/src/platform/modrinth.ts @@ -1,6 +1,7 @@ import fs from "node:fs"; import { mr_fastdownload, usemirror } from "../utils/utils.js"; import { modpack_info, XPlatform } from "./index.js"; +import { join } from "node:path"; interface ModrinthManifest { files: Array<{ path: string; downloads: string[]; fileSize: number; }>; @@ -36,10 +37,11 @@ export class Modrinth implements XPlatform { if (e.path.endsWith(".zip")) { return; } + const unpath = join(path,e.path) if (usemirror){ - tmp.push(["https://mod.mcimirror.top"+new URL(e.downloads[0]).pathname,path+e.path,String(e.fileSize)]) + tmp.push(["https://mod.mcimirror.top"+new URL(e.downloads[0]).pathname,unpath,String(e.fileSize)]) }else{ - tmp.push([e.downloads[0],path + e.path,String(e.fileSize)]) + tmp.push([e.downloads[0],unpath,String(e.fileSize)]) } }); await mr_fastdownload(tmp as unknown as [string, string, string]) diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 1ba3a2f..d9b2ec7 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -29,7 +29,7 @@ export async function fastdownload(data:[string,string]){ }) const totalBar = multibar.create(data.length, 0, {filename: '总文件数'}) return await pMap(data,async(e)=>{ - const size:number = await (async()=>{const head = (await got.head(e[0])).headers['content-length'];if(head){return Number(head)}else{return 0}})() + const size:number = await (async()=>{const head = (await got.head(e[0].replace("https://mod.mcimirror.top","https://edge.forgecdn.net"))).headers['content-length'];if(head){return Number(head)}else{return 0}})() const bar = multibar.create(size, 0, {filename: e[1]}) try{ await pRetry(async()=>{ @@ -124,7 +124,7 @@ export async function xfastdownload( } export const usemirror = (()=>{ - env.config() + env.config({debug:false}) const mirror = process.env.MIRROR if(mirror){ return false