added install creds, fixed inserts into files

This commit is contained in:
PaulaBras 2023-01-17 14:05:21 +01:00
parent ca3e9f9c6f
commit 4d84d7a5f1
9 changed files with 85 additions and 94 deletions

View File

@ -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);
});
}
});
@ -24,3 +27,29 @@ 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);
}
});
});
}

View File

@ -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,

View File

@ -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}`);
}

View File

@ -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);
}

View File

@ -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');

View File

@ -19,7 +19,8 @@
<button id="download" style="display:block">Download Update</button>
<!-- <button id="download" style="display:none">Download Update</button> -->
<br>
<br> Apply to profile: <input type="checkbox" id="applyToPrf" /> Apply Hoppie Creds: <input type="checkbox" id="applyHoppie" />
<div id="login">
<select id="rating">
<option id="0">obs</option>
@ -35,15 +36,12 @@
</select>
<form>
<p>Realname</p>
<input type="text" id="realname" />
Realname: <input type="text" id="realname" />
<input type="checkbox" id="saverealname" />
<p>Username</p>
<input type="text" id="username" />
<br> Username: <input type="text" id="username" />
<input type="checkbox" id="saveuser" />
<div class="tooltip">
<p>Password</p>
<input type="password" id="password" />
<br> Password: <input type="password" id="password" />
<input type="checkbox" id="savepw" />
<span class="tooltiptext">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.</span>
</div>
<div class="tooltip">
<p>Password Hoppie</p>
<input type="password" id="passwordhoppie" />
<br>Password Hoppie: <input type="password" id="passwordhoppie" />
<input type="checkbox" id="savepwhoppie" />
<span class="tooltiptext">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

View File

@ -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();
});

View File

@ -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');
};

View File

@ -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();
// }