mirror of
https://github.com/AltarikMC/Launcher
synced 2024-11-22 06:19:50 +01:00
Lint: script more compliente with jslint
This commit is contained in:
parent
a25e81017f
commit
1a05dd165c
@ -1,21 +1,21 @@
|
|||||||
const isDev = require('electron-is-dev')
|
const isDev = require("electron-is-dev")
|
||||||
const { Client, Authenticator } = require('minecraft-launcher-core')
|
const { Authenticator, Client } = require("minecraft-launcher-core")
|
||||||
const fetch = require('node-fetch').default
|
const fetch = require("node-fetch").default
|
||||||
const hasha = require('hasha')
|
const hasha = require("hasha")
|
||||||
const fs = require('fs')
|
const fs = require("fs")
|
||||||
const { join } = require('path')
|
const { join } = require("path")
|
||||||
const constants = require("constants")
|
const constants = require("constants")
|
||||||
const zip = require('extract-zip')
|
const zip = require("extract-zip")
|
||||||
const logger = require('electron-log')
|
const logger = require("electron-log")
|
||||||
const { auth, lst } = require('msmc')
|
const { auth, lst } = require("msmc")
|
||||||
const decompress = require('decompress')
|
const decompress = require("decompress")
|
||||||
const decompressTar = require('decompress-targz')
|
const decompressTar = require("decompress-targz")
|
||||||
|
|
||||||
|
|
||||||
class Minecraft {
|
class Minecraft {
|
||||||
|
|
||||||
appdata = process.env.APPDATA || (process.platform === 'darwin' ? process.env.HOME + '/Library/Preferences' : process.env.HOME + "/.local/share")
|
appdata = process.env.APPDATA || (process.platform === "darwin" ? process.env.HOME + "/Library/Preferences" : process.env.HOME + "/.local/share")
|
||||||
localappdata = process.env.LOCALAPPDATA || (process.platform === 'darwin' ? process.env.HOME + '/Library/Application Support/' : process.env.HOME + "/.config")
|
localappdata = process.env.LOCALAPPDATA || (process.platform === "darwin" ? process.env.HOME + "/Library/Application Support/" : process.env.HOME + "/.config")
|
||||||
minecraftpath = join(this.appdata, ".altarik")
|
minecraftpath = join(this.appdata, ".altarik")
|
||||||
launcher = new Client()
|
launcher = new Client()
|
||||||
auth = null
|
auth = null
|
||||||
@ -34,7 +34,7 @@ class Minecraft {
|
|||||||
if(isDev || password.trim() !== "") {
|
if(isDev || password.trim() !== "") {
|
||||||
this.auth = Authenticator.getAuth(username, password)
|
this.auth = Authenticator.getAuth(username, password)
|
||||||
this.auth.then(v => {
|
this.auth.then(v => {
|
||||||
win.loadFile('src/client/index.html')
|
win.loadFile("src/client/index.html")
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
event.sender.send("loginError")
|
event.sender.send("loginError")
|
||||||
logger.error("[MJ login] User haven't purchase the game")
|
logger.error("[MJ login] User haven't purchase the game")
|
||||||
@ -54,7 +54,7 @@ class Minecraft {
|
|||||||
xboxManager.getMinecraft().then(async token => {
|
xboxManager.getMinecraft().then(async token => {
|
||||||
if(!token.isDemo()) {
|
if(!token.isDemo()) {
|
||||||
this.auth = token.mclc()
|
this.auth = token.mclc()
|
||||||
win.loadFile('src/client/index.html')
|
win.loadFile("src/client/index.html")
|
||||||
} else {
|
} else {
|
||||||
event.sender.send("loginError")
|
event.sender.send("loginError")
|
||||||
logger.error("[MS login] User haven't purchase the game")
|
logger.error("[MS login] User haven't purchase the game")
|
||||||
@ -95,24 +95,24 @@ class Minecraft {
|
|||||||
this.close(event, -1)
|
this.close(event, -1)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
this.launcher.on('debug', (e) => logger.info(`debug: ${e}`));
|
this.launcher.on("debug", (e) => logger.info(`debug: ${e}`));
|
||||||
this.launcher.on('data', (e) => logger.info(`data: ${e}`));
|
this.launcher.on("data", (e) => logger.info(`data: ${e}`));
|
||||||
this.launcher.on('progress', (e) => {
|
this.launcher.on("progress", (e) => {
|
||||||
event.sender.send("progress", e)
|
event.sender.send("progress", e)
|
||||||
logger.info(`progress ${e.type} :${e.task} / ${e.total}`)
|
logger.info(`progress ${e.type} :${e.task} / ${e.total}`)
|
||||||
})
|
})
|
||||||
this.launcher.on('arguments', (e) => {
|
this.launcher.on("arguments", (e) => {
|
||||||
event.sender.send("launch", e)
|
event.sender.send("launch", e)
|
||||||
logger.info("launching the game")
|
logger.info("launching the game")
|
||||||
logger.info(e)
|
logger.info(e)
|
||||||
})
|
})
|
||||||
this.launcher.on('close', (e) => {
|
this.launcher.on("close", (e) => {
|
||||||
this.close(event, e)
|
this.close(event, e)
|
||||||
})
|
})
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
this.showNotification("Impossible de lancer le jeu", "Erreur inconnue", "error")
|
this.showNotification("Impossible de lancer le jeu", "Erreur inconnue", "error")
|
||||||
event.sender.send("close", 1)
|
event.sender.send("close", 1)
|
||||||
logger.error('Unable to launch the game')
|
logger.error("Unable to launch the game")
|
||||||
logger.error(err)
|
logger.error(err)
|
||||||
})
|
})
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
@ -121,7 +121,6 @@ class Minecraft {
|
|||||||
logger.warn("Unable to install java")
|
logger.warn("Unable to install java")
|
||||||
logger.warn(err)
|
logger.warn(err)
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
close(event, code) {
|
close(event, code) {
|
||||||
@ -144,21 +143,21 @@ class Minecraft {
|
|||||||
if(fs.existsSync(file))
|
if(fs.existsSync(file))
|
||||||
fs.rmSync(file)
|
fs.rmSync(file)
|
||||||
fs.writeFileSync(file, JSON.stringify(data))
|
fs.writeFileSync(file, JSON.stringify(data))
|
||||||
event.sender.send('modsInformations', this.extractModsInformations(data))
|
event.sender.send("modsInformations", this.extractModsInformations(data))
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
event.sender.send('modsInformations', this.extractModsFromFileSystem())
|
event.sender.send("modsInformations", this.extractModsFromFileSystem())
|
||||||
logger.warn(err)
|
logger.warn(err)
|
||||||
logger.warn("An error occured while trying to connect to server")
|
logger.warn("An error occured while trying to connect to server")
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
logger.warn("Unable to connect to server")
|
logger.warn("Unable to connect to server")
|
||||||
logger.warn(err)
|
logger.warn(err)
|
||||||
event.sender.send('modsInformations', this.extractModsFromFileSystem())
|
event.sender.send("modsInformations", this.extractModsFromFileSystem())
|
||||||
}
|
}
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
logger.warn("Unable to connect to server")
|
logger.warn("Unable to connect to server")
|
||||||
logger.warn(err)
|
logger.warn(err)
|
||||||
event.sender.send('modsInformations', this.extractModsFromFileSystem())
|
event.sender.send("modsInformations", this.extractModsFromFileSystem())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,7 +176,6 @@ class Minecraft {
|
|||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extractModsInformations(json) {
|
extractModsInformations(json) {
|
||||||
@ -204,7 +202,7 @@ class Minecraft {
|
|||||||
const path = join(modpackFolder, `modpack${j}.zip`)
|
const path = join(modpackFolder, `modpack${j}.zip`)
|
||||||
try {
|
try {
|
||||||
fs.accessSync(path, constants.W_OK)
|
fs.accessSync(path, constants.W_OK)
|
||||||
let sha1 = await hasha.fromFile(path, {algorithm: 'sha1'})
|
let sha1 = await hasha.fromFile(path, {algorithm: "sha1"})
|
||||||
if(sha1 === chapter.modspack.sha1sum[j]) {
|
if(sha1 === chapter.modspack.sha1sum[j]) {
|
||||||
await this.unzipMods(path).catch(err => {
|
await this.unzipMods(path).catch(err => {
|
||||||
reject(err)
|
reject(err)
|
||||||
@ -227,13 +225,11 @@ class Minecraft {
|
|||||||
}
|
}
|
||||||
resolve(chapter)
|
resolve(chapter)
|
||||||
return
|
return
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
reject("didn't found the correct chapter" + chapter)
|
reject("didn't found the correct chapter" + chapter)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
downloadMods(link, path) {
|
downloadMods(link, path) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
fetch(link).then(response => {
|
fetch(link).then(response => {
|
||||||
@ -286,7 +282,6 @@ class Minecraft {
|
|||||||
reject(e)
|
reject(e)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
let data
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async downloadAndExtractMods(link, path) {
|
async downloadAndExtractMods(link, path) {
|
||||||
@ -300,7 +295,6 @@ class Minecraft {
|
|||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
reject(err)
|
reject(err)
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -319,17 +313,17 @@ class Minecraft {
|
|||||||
if(!fs.existsSync(downloadFolder))
|
if(!fs.existsSync(downloadFolder))
|
||||||
fs.mkdirSync(downloadFolder, { recursive: true })
|
fs.mkdirSync(downloadFolder, { recursive: true })
|
||||||
if(fs.existsSync(downloadFile)) {
|
if(fs.existsSync(downloadFile)) {
|
||||||
let sha1 = await hasha.fromFile(downloadFile, {algorithm: 'sha256'})
|
let sha1 = await hasha.fromFile(downloadFile, {algorithm: "sha256"})
|
||||||
if(sha1 === infos.sha256sum) {
|
if(sha1 === infos.sha256sum) {
|
||||||
await this.extractJavaArchive(downloadFile, runtime)
|
await this.extractJavaArchive(downloadFile, runtime)
|
||||||
let filename = process.platform == 'win32' ? 'java.exe' : 'java'
|
let filename = process.platform == "win32" ? "java.exe" : "java"
|
||||||
resolve(join(jre, 'bin', filename))
|
resolve(join(jre, "bin", filename))
|
||||||
} else {
|
} else {
|
||||||
logger.warn(`java sha256sum ${sha1} don't correspond to ${infos.sha256sum}`)
|
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))
|
await this.downloadAndExtractJava(infos, downloadFolder, runtime).then(() => resolve(join(jre, "bin", "java.exe"))).catch(err => reject(err))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
await this.downloadAndExtractJava(infos, downloadFolder, runtime).then(() => resolve(join(jre, 'bin', 'java.exe'))).catch(err => reject(err))
|
await this.downloadAndExtractJava(infos, downloadFolder, runtime).then(() => resolve(join(jre, "bin", "java.exe"))).catch(err => reject(err))
|
||||||
}
|
}
|
||||||
event.sender.send("progress", {type: "java", task: 1, total: 1 })
|
event.sender.send("progress", {type: "java", task: 1, total: 1 })
|
||||||
} else {
|
} else {
|
||||||
@ -347,7 +341,8 @@ class Minecraft {
|
|||||||
logger.info(`File unzipped`)
|
logger.info(`File unzipped`)
|
||||||
resolve()
|
resolve()
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
logger.info(`Failed to unzip ${join(downloadFolder, `${infos.name}.zip`)}`)
|
let join_s = join(downloadFolder, `${infos.name}.zip`)
|
||||||
|
logger.info(`Failed to unzip ${join_s}`)
|
||||||
reject(err)
|
reject(err)
|
||||||
})
|
})
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
@ -358,7 +353,7 @@ class Minecraft {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async extractJavaArchive(zipLocation, outLocation) {
|
async extractJavaArchive(zipLocation, outLocation) {
|
||||||
if(process.platform === 'win32') {
|
if(process.platform === "win32") {
|
||||||
await this.unzipMods(zipLocation, outLocation)
|
await this.unzipMods(zipLocation, outLocation)
|
||||||
} else {
|
} else {
|
||||||
await this.extractTar(zipLocation, outLocation)
|
await this.extractTar(zipLocation, outLocation)
|
||||||
@ -367,9 +362,9 @@ class Minecraft {
|
|||||||
|
|
||||||
invalidateData(event) {
|
invalidateData(event) {
|
||||||
logger.info("invalidate game data...")
|
logger.info("invalidate game data...")
|
||||||
const assets = join(this.minecraftpath, 'assets')
|
const assets = join(this.minecraftpath, "assets")
|
||||||
const librairies = join(this.minecraftpath,'libraries')
|
const librairies = join(this.minecraftpath,"libraries")
|
||||||
const natives = join(this.minecraftpath, 'natives')
|
const natives = join(this.minecraftpath, "natives")
|
||||||
if(fs.existsSync(assets))
|
if(fs.existsSync(assets))
|
||||||
fs.rmdirSync(assets, { recursive: true })
|
fs.rmdirSync(assets, { recursive: true })
|
||||||
if(fs.existsSync(librairies))
|
if(fs.existsSync(librairies))
|
||||||
|
Loading…
Reference in New Issue
Block a user