fixed curse dep counter

This commit is contained in:
2021-01-21 17:07:21 +01:00
parent 0b4b9a6e77
commit 68b9f56abd

View File

@ -12,10 +12,9 @@ function main() {
}); });
}); });
var resolveDepRecursionCount = []; var resolveDepRecursionCount = 0;
function resolveDep(modId, callback, index) { function resolveDep(modId, callback) {
if(index === undefined) index = resolveDepRecursionCount.push(0) - 1; ++resolveDepRecursionCount;
++resolveDepRecursionCount[index];
getData(`${modId}/files`, (files) => { getData(`${modId}/files`, (files) => {
let rightVersion; let rightVersion;
for(let i = files.length - 1; i >= 0; --i) { for(let i = files.length - 1; i >= 0; --i) {
@ -27,10 +26,10 @@ function main() {
dep.set(String(modId), {fileId: rightVersion.id, url: rightVersion.downloadUrl, filename: rightVersion.fileName}); dep.set(String(modId), {fileId: rightVersion.id, url: rightVersion.downloadUrl, filename: rightVersion.fileName});
rightVersion.dependencies.forEach(mod => { rightVersion.dependencies.forEach(mod => {
if(mod.type !== 3) return if(mod.type !== 3) return
resolveDep(mod.addonId, callback, index); resolveDep(mod.addonId, callback);
}); });
--resolveDepRecursionCount[index]; --resolveDepRecursionCount;
if(resolveDepRecursionCount[index] == 0) callback(); if(resolveDepRecursionCount == 0) callback();
}); });
} }
@ -66,12 +65,12 @@ function main() {
downloadStarted = true; downloadStarted = true;
globCallback("curse", Object.fromEntries(dep)); globCallback("curse", Object.fromEntries(dep));
dep.forEach((mod, modId) => { dep.forEach((mod, modId) => {
let path = getPath(mod) let path = getPath(mod)
if(mods_lock.has(modId)) { if(mods_lock.has(modId)) {
if(mods_lock.get(modId).fileId === mod.fileId) return; if(mods_lock.get(modId).fileId === mod.fileId) return;
fs.unlink(path, () => {}); fs.unlink(path, () => {});
} }
downloadFile(mod.url, path); downloadFile(mod.url, path);
}); });
mods_lock.forEach((mod, modId) => { mods_lock.forEach((mod, modId) => {
if(!dep.has(modId)) fs.unlink(getPath(mod), () => {}) if(!dep.has(modId)) fs.unlink(getPath(mod), () => {})