Skip to content

Commit

Permalink
Doesn't remove shader folder anymore, change syntax to avoid Promise …
Browse files Browse the repository at this point in the history
…executor to be an async func
  • Loading branch information
quentinlegot committed Jan 14, 2024
1 parent 7693898 commit 508dc2d
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions src/server/minecraft.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,11 @@ export default class Minecraft {
}

async extractMods (chapterId, event) {
return new Promise(async (resolve, reject) => {
return new Promise((resolve, reject) => {
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(shaderFolder)) { fs.rmSync(shaderFolder, { recursive: true }) }
// if (fs.existsSync(shaderFolder)) { fs.rmSync(shaderFolder, { recursive: true }) }
for (const i in this.modsList) {
if (Number(i) === chapterId) {
const chapter = this.modsList[i]
Expand All @@ -199,25 +199,25 @@ export default class Minecraft {
const path = join(modpackFolder, `modpack${j}.zip`)
try {
fs.accessSync(path, fs.W_OK)
const sha1 = await hashFile(path, { algorithm: 'sha1' })
if (sha1 === chapter.modspack.sha1sum[j]) {
await this.unzipMods(path).catch(err => {
reject(err)
})
} else {
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 => {
reject(err)
})
}
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) {
try {
await this.downloadAndExtractMods(chapter.modspack.mods[j], path)
} catch (e) {
reject(new Error({ err, e }))
return
}
this.downloadAndExtractMods(chapter.modspack.mods[j], path).catch(err => {
reject(err)
})
}
}
resolve(chapter)
Expand Down

0 comments on commit 508dc2d

Please sign in to comment.