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:
+