4
0
mirror of https://github.com/AltarikMC/Launcher synced 2024-11-21 06:09:51 +01:00

Fix mod extraction not finished when game launch sometime

This commit is contained in:
Quentin Legot 2024-02-17 23:58:46 +01:00
parent caa50855cf
commit 15bad24e69

View File

@ -189,42 +189,50 @@ export default class Minecraft {
// const shaderFolder = join(this.minecraftpath, 'shaderpacks') // const shaderFolder = join(this.minecraftpath, 'shaderpacks')
if (fs.existsSync(modsFolder)) { fs.rmSync(modsFolder, { recursive: true }) } if (fs.existsSync(modsFolder)) { fs.rmSync(modsFolder, { recursive: true }) }
// if (fs.existsSync(shaderFolder)) { fs.rmSync(shaderFolder, { recursive: true }) } // if (fs.existsSync(shaderFolder)) { fs.rmSync(shaderFolder, { recursive: true }) }
let chapterFound = false
for (const i in this.modsList) { for (const i in this.modsList) {
if (Number(i) === chapterId) { if (Number(i) === chapterId) {
chapterFound = true
const chapter = this.modsList[i] const chapter = this.modsList[i]
const modsList = []
for (const j in chapter.modspack.mods) { for (const j in chapter.modspack.mods) {
event.sender.send('progress', { type: 'mods', task: 0, total: chapter.modspack.mods.length }) modsList.push(new Promise((resolve, reject) => {
const modpackFolder = join(this.minecraftpath, 'modpack', chapter.title) event.sender.send('progress', { type: 'mods', task: 0, total: chapter.modspack.mods.length })
if (!fs.existsSync(modpackFolder)) { fs.mkdirSync(modpackFolder, { recursive: true }) } const modpackFolder = join(this.minecraftpath, 'modpack', chapter.title)
const path = join(modpackFolder, `modpack${j}.zip`) if (!fs.existsSync(modpackFolder)) { fs.mkdirSync(modpackFolder, { recursive: true }) }
try { const path = join(modpackFolder, `modpack${j}.zip`)
fs.accessSync(path, fs.W_OK) try {
hashFile(path, { algorithm: 'sha1' }).then(sha1 => { fs.accessSync(path, fs.W_OK)
if (sha1 === chapter.modspack.sha1sum[j]) { hashFile(path, { algorithm: 'sha1' }).then(sha1 => {
this.unzipMods(path).catch(err => { if (sha1 === chapter.modspack.sha1sum[j]) {
reject(err) this.unzipMods(path)
}) .then(() => resolve())
} else { .catch(err => reject(err))
logger.warn(`sha1sum ${sha1} don't correspond to ${chapter.modspack.sha1sum[j]} of mods ${path}`) } else {
this.downloadAndExtractMods(chapter.modspack.mods[j], path).catch(err => { logger.warn(`sha1sum ${sha1} don't correspond to ${chapter.modspack.sha1sum[j]} of mods ${path}`)
reject(err) this.downloadAndExtractMods(chapter.modspack.mods[j], path).then(() => resolve()).catch(err => reject(err))
}) }
} }).catch(err => {
}).catch(err => { reject(new Error('Can obtain md5 hash of file ' + path + ': ' + 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 })
event.sender.send('progress', { type: 'mods', task: Number(j) + 1, total: chapter.modspack.mods.length }) } catch (err) {
} catch (err) { this.downloadAndExtractMods(chapter.modspack.mods[j], path).then(() => resolve()).catch(err => {
this.downloadAndExtractMods(chapter.modspack.mods[j], path).catch(err => { reject(err)
reject(err) })
}) }
} }))
} }
resolve(chapter) Promise.all(modsList).then(() => {
return 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))
}
}) })
} }