mirror of
https://github.com/JustusPlays78/SectorFileUpdater.git
synced 2025-04-29 19:24:24 +00:00
added install creds, fixed inserts into files
This commit is contained in:
parent
ca3e9f9c6f
commit
4d84d7a5f1
@ -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`;
|
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) => {
|
fs.readdir(dir, (err, files) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
@ -12,10 +14,11 @@ function searchAndAppend(dir, data) {
|
|||||||
fs.readFile(filepath, 'utf8', (err, data) => {
|
fs.readFile(filepath, 'utf8', (err, data) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
const lastLine = data.split('\n').slice(-2)[0];
|
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) => {
|
fs.appendFile(filepath, stringToAppend, (err) => {
|
||||||
if (err) throw 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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
@ -5,7 +5,7 @@ var systemstructure = {
|
|||||||
var structure = {
|
var structure = {
|
||||||
region: 0,
|
region: 0,
|
||||||
file: 0,
|
file: 0,
|
||||||
installcreds: false, // Not yet implemented
|
installcreds: false,
|
||||||
installhoppie: false, // Not yet implemented
|
installhoppie: false, // Not yet implemented
|
||||||
realname: {
|
realname: {
|
||||||
save: false,
|
save: false,
|
||||||
|
@ -7,6 +7,7 @@ var region = "";
|
|||||||
function downloadFile(source) {
|
function downloadFile(source) {
|
||||||
saveDownloadInfo(dropDownFiles.options[dropDownFiles.selectedIndex].version);
|
saveDownloadInfo(dropDownFiles.options[dropDownFiles.selectedIndex].version);
|
||||||
let startpath = systemstructure.path;
|
let startpath = systemstructure.path;
|
||||||
|
createLocalStructure(startpath);
|
||||||
airacversion = structure.currentInstalledAirac;
|
airacversion = structure.currentInstalledAirac;
|
||||||
releaseversion = structure.version;
|
releaseversion = structure.version;
|
||||||
region = gng.options[gng.selectedIndex].text;
|
region = gng.options[gng.selectedIndex].text;
|
||||||
@ -35,14 +36,25 @@ function downloadFile(source) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
request
|
request
|
||||||
.pipe(fs.createWriteStream(startpath + "\\" + zipFile))
|
.pipe(fs.createWriteStream(`${startpath}/${zipFile}`))
|
||||||
.on('finish', function() {
|
.on('finish', function() {
|
||||||
// Code to extract file
|
// Code to extract file
|
||||||
fs.createReadStream(startpath + "\\" + zipFile)
|
fs.createReadStream(`${startpath}/${zipFile}`)
|
||||||
.pipe(unzipper.Extract({ path: `${startpath}/${region}/${airacversion}_v${releaseversion}` }))
|
.pipe(unzipper.Extract({ path: `${startpath}/${region}/${airacversion}_v${releaseversion}` }))
|
||||||
.on('finish', function() {
|
.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);
|
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 airacversion = structure.currentInstalledAirac;
|
||||||
const releaseversion = structure.version;
|
const releaseversion = structure.version;
|
||||||
const region = gng.options[gng.selectedIndex].text;
|
const region = gng.options[gng.selectedIndex].text;
|
||||||
|
|
||||||
createFolder('config');
|
createFolder(`${startpath}/config`);
|
||||||
createFolder(`${region}`);
|
createFolder(`${startpath}/zipfiles`);
|
||||||
createFolder(`${region}/${airacversion}_v${releaseversion}`);
|
createFolder(`${startpath}/${region}`);
|
||||||
|
createFolder(`${startpath}/${region}/${airacversion}_v${releaseversion}`);
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
function compareFolders(templatePath, comparedPath, originalPath) {
|
function compareFolders(templatePath, comparedPath, originalPath, pathToAppend) {
|
||||||
// get all files and directories in template folder
|
// get all files and directories in template folder
|
||||||
const templateFiles = fs.readdirSync(templatePath, { withFileTypes: true });
|
const templateFiles = fs.readdirSync(templatePath, { withFileTypes: true });
|
||||||
// loop through each file/directory in template folder
|
// loop through each file/directory in template folder
|
||||||
@ -14,7 +14,7 @@ function compareFolders(templatePath, comparedPath, originalPath) {
|
|||||||
if (!fs.existsSync(comparedFilePath)) {
|
if (!fs.existsSync(comparedFilePath)) {
|
||||||
fs.mkdirSync(comparedFilePath);
|
fs.mkdirSync(comparedFilePath);
|
||||||
}
|
}
|
||||||
compareFolders(templateFilePath, comparedFilePath, originalPath);
|
compareFolders(templateFilePath, comparedFilePath, originalPath, pathToAppend);
|
||||||
} else {
|
} else {
|
||||||
// check if the file exists in the compared folder
|
// check if the file exists in the compared folder
|
||||||
if (!fs.existsSync(comparedFilePath)) {
|
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);
|
|
||||||
}
|
}
|
@ -15,6 +15,8 @@ let checkBoxUsername = document.getElementById('saveuser');
|
|||||||
let checkBoxPassword = document.getElementById('savepw');
|
let checkBoxPassword = document.getElementById('savepw');
|
||||||
let checkBoxSavepwhoppie = document.getElementById('savepwhoppie');
|
let checkBoxSavepwhoppie = document.getElementById('savepwhoppie');
|
||||||
let checkBoxRealname = document.getElementById('saverealname');
|
let checkBoxRealname = document.getElementById('saverealname');
|
||||||
|
let applyToPrf = document.getElementById('applyToPrf');
|
||||||
|
let applyHoppie = document.getElementById('applyHoppie');
|
||||||
|
|
||||||
// Check update
|
// Check update
|
||||||
let dropDownGNG = document.getElementById('gng');
|
let dropDownGNG = document.getElementById('gng');
|
||||||
|
@ -19,7 +19,8 @@
|
|||||||
<button id="download" style="display:block">Download Update</button>
|
<button id="download" style="display:block">Download Update</button>
|
||||||
<!-- <button id="download" style="display:none">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">
|
<div id="login">
|
||||||
<select id="rating">
|
<select id="rating">
|
||||||
<option id="0">obs</option>
|
<option id="0">obs</option>
|
||||||
@ -35,15 +36,12 @@
|
|||||||
</select>
|
</select>
|
||||||
|
|
||||||
<form>
|
<form>
|
||||||
<p>Realname</p>
|
Realname: <input type="text" id="realname" />
|
||||||
<input type="text" id="realname" />
|
|
||||||
<input type="checkbox" id="saverealname" />
|
<input type="checkbox" id="saverealname" />
|
||||||
<p>Username</p>
|
<br> Username: <input type="text" id="username" />
|
||||||
<input type="text" id="username" />
|
|
||||||
<input type="checkbox" id="saveuser" />
|
<input type="checkbox" id="saveuser" />
|
||||||
<div class="tooltip">
|
<div class="tooltip">
|
||||||
<p>Password</p>
|
<br> Password: <input type="password" id="password" />
|
||||||
<input type="password" id="password" />
|
|
||||||
<input type="checkbox" id="savepw" />
|
<input type="checkbox" id="savepw" />
|
||||||
<span class="tooltiptext">Please be aware that the password you enter will be stored in plain
|
<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
|
text in our system. This means that it will not be encrypted or
|
||||||
@ -54,8 +52,7 @@
|
|||||||
account.</span>
|
account.</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="tooltip">
|
<div class="tooltip">
|
||||||
<p>Password Hoppie</p>
|
<br>Password Hoppie: <input type="password" id="passwordhoppie" />
|
||||||
<input type="password" id="passwordhoppie" />
|
|
||||||
<input type="checkbox" id="savepwhoppie" />
|
<input type="checkbox" id="savepwhoppie" />
|
||||||
<span class="tooltiptext">Please be aware that the password you enter will be stored in plain
|
<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
|
text in our system. This means that it will not be encrypted or
|
||||||
|
@ -53,7 +53,14 @@ ipcRenderer.on('progressbar', (event, args) => {
|
|||||||
progressbar.value = args.progress;
|
progressbar.value = args.progress;
|
||||||
});
|
});
|
||||||
|
|
||||||
rating.addEventListener('click', (e) => {
|
rating.addEventListener('change', (e) => {
|
||||||
structure.rating = rating.options[rating.selectedIndex].id;
|
save();
|
||||||
|
});
|
||||||
|
|
||||||
|
applyToPrf.addEventListener('click', (e) => {
|
||||||
|
save();
|
||||||
|
});
|
||||||
|
|
||||||
|
applyHoppie.addEventListener('click', (e) => {
|
||||||
save();
|
save();
|
||||||
});
|
});
|
@ -35,9 +35,9 @@ function save() {
|
|||||||
structure.passwordhoppie.save = false;
|
structure.passwordhoppie.save = false;
|
||||||
}
|
}
|
||||||
structure.rating = rating.options[rating.selectedIndex].id;
|
structure.rating = rating.options[rating.selectedIndex].id;
|
||||||
|
structure.installcreds = applyToPrf.checked;
|
||||||
|
structure.installhoppie = applyHoppie.checked;
|
||||||
// Save config
|
// Save config
|
||||||
console.log("Saving config");
|
|
||||||
console.log(systemstructure.path + "\\" + settings);
|
|
||||||
fs.writeFileSync(systemstructure.path + "\\" + settings, JSON.stringify(structure, null, 4), 'utf8');
|
fs.writeFileSync(systemstructure.path + "\\" + settings, JSON.stringify(structure, null, 4), 'utf8');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -51,72 +51,19 @@ function updateUI() {
|
|||||||
checkBoxSavepwhoppie.checked = true;
|
checkBoxSavepwhoppie.checked = true;
|
||||||
}
|
}
|
||||||
dirBox.value = systemstructure.path;
|
dirBox.value = systemstructure.path;
|
||||||
// Set the rating WIP!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
const selectElement = document.getElementById("rating");
|
||||||
var index = [...rating.options].findIndex(o => o.value == structure.rating);
|
const optionElement = document.getElementById(structure.rating);
|
||||||
if (index > -1) {
|
selectElement.selectedIndex = optionElement.index;
|
||||||
rating.options[index].selected = true;
|
|
||||||
}
|
applyToPrf.checked = structure.applyToPrf;
|
||||||
gng.selectedIndex = structure.region;
|
applyHoppie.checked = structure.applyHoppie;
|
||||||
|
|
||||||
|
dropDownGNG.selectedIndex = structure.region;
|
||||||
|
|
||||||
|
// gng.selectedIndex = structure.region;
|
||||||
if (files.selectedIndex < 0) {
|
if (files.selectedIndex < 0) {
|
||||||
files.selectedIndex = 0;
|
files.selectedIndex = 0;
|
||||||
} else {
|
} else {
|
||||||
files.selectedIndex = structure.file;
|
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();
|
|
||||||
// }
|
|
Loading…
x
Reference in New Issue
Block a user