const { ipcRenderer, app } = require('electron'); 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", () => { getFiles(); save(); }); 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(); getUpdates(); }); // Remove all files when changing Region --> WIP no nicht function removeFileItems() { var i, L = dropDownFiles.options.length - 1; for (i = L; i >= 0; i--) { dropDownFiles.remove(i); } } 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("Released