From 9ab2afacdd9d2cf7bc5a495c8a62db263c2c4fc3 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Sun, 11 Apr 2021 19:54:31 +0200 Subject: [PATCH] improved mods downloading support + added logging system --- .gitignore | 3 +- package-lock.json | 146 ++++++++++++++------- package.json | 8 +- src/client/assets/css/index.css | 18 +++ src/client/assets/js/index.js | 35 ++++- src/client/index.html | 7 +- src/server/main.js | 225 ++++++++++++++++++++++++++------ src/server/updater.js | 37 ++---- 8 files changed, 366 insertions(+), 113 deletions(-) diff --git a/.gitignore b/.gitignore index 8f0515e..cc67d18 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules/ game out/ -.vscode/ \ No newline at end of file +.vscode/ +launcher.json \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index f196569..fb7d326 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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" diff --git a/package.json b/package.json index 73f825d..00a750a 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/src/client/assets/css/index.css b/src/client/assets/css/index.css index b564be1..bd3e3a8 100644 --- a/src/client/assets/css/index.css +++ b/src/client/assets/css/index.css @@ -28,6 +28,7 @@ body{ background-size: 100%; width: 322px; height: 398px; + padding: 20px 50px; } #media { @@ -171,4 +172,21 @@ h3 { text-decoration: underline; cursor: pointer; color: black; +} + +.selected h3 { + color: red; +} + +#sidebar h2, +#sidebar-content h3 { + margin: 0; +} + +#sidebar h2 { + margin-bottom: 10px; +} + +#sidebar-content { + overflow: auto; } \ No newline at end of file diff --git a/src/client/assets/js/index.js b/src/client/assets/js/index.js index 398a89d..2eeebea 100644 --- a/src/client/assets/js/index.js +++ b/src/client/assets/js/index.js @@ -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 = "

Une erreur est survenue lors de la récupération des informations, vérifiez votre connexion internet puis cliquez sur réessayez

" + + "" + } else { + let element = "" + for(const i in args) { + element += `

${args[i].title}

${args[i].description}

` + } + 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') }) diff --git a/src/client/index.html b/src/client/index.html index 59b7f44..c9835fb 100644 --- a/src/client/index.html +++ b/src/client/index.html @@ -32,7 +32,10 @@
@@ -51,7 +54,7 @@
-