4
0
mirror of https://github.com/AltarikMC/Launcher synced 2025-12-13 11:41:45 +00:00

Added linux support

This commit is contained in:
2022-10-10 23:39:23 +02:00
parent 1e8766689a
commit 2cb8fd1e5b
3 changed files with 247 additions and 14 deletions

View File

@@ -8,6 +8,9 @@ const constants = require("constants")
const zip = require('extract-zip')
const logger = require('electron-log')
const msmc = require('msmc')
const decompress = require('decompress')
const decompressTar = require('decompress-targz')
class Minecraft {
@@ -267,13 +270,30 @@ class Minecraft {
zip(zipLocation, { dir: outLocation }).then(() => {
resolve()
}).catch(err => {
logger.err(`failed to unzip file`)
logger.error(`failed to unzip file`)
reject(err)
})
})
}
async extractTar(tarLocation, outLocation=this.microsoftpath) {
return new Promise(async (resolve, reject) => {
logger.info(`Extracting targz ${tarLocation} file to ${outLocation}`)
decompress(tarLocation, outLocation, {
plugins: [
decompressTar()
]
}).then(() => {
resolve()
}).catch((e) => {
logger.error(`Failed to extract targz file`)
reject(e)
})
})
let data
}
async downloadAndExtractMods(link, path) {
return new Promise(async (resolve, reject) => {
@@ -307,8 +327,9 @@ class Minecraft {
if(fs.existsSync(downloadFile)) {
let sha1 = await hasha.fromFile(downloadFile, {algorithm: 'sha256'})
if(sha1 === infos.sha256sum) {
await this.unzipMods(downloadFile, runtime)
resolve(join(jre, 'bin', 'java.exe'))
await this.extractJavaArchive(downloadFile, runtime)
let filename = process.platform == 'win32' ? 'java.exe' : 'java'
resolve(join(jre, 'bin', filename))
} else {
logger.warn(`java sha256sum ${sha1} don't correspond to ${infos.sha256sum}`)
await this.downloadAndExtractJava(infos, downloadFolder, runtime).then(() => resolve(join(jre, 'bin', 'java.exe'))).catch(err => reject(err))
@@ -328,7 +349,7 @@ class Minecraft {
logger.info(`Downloading ${infos.name}`)
this.downloadMods(infos.link, join(downloadFolder, `${infos.name}.zip`)).then(() => {
logger.info(`download completed`)
this.unzipMods(join(downloadFolder, `${infos.name}.zip`), runtimeFolder).then(() => {
this.extractJavaArchive(join(downloadFolder, `${infos.name}.zip`), runtimeFolder).then(() => {
logger.info(`File unzipped`)
resolve()
}).catch(err => {
@@ -342,6 +363,14 @@ class Minecraft {
})
}
async extractJavaArchive(zipLocation, outLocation) {
if(process.platform === 'win32') {
await this.unzipMods(zipLocation, outLocation)
} else {
await this.extractTar(zipLocation, outLocation)
}
}
invalidateData(event) {
logger.info("invalidate game data...")
const assets = join(this.minecraftpath, 'assets')