Skip to content

Commit

Permalink
Try/catch mod update
Browse files Browse the repository at this point in the history
could fail over network issues or other tmp things
  • Loading branch information
mayfield committed Apr 11, 2024
1 parent 1400d0d commit 426b2dc
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/mods.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ function _initUnpacked(root) {
const settings = modsSettings[id] = (modsSettings[id] || {});
const enabled = !isNew && !!settings.enabled;
const label = `${manifest.name} (${id})`;
console.info(`Detected unpacked MOD: ${label} [${enabled ? 'ENABLED' : 'DISABLED'}]`);
console.info(`Detected unpacked MOD: ${label} ${!enabled ? '[DISABLED]' : ''}`);
if (isNew || enabled) {
validateManifest(manifest, modPath, label);
}
Expand Down Expand Up @@ -278,16 +278,19 @@ async function _initPacked(root) {
try {
const zipFile = path.join(packedModRoot, entry.file);
let mod = await openPackedMod(zipFile, id);
const latestRelease = await getLatestPackedModRelease(id);
if (latestRelease && latestRelease.hash !== mod.hash) {
console.warn('Updating packed Mod:', mod.manifest.name);
debugger;
const oldZip = mod.zip;
mod = await installPackedModRelease(id, latestRelease);
oldZip.close();
fsRemoveFile(zipFile);
console.info(`Detected packed MOD: ${mod.manifest.name} - v${mod.manifest.version}`);
try {
const latestRelease = await getLatestPackedModRelease(id);
if (latestRelease && latestRelease.hash !== mod.hash) {
console.warn('Updating packed Mod:', mod.manifest.name, '->', latestRelease.version);
const oldZip = mod.zip;
mod = await installPackedModRelease(id, latestRelease);
oldZip.close();
fsRemoveFile(zipFile);
}
} catch(e) {
console.warn("Failed to check/update Mod:", e);
}
console.info(`Detected packed MOD: ${mod.manifest.name} - v${mod.manifest.version} [ENABLED]`);
validMods.push(mod);
} catch(e) {
if (e instanceof ValidationError) {
Expand Down

0 comments on commit 426b2dc

Please sign in to comment.