From 4d84d7a5f1ba0928953741ee35d9318b519f44f5 Mon Sep 17 00:00:00 2001 From: PaulaBras <68814660+PaulaBras@users.noreply.github.com> Date: Tue, 17 Jan 2023 14:05:21 +0100 Subject: [PATCH] added install creds, fixed inserts into files --- updater/src/append_to_file.js | 35 ++++++++++++++-- updater/src/data_structure.js | 2 +- updater/src/download.js | 27 +++++++++---- updater/src/git_ops.js | 8 +--- updater/src/html_elements.js | 2 + updater/src/index.html | 15 +++---- updater/src/renderer.js | 11 ++++- updater/src/save.js | 4 +- updater/src/startup.js | 75 +++++------------------------------ 9 files changed, 85 insertions(+), 94 deletions(-) diff --git a/updater/src/append_to_file.js b/updater/src/append_to_file.js index d6b2701..e12aec4 100644 --- a/updater/src/append_to_file.js +++ b/updater/src/append_to_file.js @@ -1,4 +1,6 @@ -function searchAndAppend(dir, data) { +let filesAppended = []; + +function searchAndAppendCredentials(dir, data) { var stringToAppend = `LastSession connecttype 0\nLastSession realname ${data[0]}\nLastSession certificate ${data[1]}\nLastSession password ${data[2]}\nLastSession rating ${data[3]}\nLastSession server AMSTERDAM\nLastSession tovatsim 1\n`; fs.readdir(dir, (err, files) => { if (err) throw err; @@ -12,10 +14,11 @@ function searchAndAppend(dir, data) { fs.readFile(filepath, 'utf8', (err, data) => { if (err) throw err; const lastLine = data.split('\n').slice(-2)[0]; - if (lastLine !== stringToAppend.split('\n').slice(-2)[0]) { + if (lastLine !== stringToAppend.split('\n').slice(-2)[0] && !filesAppended.includes(filepath)) { fs.appendFile(filepath, stringToAppend, (err) => { if (err) throw err; - console.log(`The following lines were appended to ${filepath}`); + // console.log(`The following lines were appended to ${filepath}`); + filesAppended.push(filepath); }); } }); @@ -23,4 +26,30 @@ function searchAndAppend(dir, data) { }); }); }); +} + +function searchAndInsertHoppie(directory) { + let files = []; + const targetFile = "TopSkyCPDLChoppieCode.txt"; + + function searchDir(dir) { + fs.readdirSync(dir).forEach(file => { + const filePath = path.join(dir, file); + const stat = fs.statSync(filePath); + if (stat.isDirectory()) { + search(filePath); + } else if (file === targetFile) { + files.push(filePath); + } + }); + } + search(directory); + + files.forEach(file => { + fs.writeFileSync(file, passwordhoppieInput.value, (err) => { + if (err) { + console.log(err); + } + }); + }); } \ No newline at end of file diff --git a/updater/src/data_structure.js b/updater/src/data_structure.js index 626b68a..16afc6b 100644 --- a/updater/src/data_structure.js +++ b/updater/src/data_structure.js @@ -5,7 +5,7 @@ var systemstructure = { var structure = { region: 0, file: 0, - installcreds: false, // Not yet implemented + installcreds: false, installhoppie: false, // Not yet implemented realname: { save: false, diff --git a/updater/src/download.js b/updater/src/download.js index d165106..675d10f 100644 --- a/updater/src/download.js +++ b/updater/src/download.js @@ -7,6 +7,7 @@ var region = ""; function downloadFile(source) { saveDownloadInfo(dropDownFiles.options[dropDownFiles.selectedIndex].version); let startpath = systemstructure.path; + createLocalStructure(startpath); airacversion = structure.currentInstalledAirac; releaseversion = structure.version; region = gng.options[gng.selectedIndex].text; @@ -35,14 +36,25 @@ function downloadFile(source) { }); request - .pipe(fs.createWriteStream(startpath + "\\" + zipFile)) + .pipe(fs.createWriteStream(`${startpath}/${zipFile}`)) .on('finish', function() { // Code to extract file - fs.createReadStream(startpath + "\\" + zipFile) + fs.createReadStream(`${startpath}/${zipFile}`) .pipe(unzipper.Extract({ path: `${startpath}/${region}/${airacversion}_v${releaseversion}` })) .on('finish', function() { - console.log("Decompressed successfully."); + // console.log("Decompressed successfully."); + fs.rename(`${startpath}/${zipFile}`, `${startpath}/zipfiles/${zipFile}`, (err) => { + if (err) throw err; + // console.log('File moved successfully.'); + }); compareFolders(templatePath, comparedPath, startpath); + + if (structure.installcreds == true) { + // realname, cert, pass, rating + data = [structure.realname.name, structure.cid.id, structure.password.pass, structure.rating]; + searchAndAppendCredentials(comparedPath, data); + } + if (structure.installhoppie == true) { searchAndInsertHoppie(comparedPath); } }); }); } @@ -53,12 +65,13 @@ function createFolder(folder) { } }; -function createLocalStructure() { +function createLocalStructure(startpath) { const airacversion = structure.currentInstalledAirac; const releaseversion = structure.version; const region = gng.options[gng.selectedIndex].text; - createFolder('config'); - createFolder(`${region}`); - createFolder(`${region}/${airacversion}_v${releaseversion}`); + createFolder(`${startpath}/config`); + createFolder(`${startpath}/zipfiles`); + createFolder(`${startpath}/${region}`); + createFolder(`${startpath}/${region}/${airacversion}_v${releaseversion}`); } \ No newline at end of file diff --git a/updater/src/git_ops.js b/updater/src/git_ops.js index a1c56c1..4b6de6d 100644 --- a/updater/src/git_ops.js +++ b/updater/src/git_ops.js @@ -1,6 +1,6 @@ const path = require('path'); -function compareFolders(templatePath, comparedPath, originalPath) { +function compareFolders(templatePath, comparedPath, originalPath, pathToAppend) { // get all files and directories in template folder const templateFiles = fs.readdirSync(templatePath, { withFileTypes: true }); // loop through each file/directory in template folder @@ -14,7 +14,7 @@ function compareFolders(templatePath, comparedPath, originalPath) { if (!fs.existsSync(comparedFilePath)) { fs.mkdirSync(comparedFilePath); } - compareFolders(templateFilePath, comparedFilePath, originalPath); + compareFolders(templateFilePath, comparedFilePath, originalPath, pathToAppend); } else { // check if the file exists in the compared folder if (!fs.existsSync(comparedFilePath)) { @@ -38,8 +38,4 @@ function compareFolders(templatePath, comparedPath, originalPath) { } } }); - - // realname, cert, pass, rating - data = [structure.realname.name, structure.cid.id, structure.password.pass, structure.rating]; - searchAndAppend(originalPath, data); } \ No newline at end of file diff --git a/updater/src/html_elements.js b/updater/src/html_elements.js index a31b48b..29d2bdc 100644 --- a/updater/src/html_elements.js +++ b/updater/src/html_elements.js @@ -15,6 +15,8 @@ let checkBoxUsername = document.getElementById('saveuser'); let checkBoxPassword = document.getElementById('savepw'); let checkBoxSavepwhoppie = document.getElementById('savepwhoppie'); let checkBoxRealname = document.getElementById('saverealname'); +let applyToPrf = document.getElementById('applyToPrf'); +let applyHoppie = document.getElementById('applyHoppie'); // Check update let dropDownGNG = document.getElementById('gng'); diff --git a/updater/src/index.html b/updater/src/index.html index c8fda27..5f559fd 100644 --- a/updater/src/index.html +++ b/updater/src/index.html @@ -19,7 +19,8 @@ -
+
Apply to profile: Apply Hoppie Creds: +
-

Realname

- + Realname: -

Username

- +
Username:
-

Password

- +
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 @@ -54,8 +52,7 @@ account.
-

Password Hoppie

- +
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 diff --git a/updater/src/renderer.js b/updater/src/renderer.js index ea3a9a8..3abc99b 100644 --- a/updater/src/renderer.js +++ b/updater/src/renderer.js @@ -53,7 +53,14 @@ ipcRenderer.on('progressbar', (event, args) => { progressbar.value = args.progress; }); -rating.addEventListener('click', (e) => { - structure.rating = rating.options[rating.selectedIndex].id; +rating.addEventListener('change', (e) => { + save(); +}); + +applyToPrf.addEventListener('click', (e) => { + save(); +}); + +applyHoppie.addEventListener('click', (e) => { save(); }); \ No newline at end of file diff --git a/updater/src/save.js b/updater/src/save.js index 56c5992..5dca169 100644 --- a/updater/src/save.js +++ b/updater/src/save.js @@ -35,9 +35,9 @@ function save() { structure.passwordhoppie.save = false; } structure.rating = rating.options[rating.selectedIndex].id; + structure.installcreds = applyToPrf.checked; + structure.installhoppie = applyHoppie.checked; // Save config - console.log("Saving config"); - console.log(systemstructure.path + "\\" + settings); fs.writeFileSync(systemstructure.path + "\\" + settings, JSON.stringify(structure, null, 4), 'utf8'); }; diff --git a/updater/src/startup.js b/updater/src/startup.js index 5ba00e1..26d2933 100644 --- a/updater/src/startup.js +++ b/updater/src/startup.js @@ -51,72 +51,19 @@ function updateUI() { checkBoxSavepwhoppie.checked = true; } dirBox.value = systemstructure.path; - // Set the rating WIP!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - var index = [...rating.options].findIndex(o => o.value == structure.rating); - if (index > -1) { - rating.options[index].selected = true; - } - gng.selectedIndex = structure.region; + const selectElement = document.getElementById("rating"); + const optionElement = document.getElementById(structure.rating); + selectElement.selectedIndex = optionElement.index; + + applyToPrf.checked = structure.applyToPrf; + applyHoppie.checked = structure.applyHoppie; + + dropDownGNG.selectedIndex = structure.region; + + // gng.selectedIndex = structure.region; if (files.selectedIndex < 0) { files.selectedIndex = 0; } else { files.selectedIndex = structure.file; } -} - -// 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; -// 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)) { -// 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 +} \ No newline at end of file