MCPcopy Create free account
hub / github.com/MCSManager/MCSManager / parseJarMetadata

Method parseJarMetadata

daemon/src/service/mod_service.ts:69–182  ·  view source on GitHub ↗
(jarPath: string)

Source from the content-addressed store, hash-verified

67 }
68
69 private async parseJarMetadata(jarPath: string): Promise<Partial<ModInfo> | null> {
70 const zip = new StreamZip.async({ file: jarPath });
71 try {
72 const entries = await zip.entries();
73
74 // Fabric
75 if (entries["fabric.mod.json"]) {
76 const data = await zip.entryData("fabric.mod.json");
77 const json = JSON.parse(data.toString());
78 return {
79 id: json.id,
80 name: json.name || json.id,
81 version: json.version,
82 description: json.description,
83 type: "mod"
84 };
85 }
86
87 // Forge (mods.toml) / NeoForge (neoforge.mods.toml)
88 const TOML_FILES = ["META-INF/mods.toml","META-INF/neoforge.mods.toml"];
89 for (const filePath of TOML_FILES) {
90 if (!entries[filePath]) continue;
91 const data = await zip.entryData(filePath);
92 const config = toml.parse(data.toString()) as any;
93 const mod = config.mods?.[0] || {};
94 // Handle placeholder logic
95 let version = mod.version;
96 if (version === "${file.jarVersion}") {
97 version = await this.getVersionFromManifest(zip, entries) || version;
98 }
99 return {
100 id: mod.modId,
101 name: mod.displayName || mod.modId,
102 version: version,
103 description: mod.description,
104 type: "mod"
105 };
106 }
107
108 // Forge (mcmod.info)
109 if (entries["mcmod.info"]) {
110 const data = await zip.entryData("mcmod.info");
111 try {
112 const json = JSON.parse(data.toString());
113 const mod = Array.isArray(json) ? json[0] : json.modList ? json.modList[0] : json;
114 return {
115 id: mod.modid,
116 name: mod.name || mod.modid,
117 version: mod.version,
118 description: mod.description,
119 type: "mod"
120 };
121 } catch (e) { }
122 }
123
124 // Quilt
125 if (entries["quilt.mod.json"]) {
126 const data = await zip.entryData("quilt.mod.json");

Callers 1

scanDirMethod · 0.95

Calls 1

Tested by

no test coverage detected