From 2a16b75c0ba02cb7fdf7eca42d573ce7417f4bdc Mon Sep 17 00:00:00 2001 From: PaulaBras <68814660+PaulaBras@users.noreply.github.com> Date: Fri, 7 Oct 2022 00:07:54 +0200 Subject: [PATCH] savefile, extract begin, select directory --- README.md | 12 +++--- updater/data-out.yaml | 8 ++++ updater/package-lock.json | 32 +++++++++++++- updater/package.json | 3 +- updater/programInternal.yaml | 1 + updater/sectorfileUpdater.yaml | 8 ++++ updater/src/index.html | 6 +-- updater/src/index.js | 79 ++++++++++++++++++++++++++++------ updater/src/preload.js | 10 ++++- updater/src/renderer.js | 32 +++++++------- updater/yarn.lock | 77 +++++++++++++++++++++------------ 11 files changed, 201 insertions(+), 67 deletions(-) create mode 100644 updater/data-out.yaml create mode 100644 updater/programInternal.yaml create mode 100644 updater/sectorfileUpdater.yaml diff --git a/README.md b/README.md index 3424077..9851343 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,12 @@ Dieses kleine Tool soll GNG Sector Müll beheben. Leider beschäftigt sich jeder * Select ES Folder * Version herausfinden / eingeben * Updates prüfen (file from Server mit Update Möglichkeiten) bspw (vonVersion-nachVersion): - * 2200-2201 - * 2200-2202 - * 2200-2203 - * 2200-2204 - * 2200-2205 - * 2200-2206 + * 2207-2201 + * 2207-2202 + * 2207-2203 + * 2207-2204 + * 2207-2205 + * 2207-2206 * Update herunterladen und enpacken * Hierbei werden neue und modifizierte Dateien verändert. (Erkannt wird das vorab mit einem Server script, welches die Fullpackes vergleicht und mittels git vergleicht. Einschränkung hier --diff-filter=ACRTUXBD) * Inline, wie bei Git ist hier nicht möglich, da nicht git vorrausgesetzt werden kann auf dem Zielcomputer diff --git a/updater/data-out.yaml b/updater/data-out.yaml new file mode 100644 index 0000000..40d0940 --- /dev/null +++ b/updater/data-out.yaml @@ -0,0 +1,8 @@ +cid: + save: true + id: 0 +password: + save: true + pass: NaN +customUrl: '' +currentInstalledAirac: 0 diff --git a/updater/package-lock.json b/updater/package-lock.json index 4f75100..e106112 100644 --- a/updater/package-lock.json +++ b/updater/package-lock.json @@ -12,7 +12,8 @@ "@octokit/core": "^4.0.5", "decompress-zip": "^0.3.3", "electron-dl": "^3.3.1", - "electron-squirrel-startup": "^1.0.0" + "electron-squirrel-startup": "^1.0.0", + "js-yaml": "^4.1.0" }, "devDependencies": { "@electron-forge/cli": "^6.0.0-beta.66", @@ -958,6 +959,11 @@ "safe-buffer": "~5.2.0" } }, + "node_modules/argparse": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==" + }, "node_modules/asar": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/asar/-/asar-3.2.0.tgz", @@ -4028,6 +4034,17 @@ "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", "dev": true }, + "node_modules/js-yaml": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", + "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", + "dependencies": { + "argparse": "^2.0.1" + }, + "bin": { + "js-yaml": "bin/js-yaml.js" + } + }, "node_modules/json-buffer": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz", @@ -7183,6 +7200,11 @@ } } }, + "argparse": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==" + }, "asar": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/asar/-/asar-3.2.0.tgz", @@ -9556,6 +9578,14 @@ "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", "dev": true }, + "js-yaml": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", + "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", + "requires": { + "argparse": "^2.0.1" + } + }, "json-buffer": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz", diff --git a/updater/package.json b/updater/package.json index 2f7f5d0..9af2e05 100644 --- a/updater/package.json +++ b/updater/package.json @@ -48,7 +48,8 @@ "@octokit/core": "^4.0.5", "decompress-zip": "^0.3.3", "electron-dl": "^3.3.1", - "electron-squirrel-startup": "^1.0.0" + "electron-squirrel-startup": "^1.0.0", + "js-yaml": "^4.1.0" }, "devDependencies": { "@electron-forge/cli": "^6.0.0-beta.66", diff --git a/updater/programInternal.yaml b/updater/programInternal.yaml new file mode 100644 index 0000000..534f448 --- /dev/null +++ b/updater/programInternal.yaml @@ -0,0 +1 @@ +folderPath: "C:\\Euroscope" \ No newline at end of file diff --git a/updater/sectorfileUpdater.yaml b/updater/sectorfileUpdater.yaml new file mode 100644 index 0000000..430a868 --- /dev/null +++ b/updater/sectorfileUpdater.yaml @@ -0,0 +1,8 @@ +cid: + save: true + id: 1467870 +password: + save: false + pass: "Testen123" +customUrl: "" +currentInstalledAirac: 2205 \ No newline at end of file diff --git a/updater/src/index.html b/updater/src/index.html index e1a4276..0a027a7 100644 --- a/updater/src/index.html +++ b/updater/src/index.html @@ -8,14 +8,14 @@ + +

Output Test here

Input URL

Input Directory

- - -

Output Test here

+ diff --git a/updater/src/index.js b/updater/src/index.js index 918c9d5..8264375 100644 --- a/updater/src/index.js +++ b/updater/src/index.js @@ -3,6 +3,8 @@ const { download } = require("electron-dl"); const path = require('path'); //Menu.setApplicationMenu(false); // Top Bar removal var fs = require('fs'); +const yaml = require('js-yaml'); +var DecompressZip = require('decompress-zip'); // Handle creating/removing shortcuts on Windows when installing/uninstalling. // eslint-disable-next-line global-require @@ -10,6 +12,22 @@ if (require('electron-squirrel-startup')) { app.quit(); } +var filepath; +let data = { + cid: { + save: true, + id: 0 + }, + password: { + save: true, + pass: "NaN" + }, + customUrl: "", + currentInstalledAirac: 0 +}; + + + const createWindow = () => { // Create the browser window. const mainWindow = new BrowserWindow({ @@ -25,13 +43,33 @@ const createWindow = () => { mainWindow.loadFile(path.join(__dirname, 'index.html')); mainWindow.webContents.openDevTools(); + // Read system yaml + try { + let fileContents = fs.readFileSync('sectorfileUpdater.yaml', 'utf8'); + filepath = yaml.load(fileContents).folderPath; + } catch (e) { + + } + // Read config yaml + try { + let fileContents = fs.readFileSync(filepath + 'sectorfileUpdater.yaml', 'utf8'); + data = yaml.load(fileContents); + + console.log(data); + console.log(data.cid.id); + } catch (e) { + console.log(e); + ipcRenderer.send("savefile", {}); + } + // Select Directory ipcMain.on('select-dirs', async(event, arg) => { - const result = await dialog.showOpenDialog(mainWindow, { + filepath = await dialog.showOpenDialog(mainWindow, { properties: ['openDirectory'] }) - console.log('directories selected', result.filePaths) - }) + console.log('directories selected', filepath.filePaths) + // Save directory to file + }); // Download a file ipcMain.on("download", (event, info) => { @@ -42,7 +80,31 @@ const createWindow = () => { }); + // Write to a file + ipcMain.on("saveFile", () => { + let yamlStr = yaml.dump(data); + fs.writeFileSync(filepath + 'sectorfileUpdater.yaml', yamlStr, 'utf8'); + }); + // Unzip content + ipcMain.on("extract", (event, directory) => { + console.log(directory.directoryPath); + var unzipper = new DecompressZip("F:\\Desktop.zip"); + console.log("Töfte querdrad"); + unzipper.extract({ + path: "F:\\test\\" // directory.directoryPath + }); + console.log("Töfte cubique"); + // Notify "progress" of the decompressed files + unzipper.on('progress', function(fileIndex, fileCount) { + console.log('Extracted file ' + (fileIndex + 1) + ' of ' + fileCount); + }); + // Notify when everything is extracted + unzipper.on('extract', function(log) { + console.log('Finished extracting', log); + }); + console.log("Töfte donna"); + }); }; @@ -59,6 +121,8 @@ app.on('ready', createWindow); // for applications and their menu bar to stay active until the user quits // explicitly with Cmd + Q. app.on('window-all-closed', () => { + let yamlStr = yaml.dump(data); + fs.writeFileSync('data-out.yaml', yamlStr, 'utf8'); if (process.platform !== 'darwin') { app.quit(); } @@ -70,13 +134,4 @@ app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) { createWindow(); } -}); - -// Write to a file -ipcMain.on("saveFile", (event, location, txtVal) => { - fs.writeFile(location, txtVal.toString(), (err) => { - if (!err) { console.log("File.written"); } else { - console.log(err); - } - }); }); \ No newline at end of file diff --git a/updater/src/preload.js b/updater/src/preload.js index c9c18e0..bebb932 100644 --- a/updater/src/preload.js +++ b/updater/src/preload.js @@ -1 +1,9 @@ -const { contextBridge, ipcRenderer } = require('electron') \ No newline at end of file +const { contextBridge, ipcRenderer } = require('electron') + +process.once('loaded', () => { + window.addEventListener('message', evt => { + if (evt.data.type === 'select-dirs') { + ipcRenderer.send('select-dirs') + } + }) +}) \ No newline at end of file diff --git a/updater/src/renderer.js b/updater/src/renderer.js index 051dd48..bf4bf2a 100644 --- a/updater/src/renderer.js +++ b/updater/src/renderer.js @@ -1,4 +1,5 @@ const { ipcRenderer, dialog } = require('electron'); +var DecompressZip = require('decompress-zip'); ipcRenderer.on("download complete", (event, file) => { console.log(file); // Full file path @@ -10,8 +11,8 @@ ipcRenderer.on("download progress", (event, progress) => { document.getElementById('progressbar').value = cleanProgressInPercentages; }); -let donwloadbtn = document.getElementById('download'); -donwloadbtn.addEventListener('click', (e) => { +let donwloadBtn = document.getElementById('download'); +donwloadBtn.addEventListener('click', (e) => { let directoryPath = document.getElementById('dirBox'); let urlPath = document.getElementById('urlBox'); ipcRenderer.send("download", { @@ -20,19 +21,20 @@ donwloadbtn.addEventListener('click', (e) => { }); }); - -document.addEventListener('DOMContentLoaded', function() { - document.getElementById('dirs').addEventListener('click', function() { - openFile(); - }); +let directoryBtn = document.getElementById('dirs'); +directoryBtn.addEventListener('click', (e) => { + window.postMessage({ + type: 'select-dirs' + }) }); -function openFile() { - ipcRenderer.send('openFolder', () => { - console.log("Event sent."); +let extractBtn = document.getElementById('extract'); +extractBtn.addEventListener('click', (e) => { + let directoryPath = document.getElementById('dirBox'); + let urlPath = document.getElementById('urlBox'); + ipcRenderer.send("extract", { + url: urlPath.value, + properties: { directory: directoryPath.value } }); -} - -ipcRenderer.on('folderData', (event, data) => { - console.log(data) -}) \ No newline at end of file + console.log("Töfte"); +}); \ No newline at end of file diff --git a/updater/yarn.lock b/updater/yarn.lock index 2a369d7..a23bc96 100644 --- a/updater/yarn.lock +++ b/updater/yarn.lock @@ -416,9 +416,9 @@ "universal-user-agent" "^6.0.0" "@octokit/openapi-types@^13.11.0": - "integrity" "sha512-1QYzZrwnn3rTQE7ZoSxXrO8lhu0aIbac1c+qIPOPEaVXBWSaUyLV1x9yt4uDQOwmu6u5ywVS8OJgs+ErDLf6vQ==" - "resolved" "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-13.12.0.tgz" - "version" "13.12.0" + "integrity" "sha512-4EuKSk3N95UBWFau3Bz9b3pheQ8jQYbKmBL5+GSuY8YDPDwu03J4BjI+66yNi8aaX/3h1qDpb0mbBkLdr+cfGQ==" + "resolved" "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-13.13.1.tgz" + "version" "13.13.1" "@octokit/request-error@^3.0.0": "integrity" "sha512-ym4Bp0HTP7F3VFssV88WD1ZyCIRoE8H35pXSKwLeMizcdZAYc/t6N9X9Yr9n6t3aG9IH75XDnZ6UeZph0vHMWQ==" @@ -442,9 +442,9 @@ "universal-user-agent" "^6.0.0" "@octokit/types@^7.0.0": - "integrity" "sha512-aHm+olfIZjQpzoODpl+RCZzchKOrdSLJs+yfI7pMMcmB19Li6vidgx0DwUDO/Ic4Q3fq/lOjJORVCcLZefcrJw==" - "resolved" "https://registry.npmjs.org/@octokit/types/-/types-7.5.0.tgz" - "version" "7.5.0" + "integrity" "sha512-Zk4OUMLCSpXNI8KZZn47lVLJSsgMyCimsWWQI5hyjZg7hdYm0kjotaIkbG0Pp8SfU2CofMBzonboTqvzn3FrJA==" + "resolved" "https://registry.npmjs.org/@octokit/types/-/types-7.5.1.tgz" + "version" "7.5.1" dependencies: "@octokit/openapi-types" "^13.11.0" @@ -520,9 +520,9 @@ "version" "5.1.2" "@types/node@*", "@types/node@^16.11.26": - "integrity" "sha512-6u+36Dj3aDzhfBVUf/mfmc92OEdzQ2kx2jcXGdigfl70E/neV21ZHE6UCz4MDzTRcVqGAM27fk+DLXvyDsn3Jw==" - "resolved" "https://registry.npmjs.org/@types/node/-/node-16.11.59.tgz" - "version" "16.11.59" + "integrity" "sha512-3OxnrEQLBz8EIIaHpg3CibmTAEGkDBcHY4fL5cnBwg2vd2yvHrUDGWxK+MlYPeXWWIoJJW79dGtU+oeBr6166Q==" + "resolved" "https://registry.npmjs.org/@types/node/-/node-16.11.63.tgz" + "version" "16.11.63" "@types/responselike@*", "@types/responselike@^1.0.0": "integrity" "sha512-85Y2BjiufFzaMIlvJDvTTB8Fxl2xfLo4HgmHzVBz08w4wDePCTjYw66PdrolO0kzli3yam/YCgRufyo1DdQVTA==" @@ -599,6 +599,11 @@ "delegates" "^1.0.0" "readable-stream" "^3.6.0" +"argparse@^2.0.1": + "integrity" "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==" + "resolved" "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz" + "version" "2.0.1" + "asar@^2.0.1": "integrity" "sha512-d2Ovma+bfqNpvBzY/KU8oPY67ZworixTpkjSx0PCXnQi67c2cXmssaTxpFDUM0ttopXoGx/KRxNg/GDThYbXQA==" "resolved" "https://registry.npmjs.org/asar/-/asar-2.1.0.tgz" @@ -853,13 +858,13 @@ "resolved" "https://registry.npmjs.org/cli-width/-/cli-width-3.0.0.tgz" "version" "3.0.0" -"cliui@^7.0.2": - "integrity" "sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==" - "resolved" "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz" - "version" "7.0.4" +"cliui@^8.0.1": + "integrity" "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==" + "resolved" "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz" + "version" "8.0.1" dependencies: "string-width" "^4.2.0" - "strip-ansi" "^6.0.0" + "strip-ansi" "^6.0.1" "wrap-ansi" "^7.0.0" "clone-response@^1.0.2": @@ -1961,6 +1966,13 @@ "resolved" "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz" "version" "2.0.0" +"js-yaml@^4.1.0": + "integrity" "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==" + "resolved" "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz" + "version" "4.1.0" + dependencies: + "argparse" "^2.0.1" + "json-buffer@3.0.0": "integrity" "sha512-CuUqjv0FUZIdXkHPI8MezCnFCdaTAacej1TZYulLoAg1h/PhwkdXFN4V/gzY4g+fMBCOV2xF+rp7t2XD2ns/NQ==" "resolved" "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.0.tgz" @@ -2323,9 +2335,9 @@ "version" "1.0.5" "node-abi@^3.0.0": - "integrity" "sha512-YPG3Co0luSu6GwOBsmIdGW6Wx0NyNDLg/hriIyDllVsNwnI6UeqaWShxC3lbH4LtEQUgoLP3XR1ndXiDAWvmRw==" - "resolved" "https://registry.npmjs.org/node-abi/-/node-abi-3.24.0.tgz" - "version" "3.24.0" + "integrity" "sha512-p+0xx5ruIQ+8X57CRIMxbTZRT7tU0Tjn2C/aAK68AEMrbGsCo6IjnDdPNhEyyjWCT4bRtzomXchYd3sSgk3BJQ==" + "resolved" "https://registry.npmjs.org/node-abi/-/node-abi-3.25.0.tgz" + "version" "3.25.0" dependencies: "semver" "^7.3.5" @@ -2767,7 +2779,16 @@ "isarray" "0.0.1" "string_decoder" "~0.10.x" -"readable-stream@^3.4.0", "readable-stream@^3.6.0": +"readable-stream@^3.4.0": + "integrity" "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==" + "resolved" "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz" + "version" "3.6.0" + dependencies: + "inherits" "^2.0.3" + "string_decoder" "^1.1.1" + "util-deprecate" "^1.0.1" + +"readable-stream@^3.6.0": "integrity" "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==" "resolved" "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz" "version" "3.6.0" @@ -2888,9 +2909,9 @@ "queue-microtask" "^1.2.2" "rxjs@^7.5.5": - "integrity" "sha512-dnyv2/YsXhnm461G+R/Pe5bWP41Nm6LBXEYWI6eiFP4fiwx6WRI/CD0zbdVAudd9xwLEF2IDcKXLHit0FYjUzw==" - "resolved" "https://registry.npmjs.org/rxjs/-/rxjs-7.5.6.tgz" - "version" "7.5.6" + "integrity" "sha512-z9MzKh/UcOqB3i20H6rtrlaE/CgjLOvheWK/9ILrbhROGTweAi1BaFsTT9FbwZi5Trr1qNRs+MXkhmR06awzQA==" + "resolved" "https://registry.npmjs.org/rxjs/-/rxjs-7.5.7.tgz" + "version" "7.5.7" dependencies: "tslib" "^2.1.0" @@ -2987,9 +3008,9 @@ "socks" "^2.6.2" "socks@^2.6.2": - "integrity" "sha512-scnOe9y4VuiNUULJN72GrM26BNOjVsfPXI+j+98PkyEfsIXroa5ofyjT+FzGvn/xHs73U2JtoBYAVx9Hl4quSA==" - "resolved" "https://registry.npmjs.org/socks/-/socks-2.7.0.tgz" - "version" "2.7.0" + "integrity" "sha512-7maUZy1N7uo6+WVEX6psASxtNlKaNVMlGQKkG/63nEDdLOWNbiUMoLK7X4uYoLhQstau72mLgfEWcXcwsaHbYQ==" + "resolved" "https://registry.npmjs.org/socks/-/socks-2.7.1.tgz" + "version" "2.7.1" dependencies: "ip" "^2.0.0" "smart-buffer" "^4.2.0" @@ -3398,11 +3419,11 @@ "version" "21.1.1" "yargs@^17.0.1": - "integrity" "sha512-t6YAJcxDkNX7NFYiVtKvWUz8l+PaKTLiL63mJYWR2GnHq2gjEWISzsLp9wg3aY36dY1j+gfIEL3pIF+XlJJfbA==" - "resolved" "https://registry.npmjs.org/yargs/-/yargs-17.5.1.tgz" - "version" "17.5.1" + "integrity" "sha512-8H/wTDqlSwoSnScvV2N/JHfLWOKuh5MVla9hqLjK3nsfyy6Y4kDSYSvkU5YCUEPOSnRXfIyx3Sq+B/IWudTo4g==" + "resolved" "https://registry.npmjs.org/yargs/-/yargs-17.6.0.tgz" + "version" "17.6.0" dependencies: - "cliui" "^7.0.2" + "cliui" "^8.0.1" "escalade" "^3.1.1" "get-caller-file" "^2.0.5" "require-directory" "^2.1.1"