4
0
mirror of https://github.com/AltarikMC/Launcher synced 2024-11-22 06:19:50 +01:00

Doesn't remove shader folder anymore, change syntax to avoid Promise executor to be an async func

This commit is contained in:
Quentin Legot 2024-01-14 17:58:37 +01:00
parent 7693898360
commit 508dc2d4d0

View File

@ -184,11 +184,11 @@ export default class Minecraft {
} }
async extractMods (chapterId, event) { async extractMods (chapterId, event) {
return new Promise(async (resolve, reject) => { return new Promise((resolve, reject) => {
const modsFolder = join(this.minecraftpath, 'mods') const modsFolder = join(this.minecraftpath, 'mods')
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 }) }
for (const i in this.modsList) { for (const i in this.modsList) {
if (Number(i) === chapterId) { if (Number(i) === chapterId) {
const chapter = this.modsList[i] const chapter = this.modsList[i]
@ -199,25 +199,25 @@ export default class Minecraft {
const path = join(modpackFolder, `modpack${j}.zip`) const path = join(modpackFolder, `modpack${j}.zip`)
try { try {
fs.accessSync(path, fs.W_OK) fs.accessSync(path, fs.W_OK)
const sha1 = await hashFile(path, { algorithm: 'sha1' }) hashFile(path, { algorithm: 'sha1' }).then(sha1 => {
if (sha1 === chapter.modspack.sha1sum[j]) { if (sha1 === chapter.modspack.sha1sum[j]) {
await this.unzipMods(path).catch(err => { this.unzipMods(path).catch(err => {
reject(err) reject(err)
}) })
} else { } else {
logger.warn(`sha1sum ${sha1} don't correspond to ${chapter.modspack.sha1sum[j]} of mods ${path}`) logger.warn(`sha1sum ${sha1} don't correspond to ${chapter.modspack.sha1sum[j]} of mods ${path}`)
await this.downloadAndExtractMods(chapter.modspack.mods[j], path).catch(err => { this.downloadAndExtractMods(chapter.modspack.mods[j], path).catch(err => {
reject(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 }) event.sender.send('progress', { type: 'mods', task: Number(j) + 1, total: chapter.modspack.mods.length })
} catch (err) { } catch (err) {
try { this.downloadAndExtractMods(chapter.modspack.mods[j], path).catch(err => {
await this.downloadAndExtractMods(chapter.modspack.mods[j], path) reject(err)
} catch (e) { })
reject(new Error({ err, e }))
return
}
} }
} }
resolve(chapter) resolve(chapter)