From e51694dc9157a187799193cd4ceb6d9f2965136e Mon Sep 17 00:00:00 2001 From: PaulaBras <68814660+PaulaBras@users.noreply.github.com> Date: Sat, 14 Jan 2023 01:26:26 +0100 Subject: [PATCH] updates, soc, simplify code --- updater/package-lock.json | 59 +++++++- updater/package.json | 6 +- updater/src/data_structure.js | 24 +++ updater/src/download.js | 20 +++ updater/src/getFiles.js | 40 +++++ updater/src/git_ops.js | 0 updater/src/html_elements.js | 19 +++ updater/src/index.html | 80 +++++----- updater/src/renderer.js | 276 ---------------------------------- updater/src/save.js | 36 +++++ updater/src/startup.js | 61 ++++++++ updater/src/unzip.js | 29 ++++ updater/yarn.lock | 21 +++ 13 files changed, 352 insertions(+), 319 deletions(-) create mode 100644 updater/src/data_structure.js create mode 100644 updater/src/download.js create mode 100644 updater/src/getFiles.js create mode 100644 updater/src/git_ops.js create mode 100644 updater/src/html_elements.js create mode 100644 updater/src/save.js create mode 100644 updater/src/startup.js create mode 100644 updater/src/unzip.js diff --git a/updater/package-lock.json b/updater/package-lock.json index e0dbeca..dea3f12 100644 --- a/updater/package-lock.json +++ b/updater/package-lock.json @@ -1,12 +1,12 @@ { - "name": "updater", - "version": "1.0.0", + "name": "sectorfile_updater", + "version": "0.0.1", "lockfileVersion": 2, "requires": true, "packages": { "": { - "name": "updater", - "version": "1.0.0", + "name": "sectorfile_updater", + "version": "0.0.1", "license": "MIT", "dependencies": { "@octokit/core": "^4.0.5", @@ -15,6 +15,7 @@ "electron-squirrel-startup": "^1.0.0", "http": "^0.0.1-security", "js-yaml": "^4.1.0", + "simple-git": "^3.15.1", "superagent": "^8.0.3" }, "devDependencies": { @@ -544,6 +545,19 @@ "integrity": "sha512-k2Ty1JcVojjJFwrg/ThKi2ujJ7XNLYaFGNB/bWT9wGR+oSMJHMa5w+CUq6p/pVrKeNNgA7pCqEcjSnHVoqJQFw==", "dev": true }, + "node_modules/@kwsites/file-exists": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@kwsites/file-exists/-/file-exists-1.1.1.tgz", + "integrity": "sha512-m9/5YGR18lIwxSFDwfE3oA7bWuq9kdau6ugN4H2rJeyhFQZcG9AgSHkQtSD15a8WvTgfz9aikZMrKPHvbpqFiw==", + "dependencies": { + "debug": "^4.1.1" + } + }, + "node_modules/@kwsites/promise-deferred": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@kwsites/promise-deferred/-/promise-deferred-1.1.1.tgz", + "integrity": "sha512-GaHYm+c0O9MjZRu0ongGBRbinu8gVAMd2UZjji6jVmqKtZluZnptXGWhz1E8j8D2HJ3f/yMxKAUC0b+57wncIw==" + }, "node_modules/@malept/cross-spawn-promise": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/@malept/cross-spawn-promise/-/cross-spawn-promise-2.0.0.tgz", @@ -5600,6 +5614,20 @@ "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", "dev": true }, + "node_modules/simple-git": { + "version": "3.15.1", + "resolved": "https://registry.npmjs.org/simple-git/-/simple-git-3.15.1.tgz", + "integrity": "sha512-73MVa5984t/JP4JcQt0oZlKGr42ROYWC3BcUZfuHtT3IHKPspIvL0cZBnvPXF7LL3S/qVeVHVdYYmJ3LOTw4Rg==", + "dependencies": { + "@kwsites/file-exists": "^1.1.1", + "@kwsites/promise-deferred": "^1.1.1", + "debug": "^4.3.4" + }, + "funding": { + "type": "github", + "url": "https://github.com/steveukx/git-js?sponsor=1" + } + }, "node_modules/smart-buffer": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz", @@ -6854,6 +6882,19 @@ "integrity": "sha512-k2Ty1JcVojjJFwrg/ThKi2ujJ7XNLYaFGNB/bWT9wGR+oSMJHMa5w+CUq6p/pVrKeNNgA7pCqEcjSnHVoqJQFw==", "dev": true }, + "@kwsites/file-exists": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@kwsites/file-exists/-/file-exists-1.1.1.tgz", + "integrity": "sha512-m9/5YGR18lIwxSFDwfE3oA7bWuq9kdau6ugN4H2rJeyhFQZcG9AgSHkQtSD15a8WvTgfz9aikZMrKPHvbpqFiw==", + "requires": { + "debug": "^4.1.1" + } + }, + "@kwsites/promise-deferred": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@kwsites/promise-deferred/-/promise-deferred-1.1.1.tgz", + "integrity": "sha512-GaHYm+c0O9MjZRu0ongGBRbinu8gVAMd2UZjji6jVmqKtZluZnptXGWhz1E8j8D2HJ3f/yMxKAUC0b+57wncIw==" + }, "@malept/cross-spawn-promise": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/@malept/cross-spawn-promise/-/cross-spawn-promise-2.0.0.tgz", @@ -10686,6 +10727,16 @@ "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", "dev": true }, + "simple-git": { + "version": "3.15.1", + "resolved": "https://registry.npmjs.org/simple-git/-/simple-git-3.15.1.tgz", + "integrity": "sha512-73MVa5984t/JP4JcQt0oZlKGr42ROYWC3BcUZfuHtT3IHKPspIvL0cZBnvPXF7LL3S/qVeVHVdYYmJ3LOTw4Rg==", + "requires": { + "@kwsites/file-exists": "^1.1.1", + "@kwsites/promise-deferred": "^1.1.1", + "debug": "^4.3.4" + } + }, "smart-buffer": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz", diff --git a/updater/package.json b/updater/package.json index 460455f..76d0674 100644 --- a/updater/package.json +++ b/updater/package.json @@ -20,7 +20,8 @@ "config": { "forge": { "packagerConfig": {}, - "makers": [{ + "makers": [ + { "name": "@electron-forge/maker-squirrel", "config": { "name": "updater" @@ -50,6 +51,7 @@ "electron-squirrel-startup": "^1.0.0", "http": "^0.0.1-security", "js-yaml": "^4.1.0", + "simple-git": "^3.15.1", "superagent": "^8.0.3" }, "devDependencies": { @@ -60,4 +62,4 @@ "@electron-forge/maker-zip": "^6.0.0-beta.66", "electron": "^21.0.1" } -} \ No newline at end of file +} diff --git a/updater/src/data_structure.js b/updater/src/data_structure.js new file mode 100644 index 0000000..40c8f5d --- /dev/null +++ b/updater/src/data_structure.js @@ -0,0 +1,24 @@ +var systemstructure = { + path: "" +}; + +var structure = { + region: 0, + file: 0, + installcreds: false, // Not yet implemented + installhoppie: false, // Not yet implemented + cid: { + save: true, + id: -1 + }, + password: { + save: true, + pass: "" + }, + passwordhoppie: { + save: true, + pass: "" + }, + currentInstalledAirac: 0, + version: "v1" +}; \ No newline at end of file diff --git a/updater/src/download.js b/updater/src/download.js new file mode 100644 index 0000000..6ff9961 --- /dev/null +++ b/updater/src/download.js @@ -0,0 +1,20 @@ +function downloadFile(source, path) { + console.log(source); + const zipFile = source.split('/').pop(); + + superagent + .get(source).set("Referer", "http://files.aero-nav.com/") + .on('error', function(error) { + console.log(error); + }) + .pipe(fs.createWriteStream(path + "\\" + zipFile)) + .on('finish', function() { + // add code below to here + }); +} + +function createFolder(folder) { + if (!fs.existsSync(folder)) { + fs.mkdirSync(folder); + } +}; \ No newline at end of file diff --git a/updater/src/getFiles.js b/updater/src/getFiles.js new file mode 100644 index 0000000..dde3872 --- /dev/null +++ b/updater/src/getFiles.js @@ -0,0 +1,40 @@ +async function getUpdates() { + const courses = await superagent.get('https://files.aero-nav.com/'); + let text = courses.text.match(/Download Pages([^]*?)<\/body>/g); + console.log(text); + let liste = text[0].match(/(.*?)<\/b>/g).map(item => item.replace(/<\/?b>/g, "")); + + liste.forEach(item => { + var option = document.createElement("option"); + option.text = item; + dropDownGNG.add(option); + }); + getFiles(); +} + + +async function getFiles() { + await removeFileItems(); + let region = "https://files.aero-nav.com/" + dropDownGNG.options[dropDownGNG.selectedIndex].text; + let courses = await superagent.get(region); + let text = courses.text.split("ReleasedDownload").pop(); + text = text.split("

AIRAC News

")[0]; + let rows = text.match(/(.*?)<\/td>/g).map(row => row.replace(/<\/?td>/g, "")); + + let fileNames = rows.filter((row, index) => index % 5 === 1); + let versionNumbers = rows.filter((row, index) => index % 5 === 2); + let hrefLinks = rows.filter((row, index) => index % 5 === 4).map(row => row.match(/href="(.*?)"/)[1]); + + removeFileItems(); + fileNames.forEach((fileName, index) => { + let option = document.createElement("option"); + option.text = fileName; + option.version = versionNumbers[index]; + option.href = hrefLinks[index]; + dropDownFiles.add(option); + }); + if (structure.file != -1) { + dropDownFiles.selectedIndex = structure.file; + } + return hrefLinks; +} \ No newline at end of file diff --git a/updater/src/git_ops.js b/updater/src/git_ops.js new file mode 100644 index 0000000..e69de29 diff --git a/updater/src/html_elements.js b/updater/src/html_elements.js new file mode 100644 index 0000000..47530b0 --- /dev/null +++ b/updater/src/html_elements.js @@ -0,0 +1,19 @@ +// Global Variabels +let dirBox = document.getElementById('dirBox'); +let usernameInput = document.getElementById('username'); +let passwordInput = document.getElementById('password'); +let passwordhoppieInput = document.getElementById('passwordhoppie'); +let saveCredBtn = document.getElementById('savecred'); + +// CheckBox Events +let checkBoxUsername = document.getElementById('saveuser'); +let checkBoxPassword = document.getElementById('savepw'); +let checkBoxSavepwhoppie = document.getElementById('savepwhoppie'); + +// Check update +let dropDownGNG = document.getElementById('gng'); +let dropDownFiles = document.getElementById('files'); + +saveCredBtn.addEventListener('click', (e) => { + save(); +}); \ No newline at end of file diff --git a/updater/src/index.html b/updater/src/index.html index 8a6d587..11e9715 100644 --- a/updater/src/index.html +++ b/updater/src/index.html @@ -1,11 +1,13 @@ - + + Sectorfile Updater - - + + +

Input Directory

@@ -19,40 +21,44 @@
-

Username

- - -
-

Password

- - - Please be aware that the password you enter will be stored in plain - text in our system. This means that it will not be encrypted or - otherwise secured. We recommend that you do not use a password that - you also use for other important accounts, such as your email or - banking. Please use caution when entering your password and consider - using a unique and strong password specifically for this - account. -
-
-

Password Hoppie

- - - Please be aware that the password you enter will be stored in plain - text in our system. This means that it will not be encrypted or - otherwise secured. We recommend that you do not use a password that - you also use for other important accounts, such as your email or - banking. Please use caution when entering your password and consider - using a unique and strong password specifically for this - account. -
- +

Username

+ + +
+

Password

+ + + Please be aware that the password you enter will be stored in plain + text in our system. This means that it will not be encrypted or + otherwise secured. We recommend that you do not use a password that + you also use for other important accounts, such as your email or + banking. Please use caution when entering your password and consider + using a unique and strong password specifically for this + account. +
+
+

Password Hoppie

+ + + Please be aware that the password you enter will be stored in plain + text in our system. This means that it will not be encrypted or + otherwise secured. We recommend that you do not use a password that + you also use for other important accounts, such as your email or + banking. Please use caution when entering your password and consider + using a unique and strong password specifically for this + account. +
+
- - + + + + + + + + + + \ No newline at end of file diff --git a/updater/src/renderer.js b/updater/src/renderer.js index 6a066f8..988b41a 100644 --- a/updater/src/renderer.js +++ b/updater/src/renderer.js @@ -3,106 +3,12 @@ const superagent = require('superagent').agent(); var fs = require('fs'); var DecompressZip = require('decompress-zip'); -// Global Variabels -let dirBox = document.getElementById('dirBox'); -let usernameInput = document.getElementById('username'); -let passwordInput = document.getElementById('password'); -let passwordhoppieInput = document.getElementById('passwordhoppie'); -let saveCredBtn = document.getElementById('savecred'); - -// CheckBox Events -let checkBoxUsername = document.getElementById('saveuser'); -let checkBoxPassword = document.getElementById('savepw'); -let checkBoxSavepwhoppie = document.getElementById('savepwhoppie'); - const delay = ms => new Promise(resolve => setTimeout(resolve, ms)); -var systemstructure = { - path: "" -}; -var structure = { - region: 0, - file: 0, - installcreds: false, // Not yet implemented - installhoppie: false, // Not yet implemented - cid: { - save: true, - id: -1 - }, - password: { - save: true, - pass: "" - }, - passwordhoppie: { - save: true, - pass: "" - }, - currentInstalledAirac: 0, - version: "v1" -}; document.addEventListener('DOMContentLoaded', function() { // Seems to work (tm) firstStart(); }, false); -let systemsettings = "systemfile.json"; -let settings = "settings.json"; -var filepath = "F:\\02 Benutzer\\Chef\\Dokumente\\00 Git\\sectorfileupdater\\updater"; // Set to exe path ex: app.getPath('exe') + '\\' + systemsettings; -async function firstStart() { - // await ipcRenderer.send('app-path'); - // await ipcRenderer.on("app-path", async(event, path) => { - // filepath = path; - // }); - // await delay(2000); // Not the best solution - // filepath = await app.getPath('home') + '\\' + systemsettings; - await console.log(filepath + "\\" + systemsettings); - if (await fs.existsSync(filepath + "\\" + systemsettings)) { - systemstructure = JSON.parse(fs.readFileSync(filepath + "\\" + systemsettings, 'utf8')); - } else { - await changeUserpath(); - } - if (await fs.existsSync(systemstructure.path + "\\" + settings)) { - structure = JSON.parse(fs.readFileSync(systemstructure.path + "\\" + settings, 'utf8')); - if (structure.cid.save == true) { - usernameInput.value = structure.cid.id; - } - if (structure.password.save == true) { - passwordInput.value = structure.password.pass; - } - if (structure.passwordhoppie.save == true) { - passwordhoppieInput.value = structure.passwordhoppie.pass; - } - if (structure.cid.save == true) { - checkBoxUsername.checked = true; - } - if (structure.password.save == true) { - checkBoxPassword.checked = true; - } - if (structure.passwordhoppie.save == true) { - checkBoxSavepwhoppie.checked = true; - } - dirBox.value = systemstructure.path; - - } else { - fs.writeFileSync(systemstructure.path + "\\" + settings, JSON.stringify(structure, null, 4), 'utf8'); - gng.selectedIndex = structure.region; - if (files.selectedIndex < 0) { - files.selectedIndex = 0; - } else { - files.selectedIndex = structure.file; - } - // Broken - - } - await getUpdates(); - gng.selectedIndex = structure.region; - if (files.selectedIndex < 0) { - files.selectedIndex = 0; - } else { - files.selectedIndex = structure.file; - } - await getFiles(); - save(); -} // Save Event gng.addEventListener("change", () => { @@ -113,47 +19,6 @@ files.addEventListener("change", () => { save(); }); -function save() { - // WORK HERE, new files - // Read config - structure = JSON.parse(fs.readFileSync(systemstructure.path + "\\" + settings, 'utf8')); - structure.region = gng.selectedIndex; - structure.file = files.selectedIndex; - if (structure.file == -1) { - structure.file = 0; - } - if (checkBoxUsername.checked == true) { - structure.cid.id = usernameInput.value; - structure.cid.save = true; - } else { - structure.cid.id = -1; - structure.cid.save = false; - } - if (checkBoxPassword.checked == true) { - structure.password.pass = passwordInput.value; - structure.password.save = true; - } else { - structure.password.pass = ""; - structure.password.save = false; - } - if (checkBoxSavepwhoppie.checked == true) { - structure.passwordhoppie.pass = passwordhoppieInput.value; - structure.passwordhoppie.save = true; - } else { - structure.passwordhoppie.pass = ""; - structure.passwordhoppie.save = false; - } - // WIP - //structure.currentInstalledAirac = currentAirac; - //structure.version = airacversion; - // Save config - fs.writeFileSync(systemstructure.path + "\\" + settings, JSON.stringify(structure, null, 4), 'utf8'); -}; - -// Check update -let dropDownGNG = document.getElementById('gng'); -let dropDownFiles = document.getElementById('files'); - let updateBtn = document.getElementById('update'); updateBtn.addEventListener('click', () => { removeFileItems(); @@ -168,143 +33,6 @@ function removeFileItems() { } } -async function getUpdates() { - // Get all GNG Options - const courses = await superagent.get('https://files.aero-nav.com/'); - let text = courses.text.split("Download Pages").pop(); - let textArray = text.split("\n"); - let liste = ""; - let firstElement = ""; - let lastElement = ""; - textArray.forEach(element => { - if (element.includes(firstElement)) { - liste += element.substring( - element.indexOf(firstElement) + firstElement.length, - element.indexOf(lastElement, element.indexOf(firstElement))) + - "\n"; - } - }); - const listeArray = liste.split("\n"); - - // Add to html selector - listeArray.pop(); - listeArray.forEach(optionsAdd); - - // Add Elements to Drop Down - function optionsAdd(item) { - var option = document.createElement("option"); - option.text = item; - dropDownGNG.add(option); - } - getFiles(); -} - -async function getFiles() { - await removeFileItems(); - // Get all GNG Package Options - let region = "https://files.aero-nav.com/" + dropDownGNG.options[dropDownGNG.selectedIndex].text; - let courses = await superagent.get(region); - let text = courses.text.split("ReleasedDownload").pop(); - text = text.split("

AIRAC News

")[0]; - let rows = ""; - - for (var i = 0; i < text.length; i++) { - if (text[i] + text[i + 1] + text[i + 2] + text[i + 3] === "") { - let i2 = i + 4; - while (text[i2] + text[i2 + 1] + text[i2 + 2] + text[i2 + 3] + text[i2 + 4] !== "") { - rows += text[i2]; - i2++; - } - rows += "\n"; - } - } - //console.log(rows); // For debugging only - - // All Rows in Table - const listeArray = rows.split("\n"); - listeArray.pop(); - let fileNames = ""; - // Select only Package names - for (var i = 1; i < listeArray.length; i = i + 5) { - fileNames += listeArray[i] + "\n"; - } - const fileNamesArray = fileNames.split("\n"); - fileNamesArray.pop(); - - let firstElement = "href="; - let lastElement = "class="; - let hrefLinksList = ""; - for (var i = 4; i < listeArray.length; i = i + 5) { - hrefLinksList += listeArray[i].substring( - listeArray[i].indexOf(firstElement) + firstElement.length + 1, - listeArray[i].indexOf(lastElement) - 2) + "\n"; - } - const hrefLinksArray = hrefLinksList.split("\n"); - hrefLinksArray.pop(); - - removeFileItems(); - // Add Elements to Drop Down - for (let i = 0; i < fileNamesArray.length; i++) { - var option = document.createElement("option"); - option.text = fileNamesArray[i]; - option.href = hrefLinksArray[i]; - dropDownFiles.add(option); - } - if (structure.file != -1) { - dropDownFiles.selectedIndex = structure.file; - } - //files.selectedIndex = structure.file; - return hrefLinksArray; -} - - -function downloadFile(source, path) { - console.log(source) - const zipFile = source.split('/').pop(); - - superagent - .get(source).set("Referer", "http://files.aero-nav.com/") - .on('error', function(error) { - console.log(error); - }) - .pipe(fs.createWriteStream(path + "\\" + zipFile)) - .on('finish', function() { - // add code below to here - }); -} - -// Unzip file -function decompress(url, DESTINATION_PATH) { - let file = url.split('/').pop() - var ZIP_FILE_PATH = DESTINATION_PATH + "\\" + file; - DESTINATION_PATH += "\\" + file.split('.')[0]; - console.log(DESTINATION_PATH) - var unzipper = new DecompressZip(ZIP_FILE_PATH); - - // Add the error event listener - unzipper.on('error', function(err) { - console.log('Caught an error', err); - }); - - // Notify when everything is extracted - unzipper.on('extract', function(log) { - console.log('Finished extracting', log); - }); - - // Notify "progress" of the decompressed files - unzipper.on('progress', function(fileIndex, fileCount) { - document.getElementById('progressbar').value = (0.5 + ((fileIndex + 1) / fileCount) / 2) * 100 - console.log(0.5 + ((fileIndex + 1) / fileCount) / 2); - }); - - // Start extraction of the content - unzipper.extract({ - path: DESTINATION_PATH - }); -} - - - function changeUserpath() { ipcRenderer.send('app-path'); } @@ -331,8 +59,4 @@ testBtn.addEventListener('click', (e) => { var systemReadJson = JSON.parse(fs.readFileSync(systemsettings, 'utf8')); var userReadJson = JSON.parse(fs.readFileSync(systemReadJson.path + settings, 'utf8')); decompress(files.options[files.selectedIndex].href, systemReadJson.path) -}); - -saveCredBtn.addEventListener('click', (e) => { - save(); }); \ No newline at end of file diff --git a/updater/src/save.js b/updater/src/save.js new file mode 100644 index 0000000..4f6f817 --- /dev/null +++ b/updater/src/save.js @@ -0,0 +1,36 @@ +function save() { + // WORK HERE, new files + // Read config + structure = JSON.parse(fs.readFileSync(systemstructure.path + "\\" + settings, 'utf8')); + structure.region = gng.selectedIndex; + structure.file = files.selectedIndex; + if (structure.file == -1) { + structure.file = 0; + } + if (checkBoxUsername.checked == true) { + structure.cid.id = usernameInput.value; + structure.cid.save = true; + } else { + structure.cid.id = -1; + structure.cid.save = false; + } + if (checkBoxPassword.checked == true) { + structure.password.pass = passwordInput.value; + structure.password.save = true; + } else { + structure.password.pass = ""; + structure.password.save = false; + } + if (checkBoxSavepwhoppie.checked == true) { + structure.passwordhoppie.pass = passwordhoppieInput.value; + structure.passwordhoppie.save = true; + } else { + structure.passwordhoppie.pass = ""; + structure.passwordhoppie.save = false; + } + // WIP + //structure.currentInstalledAirac = currentAirac; + //structure.version = airacversion; + // Save config + fs.writeFileSync(systemstructure.path + "\\" + settings, JSON.stringify(structure, null, 4), 'utf8'); +}; \ No newline at end of file diff --git a/updater/src/startup.js b/updater/src/startup.js new file mode 100644 index 0000000..9894036 --- /dev/null +++ b/updater/src/startup.js @@ -0,0 +1,61 @@ +let systemsettings = "systemfile.json"; +let settings = "settings.json"; +var filepath = "F:\\02 Benutzer\\Chef\\Dokumente\\00 Git\\sectorfileupdater\\updater"; // Set to exe path ex: app.getPath('exe') + '\\' + systemsettings; +async function firstStart() { + // await ipcRenderer.send('app-path'); + // await ipcRenderer.on("app-path", async(event, path) => { + // filepath = path; + // }); + // await delay(2000); // Not the best solution + // filepath = await app.getPath('home') + '\\' + systemsettings; + await console.log(filepath + "\\" + systemsettings); + if (await fs.existsSync(filepath + "\\" + systemsettings)) { + systemstructure = JSON.parse(fs.readFileSync(filepath + "\\" + systemsettings, 'utf8')); + } else { + await changeUserpath(); + } + delay(100); + if (await fs.existsSync(systemstructure.path + "\\" + settings)) { + console.log(fs.readFileSync(systemstructure.path + "\\" + settings, 'utf8')); + structure = JSON.parse(await fs.readFileSync(systemstructure.path + "\\" + settings, 'utf8')); + if (structure.cid.save == true) { + usernameInput.value = structure.cid.id; + } + if (structure.password.save == true) { + passwordInput.value = structure.password.pass; + } + if (structure.passwordhoppie.save == true) { + passwordhoppieInput.value = structure.passwordhoppie.pass; + } + if (structure.cid.save == true) { + checkBoxUsername.checked = true; + } + if (structure.password.save == true) { + checkBoxPassword.checked = true; + } + if (structure.passwordhoppie.save == true) { + checkBoxSavepwhoppie.checked = true; + } + dirBox.value = systemstructure.path; + + } else { + fs.writeFileSync(systemstructure.path + "\\" + settings, JSON.stringify(structure, null, 4), 'utf8'); + gng.selectedIndex = structure.region; + if (files.selectedIndex < 0) { + files.selectedIndex = 0; + } else { + files.selectedIndex = structure.file; + } + // Broken + + } + await getUpdates(); + gng.selectedIndex = structure.region; + if (files.selectedIndex < 0) { + files.selectedIndex = 0; + } else { + files.selectedIndex = structure.file; + } + await getFiles(); + save(); +} \ No newline at end of file diff --git a/updater/src/unzip.js b/updater/src/unzip.js new file mode 100644 index 0000000..761fe9f --- /dev/null +++ b/updater/src/unzip.js @@ -0,0 +1,29 @@ +// Unzip file +function decompress(url, DESTINATION_PATH) { + let file = url.split('/').pop(); + var ZIP_FILE_PATH = DESTINATION_PATH + "\\" + file; + DESTINATION_PATH += "\\" + file.split('.')[0]; + console.log(DESTINATION_PATH); + var unzipper = new DecompressZip(ZIP_FILE_PATH); + + // Add the error event listener + unzipper.on('error', function(err) { + console.log('Caught an error', err); + }); + + // Notify when everything is extracted + unzipper.on('extract', function(log) { + console.log('Finished extracting', log); + }); + + // Notify "progress" of the decompressed files + unzipper.on('progress', function(fileIndex, fileCount) { + document.getElementById('progressbar').value = (0.5 + ((fileIndex + 1) / fileCount) / 2) * 100 + console.log(0.5 + ((fileIndex + 1) / fileCount) / 2); + }); + + // Start extraction of the content + unzipper.extract({ + path: DESTINATION_PATH + }); +} \ No newline at end of file diff --git a/updater/yarn.lock b/updater/yarn.lock index f7129b5..22bf0b6 100644 --- a/updater/yarn.lock +++ b/updater/yarn.lock @@ -303,6 +303,18 @@ "resolved" "https://registry.npmjs.org/@gar/promisify/-/promisify-1.1.3.tgz" "version" "1.1.3" +"@kwsites/file-exists@^1.1.1": + "integrity" "sha512-m9/5YGR18lIwxSFDwfE3oA7bWuq9kdau6ugN4H2rJeyhFQZcG9AgSHkQtSD15a8WvTgfz9aikZMrKPHvbpqFiw==" + "resolved" "https://registry.npmjs.org/@kwsites/file-exists/-/file-exists-1.1.1.tgz" + "version" "1.1.1" + dependencies: + "debug" "^4.1.1" + +"@kwsites/promise-deferred@^1.1.1": + "integrity" "sha512-GaHYm+c0O9MjZRu0ongGBRbinu8gVAMd2UZjji6jVmqKtZluZnptXGWhz1E8j8D2HJ3f/yMxKAUC0b+57wncIw==" + "resolved" "https://registry.npmjs.org/@kwsites/promise-deferred/-/promise-deferred-1.1.1.tgz" + "version" "1.1.1" + "@malept/cross-spawn-promise@^1.0.0": "integrity" "sha512-RTBGWL5FWQcg9orDOCcp4LvItNzUPcyEU9bwaeJX0rJ1IQxzucC48Y0/sQLp/g6t99IQgAlGIaesJS+gTn7tVQ==" "resolved" "https://registry.npmjs.org/@malept/cross-spawn-promise/-/cross-spawn-promise-1.1.1.tgz" @@ -3102,6 +3114,15 @@ "resolved" "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz" "version" "3.0.7" +"simple-git@^3.15.1": + "integrity" "sha512-73MVa5984t/JP4JcQt0oZlKGr42ROYWC3BcUZfuHtT3IHKPspIvL0cZBnvPXF7LL3S/qVeVHVdYYmJ3LOTw4Rg==" + "resolved" "https://registry.npmjs.org/simple-git/-/simple-git-3.15.1.tgz" + "version" "3.15.1" + dependencies: + "@kwsites/file-exists" "^1.1.1" + "@kwsites/promise-deferred" "^1.1.1" + "debug" "^4.3.4" + "smart-buffer@^4.2.0": "integrity" "sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg==" "resolved" "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz"