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

improved mods downloading support + added logging system

This commit is contained in:
Quentin Legot 2021-04-11 19:54:31 +02:00
parent 91f5d1c91a
commit 9ab2afacdd
8 changed files with 366 additions and 113 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@ node_modules/
game
out/
.vscode/
launcher.json

146
package-lock.json generated
View File

@ -768,8 +768,7 @@
"@types/node": {
"version": "12.19.8",
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.19.8.tgz",
"integrity": "sha512-D4k2kNi0URNBxIRCb1khTnkWNHv8KSL1owPmS/K5e5t8B2GzMReY7AsJIY1BnP5KdlgC4rj9jk2IkDMasIE7xg==",
"dev": true
"integrity": "sha512-D4k2kNi0URNBxIRCb1khTnkWNHv8KSL1owPmS/K5e5t8B2GzMReY7AsJIY1BnP5KdlgC4rj9jk2IkDMasIE7xg=="
},
"@types/responselike": {
"version": "1.0.0",
@ -784,7 +783,6 @@
"version": "2.9.1",
"resolved": "https://registry.npmjs.org/@types/yauzl/-/yauzl-2.9.1.tgz",
"integrity": "sha512-A1b8SU4D10uoPjwb0lnHmmu8wZhR9d+9o2PKBQT2jU5YPTKsxac6M2qGAdY7VcL+dHHhARVUDmeg0rOrcd9EjA==",
"dev": true,
"optional": true,
"requires": {
"@types/node": "*"
@ -927,6 +925,14 @@
"resolved": "https://registry.npmjs.org/aws4/-/aws4-1.11.0.tgz",
"integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA=="
},
"axios": {
"version": "0.21.1",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz",
"integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==",
"requires": {
"follow-redirects": "^1.10.0"
}
},
"balanced-match": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
@ -989,8 +995,7 @@
"buffer-crc32": {
"version": "0.2.13",
"resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz",
"integrity": "sha1-DTM+PwDqxQqhRUq9MO+MKl2ackI=",
"dev": true
"integrity": "sha1-DTM+PwDqxQqhRUq9MO+MKl2ackI="
},
"buffer-fill": {
"version": "1.0.0",
@ -1298,7 +1303,6 @@
"version": "4.3.1",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz",
"integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==",
"dev": true,
"requires": {
"ms": "2.1.2"
}
@ -1404,6 +1408,33 @@
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.37.tgz",
"integrity": "sha512-XYmBiy+ohOR4Lh5jE379fV2IU+6Jn4g5qASinhitfyO71b/sCo6MKsMLF5tc7Zf2CE8hViVQyYSobJNke8OvUw==",
"dev": true
},
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"dev": true,
"requires": {
"ms": "2.0.0"
}
},
"extract-zip": {
"version": "1.7.0",
"resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-1.7.0.tgz",
"integrity": "sha512-xoh5G1W/PB0/27lXgMQyIhP5DSY/LhoCsOyZgb+6iMmRtCwVBo55uKaMoEYrDCKQhWvqEip5ZPKAc6eFNyf/MA==",
"dev": true,
"requires": {
"concat-stream": "^1.6.2",
"debug": "^2.6.9",
"mkdirp": "^0.5.4",
"yauzl": "^2.10.0"
}
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=",
"dev": true
}
}
},
@ -1412,6 +1443,11 @@
"resolved": "https://registry.npmjs.org/electron-is-dev/-/electron-is-dev-2.0.0.tgz",
"integrity": "sha512-3X99K852Yoqu9AcW50qz3ibYBWY79/pBhlMCab8ToEWS48R0T9tyxRiQhwylE7zQdXrMnx2JKqUJyMPmt5FBqA=="
},
"electron-log": {
"version": "4.3.4",
"resolved": "https://registry.npmjs.org/electron-log/-/electron-log-4.3.4.tgz",
"integrity": "sha512-Cd6xZ9if2J4NG+PNoi3cARAYoanbM4ddpod0faaL5LIhmwuSdxP9XH95C9SgTpHMqklbg8u3CFh1yqiaqo2Bng=="
},
"electron-notarize": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/electron-notarize/-/electron-notarize-1.0.0.tgz",
@ -1840,7 +1876,6 @@
"version": "1.4.4",
"resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz",
"integrity": "sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==",
"dev": true,
"requires": {
"once": "^1.4.0"
}
@ -1972,31 +2007,23 @@
}
},
"extract-zip": {
"version": "1.7.0",
"resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-1.7.0.tgz",
"integrity": "sha512-xoh5G1W/PB0/27lXgMQyIhP5DSY/LhoCsOyZgb+6iMmRtCwVBo55uKaMoEYrDCKQhWvqEip5ZPKAc6eFNyf/MA==",
"dev": true,
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-2.0.1.tgz",
"integrity": "sha512-GDhU9ntwuKyGXdZBUgTIe+vXnWj0fppUEtMDL0+idd5Sta8TGpHssn/eusA9mrPr9qNDym6SxAYZjNvCn/9RBg==",
"requires": {
"concat-stream": "^1.6.2",
"debug": "^2.6.9",
"mkdirp": "^0.5.4",
"@types/yauzl": "^2.9.1",
"debug": "^4.1.1",
"get-stream": "^5.1.0",
"yauzl": "^2.10.0"
},
"dependencies": {
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"dev": true,
"get-stream": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.2.0.tgz",
"integrity": "sha512-nBF+F1rAZVCu/p7rjzgA+Yb4lfYXrpl7a6VmJrU8wF9I1CKvP/QwPNZHnOlwbTkY6dvtFIzFMSyQXbLoTQPRpA==",
"requires": {
"ms": "2.0.0"
"pump": "^3.0.0"
}
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=",
"dev": true
}
}
},
@ -2019,7 +2046,6 @@
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.1.0.tgz",
"integrity": "sha1-JcfInLH5B3+IkbvmHY85Dq4lbx4=",
"dev": true,
"requires": {
"pend": "~1.2.0"
}
@ -2126,6 +2152,11 @@
}
}
},
"follow-redirects": {
"version": "1.13.3",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.3.tgz",
"integrity": "sha512-DUgl6+HDzB0iEptNQEXLx/KhTmDb8tZUHSeLqpnjpknR70H0nC2t9N73BK6fN4hOvJ84pKlIQVQ4k5FFlBedKA=="
},
"forever-agent": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz",
@ -2454,6 +2485,27 @@
"integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk=",
"dev": true
},
"hasha": {
"version": "5.2.2",
"resolved": "https://registry.npmjs.org/hasha/-/hasha-5.2.2.tgz",
"integrity": "sha512-Hrp5vIK/xr5SkeN2onO32H0MgNZ0f17HRNH39WfL0SYUNOTZ5Lz1TJ8Pajo/87dYGEFlLMm7mIc/k/s6Bvz9HQ==",
"requires": {
"is-stream": "^2.0.0",
"type-fest": "^0.8.0"
},
"dependencies": {
"is-stream": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.0.tgz",
"integrity": "sha512-XCoy+WlUr7d1+Z8GgSuXmpuUFC9fOhRXglJMx+dwLKTkL44Cjd4W1Z5P+BQZpr+cR93aGP4S/s7Ftw6Nd/kiEw=="
},
"type-fest": {
"version": "0.8.1",
"resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz",
"integrity": "sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA=="
}
}
},
"homedir-polyfill": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/homedir-polyfill/-/homedir-polyfill-1.0.3.tgz",
@ -2997,16 +3049,16 @@
}
},
"mime-db": {
"version": "1.44.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.44.0.tgz",
"integrity": "sha512-/NOTfLrsPBVeH7YtFPgsVWveuL+4SjjYxaQ1xtM1KMFj7HdxlBlxeyNLzhyJVx7r4rZGJAZ/6lkKCitSc/Nmpg=="
"version": "1.47.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.47.0.tgz",
"integrity": "sha512-QBmA/G2y+IfeS4oktet3qRZ+P5kPhCKRXxXnQEudYqUaEioAU1/Lq2us3D/t1Jfo4hE9REQPrbB7K5sOczJVIw=="
},
"mime-types": {
"version": "2.1.27",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.27.tgz",
"integrity": "sha512-JIhqnCasI9yD+SsmkquHBxTSEuZdQX5BuQnS2Vc7puQQQ+8yiP5AY5uWhpdv4YL4VM5c6iliiYWPgJ/nJQLp7w==",
"version": "2.1.30",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.30.tgz",
"integrity": "sha512-crmjA4bLtR8m9qLpHvgxSChT+XoSlZi8J4n/aIdn3z92e/U47Z0V/yl+Wh9W046GgFVAmoNR/fmdbZYcSSIUeg==",
"requires": {
"mime-db": "1.44.0"
"mime-db": "1.47.0"
}
},
"mimic-fn": {
@ -3086,8 +3138,7 @@
"ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
"dev": true
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
},
"mute-stream": {
"version": "0.0.8",
@ -3399,7 +3450,6 @@
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
"dev": true,
"requires": {
"wrappy": "1"
}
@ -3591,8 +3641,7 @@
"pend": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz",
"integrity": "sha1-elfrVQpng/kRUzH89GY9XI4AelA=",
"dev": true
"integrity": "sha1-elfrVQpng/kRUzH89GY9XI4AelA="
},
"performance-now": {
"version": "2.1.0",
@ -3755,7 +3804,6 @@
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz",
"integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==",
"dev": true,
"requires": {
"end-of-stream": "^1.1.0",
"once": "^1.3.1"
@ -4044,6 +4092,14 @@
"integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=",
"dev": true
},
"sha1-file": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/sha1-file/-/sha1-file-2.0.0.tgz",
"integrity": "sha512-ejHwMRlsshtZF/UVYfuzq0B4jSUFPxBgbBUnYr1sS4K7i9j5Ix6bz2ZxxDIXB6tqZCVv08Gjp1McFkoGIsa7Jw==",
"requires": {
"hasha": "^5.2.0"
}
},
"shebang-command": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz",
@ -4517,9 +4573,9 @@
"dev": true
},
"uri-js": {
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.0.tgz",
"integrity": "sha512-B0yRTzYdUCCn9n+F4+Gh4yIDtMQcaJsmYBDsTSG8g/OejKBodLQ2IHfN3bM7jUsRXndopT7OIXWdYqc1fjmV6g==",
"version": "4.4.1",
"resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz",
"integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==",
"requires": {
"punycode": "^2.1.0"
}
@ -4645,8 +4701,7 @@
"wrappy": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
"dev": true
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
},
"xmlbuilder": {
"version": "9.0.7",
@ -4794,7 +4849,6 @@
"version": "2.10.0",
"resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.10.0.tgz",
"integrity": "sha1-x+sXyT4RLLEIb6bY5R+wZnt5pfk=",
"dev": true,
"requires": {
"buffer-crc32": "~0.2.3",
"fd-slicer": "~1.1.0"

View File

@ -6,7 +6,7 @@
"repository": "AltarikMC/Launcher",
"scripts": {
"start": "electron-forge start",
"test": "echo \"Error: no test specified\" && exit 1",
"test": "electron .",
"package": "electron-forge package",
"make": "electron-forge make"
},
@ -21,9 +21,13 @@
"electron": "^12.0.2"
},
"dependencies": {
"axios": "^0.21.1",
"electron-is-dev": "^2.0.0",
"electron-log": "^4.3.4",
"electron-squirrel-startup": "^1.0.0",
"minecraft-launcher-core": "^3.16.2"
"extract-zip": "^2.0.1",
"minecraft-launcher-core": "^3.16.2",
"sha1-file": "^2.0.0"
},
"config": {
"forge": "./config.forge.js"

View File

@ -28,6 +28,7 @@ body{
background-size: 100%;
width: 322px;
height: 398px;
padding: 20px 50px;
}
#media {
@ -172,3 +173,20 @@ h3 {
cursor: pointer;
color: black;
}
.selected h3 {
color: red;
}
#sidebar h2,
#sidebar-content h3 {
margin: 0;
}
#sidebar h2 {
margin-bottom: 10px;
}
#sidebar-content {
overflow: auto;
}

View File

@ -11,14 +11,18 @@ const maxMem = document.querySelector('#maxMem')
const outputMinMem = document.querySelector('#outputMinMem')
const outputMaxMem = document.querySelector('#outputMaxMem')
const totalMem = os.totalmem() / (1.049 * Math.pow(10, 6))
const sidebar = document.querySelector("#sidebar-content")
document.body.onload = (e) => {
let selectedChapter = -1;
document.body.onload = () => {
minMem.max = totalMem
maxMem.max = totalMem
minMem.value = localStorage.getItem("minMem") != null ? localStorage.getItem("minMem") : 1024
outputMinMem.innerHTML = minMem.value
maxMem.value = localStorage.getItem("maxMem") != null ? localStorage.getItem("maxMem") : 2048
outputMaxMem.innerHTML = maxMem.value
demandModsInformations()
}
ipcRenderer.on("nick", (event, args) => {
@ -33,7 +37,8 @@ launchBtn.addEventListener("click", e => {
if(Number(minMem.value) <= Number(maxMem.value)){
ipcRenderer.send('launch', {
minMem: minMem.value + "M",
maxMem: maxMem.value + "M"
maxMem: maxMem.value + "M",
chapter: selectedChapter
})
launchBtn.disabled = true
localStorage.setItem("minMem", minMem.value)
@ -82,6 +87,32 @@ ipcRenderer.on('launch', (e, args) => {
loadingMessage.classList.add('hidden')
})
ipcRenderer.on("modsInformations", (e, args) => {
if(args === null) {
sidebar.innerHTML = "<p>Une erreur est survenue lors de la récupération des informations, vérifiez votre connexion internet puis cliquez sur réessayez</p>"
+ "<button onclick=\"demandModsInformations()\">Réessayer</button>"
} else {
let element = ""
for(const i in args) {
element += `<div data-chapter="${i}" onclick="changeSelectedChapter(this)"><h3>${args[i].title}</h3><p>${args[i].description}</p></div>`
}
sidebar.innerHTML = element
}
})
function demandModsInformations() {
ipcRenderer.send('demandModsInformations')
}
function changeSelectedChapter(element) {
selectedChapter = Number(element.dataset.chapter)
document.querySelectorAll("#sidebar-content > div").forEach((v, key) => {
v.classList.remove("selected")
})
element.classList.add("selected")
launchBtn.classList.remove('hidden')
}
disconnectBtn.addEventListener('click', e => {
ipcRenderer.send('disconnect')
})

View File

@ -32,8 +32,11 @@
</div>
<div id="content">
<div id="sidebar">
<h2>Chapitres</h2>
<div id="sidebar-content">
</div>
</div>
<div id="media">
<div id="options">
<img src="assets/images/svg/settings.svg">
@ -51,7 +54,7 @@
<div id="account">
<div id="nick"></div><!-- <img src=""> Head du joueur -->
</div>
<button id="launch-btn">
<button id="launch-btn" class="hidden">
<div id="launch-text">JOUER</div>
<div id="loading-message" class="hidden">Téléchargement de Minecraft en cours...</div>
<div id="fullprogressbar" class="hidden"><div id="progressbar"></div></div>

View File

@ -1,26 +1,32 @@
const { app, BrowserWindow, Menu, ipcMain, Notification, autoUpdater, dialog } = require('electron')
const logger = require('electron-log')
const { join } = require('path')
if (require('electron-squirrel-startup')) {
require("./install.js").handleSquirrelEvent(app)
app.quit()
return;
}
// don't work
require('./updater.js').configUpdater(app, autoUpdater, dialog)
require('./updater.js').configUpdater(app, autoUpdater, dialog, logger)
const axios = require('axios').default
const sha1File = require('sha1-file')
const fs = require('fs')
const constants = require("constants")
const zip = require('extract-zip')
const { Client, Authenticator } = require('minecraft-launcher-core')
const appdata = process.env.APPDATA || (process.platform == 'darwin' ? process.env.HOME + '/Library/Preferences' : process.env.HOME + "/.local/share")
const launcher = new Client();
const iconPath = join(__dirname, "icon.ico");
const launcher = new Client()
const iconPath = join(__dirname, "icon.ico")
let win = null
let auth = null
let Minecraftpath = join(appdata, ".altarik")
let clientPackage = "https://www.dropbox.com/s/ww6a052nzzgojdm/modpack.zip?dl=1"
// let clientPackage = "https://www.dropbox.com/s/ww6a052nzzgojdm/modpack.zip?dl=1"
let version = "1.16.4"
let versionFolder = "fabric-loader-0.10.8-1.16.4"
let modsList = undefined
function createWindow () {
win = new BrowserWindow({
@ -84,17 +90,13 @@ ipcMain.on("login", (event, args) => {
}, 1000)
}).catch((err) => {
console.warn(err)
logger.warn(err)
showNotification("Erreur de connexion")
})
})
function showNotification(title, body="") {
const notification = {
title: title,
body: body
}
new Notification(notification).show()
new Notification({ title: title, body: body }).show()
}
ipcMain.on("notification", (event, args) => {
@ -102,8 +104,9 @@ ipcMain.on("notification", (event, args) => {
})
ipcMain.on("launch", (event, args) => {
let opts = {
clientPackage: clientPackage,
extractMods(Number(args.chapter), event).then(() => {
launcher.launch({
// clientPackage: clientPackage,
authorization: auth,
root: Minecraftpath,
version: {
@ -115,21 +118,169 @@ ipcMain.on("launch", (event, args) => {
max: args.maxMem,
min: args.minMem
}
}
launcher.launch(opts)
})
// launcher.on('debug', (e) => console.log("debug", e));
// launcher.on('data', (e) => console.log("data", e));
launcher.on('progress', (e) => event.sender.send("progress", e))
launcher.on('arguments', (e) => event.sender.send("launch", e))
launcher.on('progress', (e) => {
event.sender.send("progress", e)
logger.info(`progress ${e.type} :${e.task} / ${e.total}`)
})
launcher.on('arguments', (e) => {
event.sender.send("launch", e)
logger.info("launching the game")
logger.info(e)
})
launcher.on('close', (e) => {
event.sender.send("close", e)
if(e !== 0){
logger.warn("Minecraft didn't close properly")
logger.warn(e)
showNotification("Une erreur est survenue", "Minecraft ne s'est pas fermé correctement")
}
})
}).catch((err) => {
showNotification("Impossible de lancer le jeu")
logger.error('Unable to launch the game')
logger.error(err)
})
})
ipcMain.on("disconnect", (e) => {
win.loadFile('src/client/login.html')
})
ipcMain.on("demandModsInformations", (e) => {
getModsInformations(e)
})
function getModsInformations(event) {
axios.get("https://altarik.fr/launcher.json").then(o => {
if(o.status === 200 && o.headers["content-type"] === "application/json") {
folder = join(process.env.LOCALAPPDATA, "altarik-launcher", "data")
if(!fs.existsSync(folder))
fs.mkdirSync(folder)
fs.writeFileSync(join(folder, "launcher.json"), JSON.stringify(o.data))
event.sender.send('modsInformations', extractModsInformations(o.data))
} else {
event.sender.send('modsInformations', extractModsFromFileSystem())
}
}).catch(err => {
logger.error("Unable to connect to server")
logger.error(err)
event.sender.send('informations', extractModsFromFileSystem())
})
}
function extractModsFromFileSystem() {
content = fs.readFileSync(join(process.env.LOCALAPPDATA, "altarik-launcher/data/launcher.json"))
if(content !== null) {
showNotification("Impossible de récupérer certaines informations en ligne", "utilisation des dernières données récupérées")
return extractModsInformations(JSON.parse(o.data))
} else {
showNotification("Impossible de récupérer certaines informations en ligne", "Veuillez réessayez en cliquant sur le bouton")
return null
}
}
function extractModsInformations(json) {
modsList = json.chapters
return modsList
}
async function extractMods(chapterId, event) {
return new Promise(async (resolve, reject) => {
modsFolder = join(Minecraftpath, "mods")
shaderFolder = join(Minecraftpath, "shaderpacks")
if(fs.existsSync(modsFolder))
fs.rmSync(modsFolder, { recursive: true })
if(fs.existsSync(shaderFolder))
fs.rmSync(shaderFolder, { recursive: true })
for(const i in modsList) {
if(Number(i) === chapterId) {
const chapter = modsList[i]
let j
for(j in chapter.modspack.mods) {
event.sender.send("progress", {type: "mods", task: i, total: chapter.modspack.mods.length })
modpackFolder = join(Minecraftpath, "modpack", chapter.title)
if(!fs.existsSync(modpackFolder))
fs.mkdirSync(modpackFolder, { recursive: true })
const path = join(modpackFolder, `modpack${j}.zip`)
try {
fs.accessSync(path, constants.W_OK)
sha1 = await sha1File(path)
if(sha1 === chapter.modspack.sha1sum) {
await unzipMods(path)
} else {
await downloadAndExtractMods(chapter.modspack.mods[j], path).catch(err => {
reject(err)
})
}
} catch (err) {
try {
await downloadAndExtractMods(chapter.modspack.mods[j], path)
} catch(e) {
reject({ err, e })
return
}
}
}
event.sender.send("progress", {type: "mods", task: Number(j)+1, total: chapter.modspack.mods.length })
resolve()
return
}
}
reject("didn't found the correct chapter" + chapter)
return
})
}
function downloadMods(link, path) {
return new Promise((resolve, reject) => {
axios.get(link, {
responseType: "stream"
}).then(res => {
if(res.status === 200) {
res.data.pipe(fs.createWriteStream(path));
res.data.on("end", () => {
logger.log("download completed");
resolve("download completed")
});
} else {
reject(res.status)
}
}).catch(err => {
reject(err)
})
})
}
async function unzipMods(path) {
return new Promise(async (resolve, reject) => {
zip(path, { dir: Minecraftpath }).then(() => {
resolve()
}).catch(err => {
reject(err)
})
})
}
async function downloadAndExtractMods(link, path) {
return new Promise(async(resolve, reject) => {
downloadMods(link, path).then(() => {
unzipMods(path).then(() => {
resolve()
}).catch(err => {
reject(err)
})
}).catch(err => {
reject(err)
})
})
}

View File

@ -2,7 +2,6 @@ const isDev = require('electron-is-dev')
const { Notification } = require('electron')
const os = require('os')
const pkg = require('../../package.json')
const { format } = require('util')
const server = 'https://update.electronjs.org'
function initUpdater(autoUpdater) {
@ -12,9 +11,13 @@ function initUpdater(autoUpdater) {
}, 10 * 60 * 1000) // 10 minutes
}
function configUpdater(app, autoUpdater, dialog) {
if(isDev)
function configUpdater(app, autoUpdater, dialog, logger) {
if(isDev) {
logger.info(`developpement version ${app.getVersion()}`)
return
}
logger.info(`production version ${app.getVersion()}`)
const feed = `${server}/${pkg.repository}/${process.platform}-${process.arch}/${app.getVersion()}`
autoUpdater.setFeedURL(feed)
app.isReady ? initUpdater(autoUpdater) : app.on("ready", () => initUpdater(autoUpdater))
@ -31,38 +34,26 @@ function configUpdater(app, autoUpdater, dialog) {
}
dialog.showMessageBox(dialogOpts).then((returnValue) => {
if (returnValue.response === 0) autoUpdater.quitAndInstall()
if (returnValue.response === 0) {
logger.info("Quit applicaiton to install update")
autoUpdater.quitAndInstall()
}
})
})
autoUpdater.on('error', message => {
console.error('There was a problem updating the application')
console.error(message)
/*
showNotification(feed)
const dialogOpts = {
type: 'info',
buttons: ['Fermer'],
title: 'Erreur lors de la tentative de mise à jour du launcher',
message: "Une erreur est survenue lros de la tentative de mise à jour du launcher",
detail: message
}
dialog.showMessageBox(dialogOpts) */
logger.error('There was a problem updating the application')
logger.error(message)
})
autoUpdater.on('update-available', () => {
showNotification("Altarik launcher", "downloading update")
autoUpdater.down
logger.info("update available, downloading...")
})
}
function showNotification(title, body="") {
const content = {
title: title,
body: body
}
new Notification(content).show()
new Notification({ title: title, body: body }).show()
}
module.exports = {