From 15bad24e69e217f1a25bb2809d31910f9ebec01c Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Sat, 17 Feb 2024 23:58:46 +0100 Subject: [PATCH 1/2] Fix mod extraction not finished when game launch sometime --- src/server/minecraft.js | 66 +++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/src/server/minecraft.js b/src/server/minecraft.js index d33b206..2766a73 100644 --- a/src/server/minecraft.js +++ b/src/server/minecraft.js @@ -189,42 +189,50 @@ export default class Minecraft { // const shaderFolder = join(this.minecraftpath, 'shaderpacks') if (fs.existsSync(modsFolder)) { fs.rmSync(modsFolder, { recursive: true }) } // if (fs.existsSync(shaderFolder)) { fs.rmSync(shaderFolder, { recursive: true }) } + let chapterFound = false for (const i in this.modsList) { if (Number(i) === chapterId) { + chapterFound = true const chapter = this.modsList[i] + const modsList = [] for (const j in chapter.modspack.mods) { - event.sender.send('progress', { type: 'mods', task: 0, total: chapter.modspack.mods.length }) - const modpackFolder = join(this.minecraftpath, 'modpack', chapter.title) - if (!fs.existsSync(modpackFolder)) { fs.mkdirSync(modpackFolder, { recursive: true }) } - const path = join(modpackFolder, `modpack${j}.zip`) - try { - fs.accessSync(path, fs.W_OK) - hashFile(path, { algorithm: 'sha1' }).then(sha1 => { - if (sha1 === chapter.modspack.sha1sum[j]) { - this.unzipMods(path).catch(err => { - reject(err) - }) - } else { - logger.warn(`sha1sum ${sha1} don't correspond to ${chapter.modspack.sha1sum[j]} of mods ${path}`) - this.downloadAndExtractMods(chapter.modspack.mods[j], path).catch(err => { - reject(err) - }) - } - }).catch(err => { - reject(new Error('Can obtain md5 hash of file ' + path + ': ' + err)) - }) - event.sender.send('progress', { type: 'mods', task: Number(j) + 1, total: chapter.modspack.mods.length }) - } catch (err) { - this.downloadAndExtractMods(chapter.modspack.mods[j], path).catch(err => { - reject(err) - }) - } + modsList.push(new Promise((resolve, reject) => { + event.sender.send('progress', { type: 'mods', task: 0, total: chapter.modspack.mods.length }) + const modpackFolder = join(this.minecraftpath, 'modpack', chapter.title) + if (!fs.existsSync(modpackFolder)) { fs.mkdirSync(modpackFolder, { recursive: true }) } + const path = join(modpackFolder, `modpack${j}.zip`) + try { + fs.accessSync(path, fs.W_OK) + hashFile(path, { algorithm: 'sha1' }).then(sha1 => { + if (sha1 === chapter.modspack.sha1sum[j]) { + this.unzipMods(path) + .then(() => resolve()) + .catch(err => reject(err)) + } else { + logger.warn(`sha1sum ${sha1} don't correspond to ${chapter.modspack.sha1sum[j]} of mods ${path}`) + this.downloadAndExtractMods(chapter.modspack.mods[j], path).then(() => resolve()).catch(err => reject(err)) + } + }).catch(err => { + reject(new Error('Can obtain md5 hash of file ' + path + ': ' + err)) + }) + event.sender.send('progress', { type: 'mods', task: Number(j) + 1, total: chapter.modspack.mods.length }) + } catch (err) { + this.downloadAndExtractMods(chapter.modspack.mods[j], path).then(() => resolve()).catch(err => { + reject(err) + }) + } + })) } - resolve(chapter) - return + Promise.all(modsList).then(() => { + resolve(chapter) + }).catch(err => { + reject(err) + }) } } - reject(new Error("didn't found the correct chapter" + chapterId)) + if (chapterFound === false) { + reject(new Error("didn't found the correct chapter" + chapterId)) + } }) } From 72d18c2205e51a02843642c884f658ca226ebb57 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Sun, 18 Feb 2024 00:00:36 +0100 Subject: [PATCH 2/2] Dump to 2.1.6 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 213dfa9..74ec03d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "altarik-launcher", "author": "Altarik", - "version": "2.1.5", + "version": "2.1.6", "description": "Altarik Launcher", "main": "src/server/main.js", "type": "module",