mirror of
https://github.com/noothenoot/crafty-mod-installer.git
synced 2026-07-21 21:37:00 +00:00
fixed curseforge problems
This commit is contained in:
+56
-24
@@ -47,40 +47,72 @@ class CurseForgeHandler {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async installModpack(modId, fileId, targetDir) {
|
async installMod(modId, fileId, targetDir) {
|
||||||
console.log(`Downloading CurseForge pack (Mod: ${modId}, File: ${fileId})...`);
|
console.log(`Downloading CurseForge file (Mod: ${modId}, File: ${fileId})...`);
|
||||||
|
|
||||||
const file = await this.client.getModFile(modId, fileId);
|
const file = await this.client.getModFile(modId, fileId);
|
||||||
if (!file.downloadUrl) throw new Error('Download URL not found for this file.');
|
if (!file.downloadUrl) throw new Error('Download URL not found for this file.');
|
||||||
|
|
||||||
const tempPath = path.join(process.cwd(), 'temp_pack.zip');
|
const fileName = file.fileName;
|
||||||
|
const tempPath = path.join(process.cwd(), fileName);
|
||||||
await this.downloadFile(file.downloadUrl, tempPath);
|
await this.downloadFile(file.downloadUrl, tempPath);
|
||||||
|
|
||||||
const zip = new AdmZip(tempPath);
|
// If it's a jar, move it to mods
|
||||||
const manifestEntry = zip.getEntry('manifest.json');
|
if (fileName.endsWith('.jar')) {
|
||||||
if (!manifestEntry) throw new Error('Invalid CurseForge pack: missing manifest.json');
|
const modsDir = path.join(targetDir, 'mods');
|
||||||
|
await fs.ensureDir(modsDir);
|
||||||
const manifest = JSON.parse(zip.readAsText(manifestEntry));
|
await fs.move(tempPath, path.join(modsDir, fileName), { overwrite: true });
|
||||||
const modsDir = path.join(targetDir, 'mods');
|
console.log('✅ Mod installation complete!');
|
||||||
await fs.ensureDir(modsDir);
|
return;
|
||||||
|
|
||||||
console.log(`Downloading ${manifest.files.length} mods from CurseForge...`);
|
|
||||||
for (const fileInfo of manifest.files) {
|
|
||||||
const modFile = await this.client.getModFile(fileInfo.projectID, fileInfo.fileID);
|
|
||||||
const destPath = path.join(modsDir, modFile.fileName);
|
|
||||||
console.log(` Downloading ${modFile.fileName}...`);
|
|
||||||
await this.downloadFile(modFile.downloadUrl, destPath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle overrides
|
// If it's a zip, check if it's a modpack
|
||||||
const overridesEntry = zip.getEntry('overrides/');
|
if (fileName.endsWith('.zip')) {
|
||||||
if (overridesEntry) {
|
const zip = new AdmZip(tempPath);
|
||||||
console.log('Applying overrides...');
|
const manifestEntry = zip.getEntry('manifest.json');
|
||||||
zip.extractAllTo(targetDir, true);
|
|
||||||
|
if (manifestEntry) {
|
||||||
|
console.log('Detected CurseForge Modpack. Installing...');
|
||||||
|
const manifest = JSON.parse(zip.readAsText(manifestEntry));
|
||||||
|
const modsDir = path.join(targetDir, 'mods');
|
||||||
|
await fs.ensureDir(modsDir);
|
||||||
|
|
||||||
|
console.log(`Downloading ${manifest.files.length} mods from CurseForge...`);
|
||||||
|
for (const fileInfo of manifest.files) {
|
||||||
|
const modFile = await this.client.getModFile(fileInfo.projectID, fileInfo.fileID);
|
||||||
|
const destPath = path.join(modsDir, modFile.fileName);
|
||||||
|
console.log(` Downloading ${modFile.fileName}...`);
|
||||||
|
await this.downloadFile(modFile.downloadUrl, destPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle overrides
|
||||||
|
const overridesDir = 'overrides';
|
||||||
|
const zipEntries = zip.getEntries();
|
||||||
|
zipEntries.forEach(entry => {
|
||||||
|
if (entry.entryName.startsWith(overridesDir + '/')) {
|
||||||
|
const relativePath = entry.entryName.substring(overridesDir.length + 1);
|
||||||
|
if (relativePath) {
|
||||||
|
const dest = path.join(targetDir, relativePath);
|
||||||
|
if (entry.isDirectory) {
|
||||||
|
fs.ensureDirSync(dest);
|
||||||
|
} else {
|
||||||
|
fs.ensureDirSync(path.dirname(dest));
|
||||||
|
fs.writeFileSync(dest, entry.getData());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
console.log('✅ Modpack installation complete!');
|
||||||
|
} else {
|
||||||
|
// Just a zipped mod? (rare but possible)
|
||||||
|
const modsDir = path.join(targetDir, 'mods');
|
||||||
|
await fs.ensureDir(modsDir);
|
||||||
|
await fs.move(tempPath, path.join(modsDir, fileName), { overwrite: true });
|
||||||
|
console.log('✅ Zipped mod installed to mods folder.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await fs.remove(tempPath);
|
if (await fs.pathExists(tempPath)) await fs.remove(tempPath);
|
||||||
console.log('CurseForge installation complete!');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user