mirror of
https://github.com/JustusPlays78/SectorFileUpdater.git
synced 2025-06-28 04:55:16 +00:00
rework everything, testing session add
This commit is contained in:
26
updater/src/append_to_file.js
Normal file
26
updater/src/append_to_file.js
Normal file
@ -0,0 +1,26 @@
|
||||
function searchAndAppend(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;
|
||||
files.forEach(file => {
|
||||
const filepath = path.join(dir, file);
|
||||
fs.stat(filepath, (err, stat) => {
|
||||
if (err) throw err;
|
||||
if (stat.isDirectory()) {
|
||||
searchAndAppend(filepath, data);
|
||||
} else if (path.extname(file) === '.prf') {
|
||||
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]) {
|
||||
fs.appendFile(filepath, stringToAppend, (err) => {
|
||||
if (err) throw err;
|
||||
console.log(`The following lines were appended to ${filepath}`);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
@ -7,18 +7,23 @@ var structure = {
|
||||
file: 0,
|
||||
installcreds: false, // Not yet implemented
|
||||
installhoppie: false, // Not yet implemented
|
||||
realname: {
|
||||
save: false,
|
||||
name: ""
|
||||
},
|
||||
cid: {
|
||||
save: true,
|
||||
save: false,
|
||||
id: -1
|
||||
},
|
||||
password: {
|
||||
save: true,
|
||||
save: false,
|
||||
pass: ""
|
||||
},
|
||||
passwordhoppie: {
|
||||
save: true,
|
||||
save: false,
|
||||
pass: ""
|
||||
},
|
||||
rating: 0,
|
||||
currentInstalledAirac: 0,
|
||||
version: "v1"
|
||||
version: "1"
|
||||
};
|
@ -1,15 +1,49 @@
|
||||
function downloadFile(source, path) {
|
||||
console.log(source);
|
||||
const zipFile = source.split('/').pop();
|
||||
const unzipper = require('unzipper');
|
||||
|
||||
superagent
|
||||
.get(source).set("Referer", "http://files.aero-nav.com/")
|
||||
var airacversion = "";
|
||||
var releaseversion = "";
|
||||
var region = "";
|
||||
|
||||
function downloadFile(source) {
|
||||
saveDownloadInfo(dropDownFiles.options[dropDownFiles.selectedIndex].version);
|
||||
let startpath = systemstructure.path;
|
||||
airacversion = structure.currentInstalledAirac;
|
||||
releaseversion = structure.version;
|
||||
region = gng.options[gng.selectedIndex].text;
|
||||
const zipFile = source.split('/').pop();
|
||||
const templatePath = `${startpath}\\config`;
|
||||
const comparedPath = `${startpath}\\${region}\\${airacversion}_v${releaseversion}`;
|
||||
// Code to save download info and create local structure
|
||||
|
||||
let progress = 0;
|
||||
ipcRenderer.send('download-progress', { progress });
|
||||
|
||||
const request = superagent
|
||||
.get(source)
|
||||
.set("Referer", "http://files.aero-nav.com/")
|
||||
.on('error', function(error) {
|
||||
console.log(error);
|
||||
})
|
||||
.pipe(fs.createWriteStream(path + "\\" + zipFile))
|
||||
});
|
||||
|
||||
request.on('response', res => {
|
||||
const total = parseInt(res.headers['content-length'], 10);
|
||||
res.on('data', chunk => {
|
||||
progress += chunk.length;
|
||||
const percent = (progress / total * 100).toFixed(2);
|
||||
ipcRenderer.send('download-progress', { progress: percent });
|
||||
});
|
||||
});
|
||||
|
||||
request
|
||||
.pipe(fs.createWriteStream(startpath + "\\" + zipFile))
|
||||
.on('finish', function() {
|
||||
// add code below to here
|
||||
// Code to extract file
|
||||
fs.createReadStream(startpath + "\\" + zipFile)
|
||||
.pipe(unzipper.Extract({ path: `${startpath}/${region}/${airacversion}_v${releaseversion}` }))
|
||||
.on('finish', function() {
|
||||
console.log("Decompressed successfully.");
|
||||
compareFolders(templatePath, comparedPath, startpath);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@ -17,4 +51,14 @@ function createFolder(folder) {
|
||||
if (!fs.existsSync(folder)) {
|
||||
fs.mkdirSync(folder);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
function createLocalStructure() {
|
||||
const airacversion = structure.currentInstalledAirac;
|
||||
const releaseversion = structure.version;
|
||||
const region = gng.options[gng.selectedIndex].text;
|
||||
|
||||
createFolder('config');
|
||||
createFolder(`${region}`);
|
||||
createFolder(`${region}/${airacversion}_v${releaseversion}`);
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
async function getUpdates() {
|
||||
const courses = await superagent.get('https://files.aero-nav.com/');
|
||||
let text = courses.text.match(/Download Pages([^]*?)<\/body>/g);
|
||||
console.log(text);
|
||||
let liste = text[0].match(/<b>(.*?)<\/b>/g).map(item => item.replace(/<\/?b>/g, ""));
|
||||
|
||||
liste.forEach(item => {
|
||||
@ -14,6 +13,7 @@ async function getUpdates() {
|
||||
|
||||
|
||||
async function getFiles() {
|
||||
await delay(300)
|
||||
await removeFileItems();
|
||||
let region = "https://files.aero-nav.com/" + dropDownGNG.options[dropDownGNG.selectedIndex].text;
|
||||
let courses = await superagent.get(region);
|
||||
@ -22,19 +22,29 @@ async function getFiles() {
|
||||
let rows = text.match(/<td>(.*?)<\/td>/g).map(row => row.replace(/<\/?td>/g, ""));
|
||||
|
||||
let fileNames = rows.filter((row, index) => index % 5 === 1);
|
||||
let versionNumbers = rows.filter((row, index) => index % 5 === 2);
|
||||
let versionNumbers = rows.filter((row, index) => index % 5 === 2).map(versionNumber => versionNumber.split('/').map(e => e.trim()));
|
||||
let hrefLinks = rows.filter((row, index) => index % 5 === 4).map(row => row.match(/href="(.*?)"/)[1]);
|
||||
|
||||
let data = fileNames.map((fileName, index) => [fileName, versionNumbers[index], hrefLinks[index]]);
|
||||
|
||||
removeFileItems();
|
||||
fileNames.forEach((fileName, index) => {
|
||||
data.forEach(row => {
|
||||
let option = document.createElement("option");
|
||||
option.text = fileName;
|
||||
option.version = versionNumbers[index];
|
||||
option.href = hrefLinks[index];
|
||||
option.text = row[0];
|
||||
option.version = row[1];
|
||||
option.href = row[2];
|
||||
dropDownFiles.add(option);
|
||||
});
|
||||
|
||||
if (structure.file != -1) {
|
||||
dropDownFiles.selectedIndex = structure.file;
|
||||
}
|
||||
|
||||
if (structure.currentInstalledAirac !== dropDownFiles.options[dropDownFiles.selectedIndex].version[0] ||
|
||||
structure.version !== dropDownFiles.options[dropDownFiles.selectedIndex].version[1]) {
|
||||
document.getElementById("download").style.display = "block";
|
||||
}
|
||||
|
||||
save();
|
||||
return hrefLinks;
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
const path = require('path');
|
||||
|
||||
function compareFolders(templatePath, comparedPath, originalPath) {
|
||||
// get all files and directories in template folder
|
||||
const templateFiles = fs.readdirSync(templatePath, { withFileTypes: true });
|
||||
// loop through each file/directory in template folder
|
||||
templateFiles.forEach(file => {
|
||||
// create the full path for the current file/directory
|
||||
const templateFilePath = path.join(templatePath, file.name);
|
||||
const comparedFilePath = path.join(comparedPath, file.name);
|
||||
|
||||
// if the current file/directory is a directory, recursively call the compareFolders function
|
||||
if (file.isDirectory()) {
|
||||
if (!fs.existsSync(comparedFilePath)) {
|
||||
fs.mkdirSync(comparedFilePath);
|
||||
}
|
||||
compareFolders(templateFilePath, comparedFilePath, originalPath);
|
||||
} else {
|
||||
// check if the file exists in the compared folder
|
||||
if (!fs.existsSync(comparedFilePath)) {
|
||||
// if it doesn't exist, copy the file from the template folder
|
||||
fs.copyFileSync(templateFilePath, comparedFilePath);
|
||||
} else {
|
||||
// if it exists, compare the contents of the file
|
||||
let templateFileContent = fs.readFileSync(templateFilePath);
|
||||
let comparedFileContent = fs.readFileSync(comparedFilePath);
|
||||
if (templateFileContent.equals(comparedFileContent)) {
|
||||
// if the contents are the same, don't copy the file
|
||||
} else {
|
||||
// if the contents are different, copy the file from the template folder
|
||||
fs.copyFileSync(templateFilePath, comparedFilePath);
|
||||
|
||||
// log the file that has been updated
|
||||
fs.appendFile(originalPath + "\\update.log", templateFilePath + " has been updated \n", (err) => {
|
||||
if (err) throw err;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// realname, cert, pass, rating
|
||||
data = [structure.realname.name, structure.cid.id, structure.password.pass, structure.rating];
|
||||
searchAndAppend(originalPath, data);
|
||||
}
|
@ -1,14 +1,20 @@
|
||||
// Global Variabels
|
||||
let selectDirBtn = document.getElementById('select-dir');
|
||||
let dirBox = document.getElementById('dirBox');
|
||||
let usernameInput = document.getElementById('username');
|
||||
let passwordInput = document.getElementById('password');
|
||||
let passwordhoppieInput = document.getElementById('passwordhoppie');
|
||||
let realnameInput = document.getElementById('realname');
|
||||
let saveCredBtn = document.getElementById('savecred');
|
||||
let rating = document.getElementById('rating');
|
||||
let progressbar = document.getElementById('progressbar');
|
||||
let downloadBtn = document.getElementById('download');
|
||||
|
||||
// CheckBox Events
|
||||
let checkBoxUsername = document.getElementById('saveuser');
|
||||
let checkBoxPassword = document.getElementById('savepw');
|
||||
let checkBoxSavepwhoppie = document.getElementById('savepwhoppie');
|
||||
let checkBoxRealname = document.getElementById('saverealname');
|
||||
|
||||
// Check update
|
||||
let dropDownGNG = document.getElementById('gng');
|
||||
@ -16,4 +22,8 @@ let dropDownFiles = document.getElementById('files');
|
||||
|
||||
saveCredBtn.addEventListener('click', (e) => {
|
||||
save();
|
||||
});
|
||||
|
||||
selectDirBtn.addEventListener('click', (e) => {
|
||||
changeUserpath();
|
||||
});
|
@ -8,57 +8,95 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<button id="extract">Extract ZIP</button>
|
||||
<p>Input Directory</p>
|
||||
<button id="select-dir">Select Directory</button>
|
||||
<input type="text" id="dirBox" name="name" size="80" readonly />
|
||||
<progress id="progressbar" max="100" value="0"></progress>
|
||||
|
||||
<button id="update">Check for update</button>
|
||||
|
||||
<p id="progressbarText"></p>
|
||||
<br>
|
||||
<select id="gng"></select>
|
||||
<select id="files"></select>
|
||||
|
||||
<button id="test">Test BTN</button>
|
||||
<button id="download" style="display:block">Download Update</button>
|
||||
<!-- <button id="download" style="display:none">Download Update</button> -->
|
||||
|
||||
<br>
|
||||
<div id="login">
|
||||
<p>Username</p>
|
||||
<input type="text" id="username" />
|
||||
<input type="checkbox" id="saveuser" />
|
||||
<div class="tooltip">
|
||||
<p>Password</p>
|
||||
<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
|
||||
otherwise secured. We recommend that you do not use a password that
|
||||
you also use for other important accounts, such as your email or
|
||||
banking. Please use caution when entering your password and consider
|
||||
using a unique and strong password specifically for this
|
||||
account.</span>
|
||||
</div>
|
||||
<div class="tooltip">
|
||||
<p>Password Hoppie</p>
|
||||
<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
|
||||
otherwise secured. We recommend that you do not use a password that
|
||||
you also use for other important accounts, such as your email or
|
||||
banking. Please use caution when entering your password and consider
|
||||
using a unique and strong password specifically for this
|
||||
account.</span>
|
||||
</div>
|
||||
<button id="savecred">Save your Credentials</button>
|
||||
<select id="rating">
|
||||
<option id="0">obs</option>
|
||||
<option id="1">s1</option>
|
||||
<option id="2">s2</option>
|
||||
<option id="3">s3</option>
|
||||
<option id="4">c1</option>
|
||||
<option id="6">c3</option>
|
||||
<option id="7">i1</option>
|
||||
<option id="9">i3</option>
|
||||
<option id="10">sup</option>
|
||||
<option id="11">adm</option>
|
||||
</select>
|
||||
|
||||
<form>
|
||||
<p>Realname</p>
|
||||
<input type="text" id="realname" />
|
||||
<input type="checkbox" id="saverealname" />
|
||||
<p>Username</p>
|
||||
<input type="text" id="username" />
|
||||
<input type="checkbox" id="saveuser" />
|
||||
<div class="tooltip">
|
||||
<p>Password</p>
|
||||
<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
|
||||
otherwise secured. We recommend that you do not use a password that
|
||||
you also use for other important accounts, such as your email or
|
||||
banking. Please use caution when entering your password and consider
|
||||
using a unique and strong password specifically for this
|
||||
account.</span>
|
||||
</div>
|
||||
<div class="tooltip">
|
||||
<p>Password Hoppie</p>
|
||||
<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
|
||||
otherwise secured. We recommend that you do not use a password that
|
||||
you also use for other important accounts, such as your email or
|
||||
banking. Please use caution when entering your password and consider
|
||||
using a unique and strong password specifically for this
|
||||
account.</span>
|
||||
</div>
|
||||
<button id="savecred">Save your Credentials</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<script src="./renderer.js"></script>
|
||||
<form>
|
||||
If you want Eurosounds, please check the box below and click the download button. <br>
|
||||
<input type="checkbox" id="download-checkbox" onclick="toggleDownloadButton()"> I confirm that I would like to download the file.
|
||||
<br>
|
||||
<a href="https://cdn.ganderoceanic.ca/resources/files/eurosounds/eurosounds-8apr20.zip" id="download-link" style="display:none">Download</a>
|
||||
</form>
|
||||
<script>
|
||||
function toggleDownloadButton() {
|
||||
const downloadLink = document.getElementById("download-link");
|
||||
if (document.getElementById("download-checkbox").checked) {
|
||||
downloadLink.style.display = "block";
|
||||
} else {
|
||||
downloadLink.style.display = "none";
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
<script src="./html_elements.js"></script>
|
||||
<script src="./renderer.js"></script>
|
||||
<script src="./startup.js"></script>
|
||||
<script src="./save.js"></script>
|
||||
<script src="./getFiles.js"></script>
|
||||
<script src="./unzip.js"></script>
|
||||
<script src="./data_structure.js"></script>
|
||||
<script src="./download.js"></script>
|
||||
<script src="./git_ops.js"></script>
|
||||
<script src="./append_to_file.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
@ -1,14 +1,6 @@
|
||||
const { app, BrowserWindow, dialog, ipcMain } = require('electron');
|
||||
const { download } = require("electron-dl");
|
||||
const path = require('path');
|
||||
//Menu.setApplicationMenu(false); // Top Bar removal
|
||||
var fs = require('fs');
|
||||
const yaml = require('js-yaml');
|
||||
var DecompressZip = require('decompress-zip');
|
||||
const { Http2ServerRequest } = require('http2');
|
||||
const superagent = require('superagent').agent();
|
||||
const http = require('node:http');
|
||||
const { options } = require('superagent');
|
||||
|
||||
// Handle creating/removing shortcuts on Windows when installing/uninstalling.
|
||||
// eslint-disable-next-line global-require
|
||||
@ -16,13 +8,6 @@ if (require('electron-squirrel-startup')) {
|
||||
app.quit();
|
||||
}
|
||||
|
||||
var filepath;
|
||||
let data = {
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
const createWindow = () => {
|
||||
// Create the browser window.
|
||||
const mainWindow = new BrowserWindow({
|
||||
@ -37,80 +22,16 @@ const createWindow = () => {
|
||||
});
|
||||
mainWindow.loadFile(path.join(__dirname, 'index.html'));
|
||||
mainWindow.webContents.openDevTools();
|
||||
/*
|
||||
// Read system yaml
|
||||
try {
|
||||
let fileContents = fs.readFileSync('sectorfileUpdater.yaml', 'utf8');
|
||||
filepath = yaml.load(fileContents).folderPath;
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
// Read config yaml
|
||||
try {
|
||||
let fileContents = fs.readFileSync(filepath + 'sectorfileUpdater.yaml', 'utf8');
|
||||
data = yaml.load(fileContents);
|
||||
|
||||
console.log(data);
|
||||
console.log(data.cid.id);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
ipcRenderer.send("savefile", {});
|
||||
}*/
|
||||
|
||||
// Select Directory
|
||||
ipcMain.on('app-path', async(event, arg) => {
|
||||
filepath = await dialog.showOpenDialog(mainWindow, {
|
||||
properties: ['openDirectory']
|
||||
});
|
||||
mainWindow.webContents.send("app-path", filepath.filePaths);
|
||||
mainWindow.webContents.send("app-dest", filepath.filePaths);
|
||||
// Save directory to file
|
||||
});
|
||||
|
||||
// Download a file
|
||||
ipcMain.on("download", (event, info) => {
|
||||
// https://dms.pabr.de/s/SpBiQYADTNak7R5/download
|
||||
info.properties.onProgress = status => mainWindow.webContents.send("download progress", status);
|
||||
// http.request
|
||||
let file = superagent.get('https://files.aero-nav.com/EDGG/Full_Package_20221104183433-221101-3.zip')
|
||||
.set('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0')
|
||||
.set('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8')
|
||||
.set('Accept-Language', 'en-US,en;q=0.5')
|
||||
.set('Accept-Encoding', 'gzip, deflate, br')
|
||||
.set('DNT', '1')
|
||||
.set('Connection', 'keep-alive')
|
||||
.set('Referer', 'http://files.aero-nav.com/')
|
||||
.set('Upgrade-Insecure-Requests', '1')
|
||||
.set('Sec-Fetch-Dest', 'document')
|
||||
.set('Sec-Fetch-Mode', 'navigate')
|
||||
.set('Sec-Fetch-Site', 'cross-site')
|
||||
.set('Sec-Fetch-User', '?1');
|
||||
// Working Download
|
||||
download(BrowserWindow.getFocusedWindow(), info.url, info.properties)
|
||||
.then(dl => mainWindow.webContents.send("download complete", dl.getSavePath()));
|
||||
});
|
||||
|
||||
|
||||
// Write to a file
|
||||
ipcMain.on("saveFile", () => {
|
||||
let yamlStr = yaml.dump(data);
|
||||
fs.writeFileSync(filepath + 'sectorfileUpdater.yaml', yamlStr, 'utf8');
|
||||
});
|
||||
|
||||
// Unzip content
|
||||
ipcMain.on("extract", () => {
|
||||
//console.log(directory.directoryPath);
|
||||
var unzipper = new DecompressZip("F:\\Desktop.zip");
|
||||
unzipper.extract({
|
||||
path: "F:\\test\\" // directory.directoryPath
|
||||
});
|
||||
// Notify "progress" of the decompressed files
|
||||
unzipper.on('progress', function(fileIndex, fileCount) {
|
||||
console.log('Extracted file ' + (fileIndex + 1) + ' of ' + fileCount);
|
||||
});
|
||||
// Notify when everything is extracted
|
||||
unzipper.on('extract', function(log) {
|
||||
console.log('Finished extracting', log);
|
||||
});
|
||||
ipcMain.on('download-progress', (event, args) => {
|
||||
mainWindow.webContents.send("progressbar", args);
|
||||
});
|
||||
};
|
||||
|
||||
@ -128,8 +49,6 @@ app.on('ready', createWindow);
|
||||
// for applications and their menu bar to stay active until the user quits
|
||||
// explicitly with Cmd + Q.
|
||||
app.on('window-all-closed', () => {
|
||||
let yamlStr = yaml.dump(data);
|
||||
fs.writeFileSync('data-out.yaml', yamlStr, 'utf8');
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit();
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
const { ipcRenderer, app } = require('electron');
|
||||
const superagent = require('superagent').agent();
|
||||
var fs = require('fs');
|
||||
var DecompressZip = require('decompress-zip');
|
||||
|
||||
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
|
||||
|
||||
@ -19,12 +18,6 @@ files.addEventListener("change", () => {
|
||||
save();
|
||||
});
|
||||
|
||||
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;
|
||||
@ -37,26 +30,30 @@ function changeUserpath() {
|
||||
ipcRenderer.send('app-path');
|
||||
}
|
||||
|
||||
ipcRenderer.on("app-path", (event, value) => {
|
||||
ipcRenderer.on("app-dest", (event, value) => {
|
||||
systemstructure.path = value[0];
|
||||
dirBox.value = value[0];
|
||||
fs.writeFileSync(systemstructure.path + "\\" + settings, JSON.stringify(structure, null, 4), 'utf8');
|
||||
console.log(systemstructure.path);
|
||||
fs.writeFileSync(filePath + "\\" + systemsettings, JSON.stringify(systemstructure, null, 4), 'utf8');
|
||||
location.reload();
|
||||
})
|
||||
|
||||
let progressbarText = document.getElementById('progressbarText');
|
||||
ipcRenderer.on("download progress", (event, progress) => {
|
||||
const cleanProgressInPercentages = Math.floor(progress.percent * 100); // Without decimal point
|
||||
document.getElementById('progressbar').value = cleanProgressInPercentages;
|
||||
});
|
||||
|
||||
// let downloadBtn = document.getElementById('download');
|
||||
// downloadBtn.addEventListener('click', (e) => {
|
||||
// var systemReadJson = JSON.parse(fs.readFileSync(systemsettings, 'utf8'));
|
||||
// var userReadJson = JSON.parse(fs.readFileSync(systemReadJson.path + settings, 'utf8'));
|
||||
// downloadFile(files.options[files.selectedIndex].href, systemReadJson.path);
|
||||
// });
|
||||
let testBtn = document.getElementById('test');
|
||||
testBtn.addEventListener('click', (e) => {
|
||||
var systemReadJson = JSON.parse(fs.readFileSync(systemsettings, 'utf8'));
|
||||
var userReadJson = JSON.parse(fs.readFileSync(systemReadJson.path + settings, 'utf8'));
|
||||
decompress(files.options[files.selectedIndex].href, systemReadJson.path)
|
||||
downloadBtn.addEventListener('click', (e) => {
|
||||
downloadFile(files.options[files.selectedIndex].href);
|
||||
});
|
||||
|
||||
ipcRenderer.on('progressbar', (event, args) => {
|
||||
progressbarText.innerHTML = args.progress + "%";
|
||||
progressbar.value = args.progress;
|
||||
});
|
||||
|
||||
rating.addEventListener('click', (e) => {
|
||||
structure.rating = rating.options[rating.selectedIndex].id;
|
||||
save();
|
||||
});
|
@ -1,12 +1,18 @@
|
||||
function save() {
|
||||
// WORK HERE, new files
|
||||
// Read config
|
||||
// Read config, if there is none, the default will be used
|
||||
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 (checkBoxRealname.checked == true) {
|
||||
structure.realname.name = realnameInput.value;
|
||||
structure.realname.save = true;
|
||||
} else {
|
||||
structure.realname.name = "";
|
||||
structure.realname.save = false;
|
||||
}
|
||||
if (checkBoxUsername.checked == true) {
|
||||
structure.cid.id = usernameInput.value;
|
||||
structure.cid.save = true;
|
||||
@ -28,9 +34,16 @@ function save() {
|
||||
structure.passwordhoppie.pass = "";
|
||||
structure.passwordhoppie.save = false;
|
||||
}
|
||||
// WIP
|
||||
//structure.currentInstalledAirac = currentAirac;
|
||||
//structure.version = airacversion;
|
||||
structure.rating = rating.options[rating.selectedIndex].id;
|
||||
// Save config
|
||||
console.log("Saving config");
|
||||
console.log(systemstructure.path + "\\" + settings);
|
||||
fs.writeFileSync(systemstructure.path + "\\" + settings, JSON.stringify(structure, null, 4), 'utf8');
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
function saveDownloadInfo(versionInfo) {
|
||||
structure.currentInstalledAirac = versionInfo[0];
|
||||
structure.version = versionInfo[1];
|
||||
fs.writeFileSync(systemstructure.path + "\\" + settings, JSON.stringify(structure, null, 4), 'utf8');
|
||||
}
|
@ -1,61 +1,122 @@
|
||||
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;
|
||||
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'));
|
||||
// Get the file path
|
||||
// filePath = await app.getPath('home');
|
||||
|
||||
// Check if the system settings file exists
|
||||
if (fs.existsSync(`${filePath}/${systemsettings}`)) {
|
||||
// If the file exists, read the structure
|
||||
systemstructure = JSON.parse(fs.readFileSync(filePath + "\\" + systemsettings, 'utf8'));
|
||||
} else {
|
||||
// If the file doesn't exist, get the user path and create the file
|
||||
await changeUserpath();
|
||||
// fs.writeFileSync(filePath + "\\" + systemsettings, JSON.stringify(systemstructure, null, 4), 'utf8');
|
||||
}
|
||||
delay(100);
|
||||
if (await fs.existsSync(systemstructure.path + "\\" + settings)) {
|
||||
console.log(fs.readFileSync(systemstructure.path + "\\" + settings, 'utf8'));
|
||||
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;
|
||||
|
||||
// Check if the user settings file exists
|
||||
if (fs.existsSync(`${systemstructure.path}/${settings}`)) {
|
||||
// If the file exists, read the structure
|
||||
structure = JSON.parse(fs.readFileSync(systemstructure.path + "\\" + settings, 'utf8'));
|
||||
} else {
|
||||
// If the file doesn't exist, create the file with the default structure
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Perform other necessary actions
|
||||
await getUpdates();
|
||||
// Update the UI with the settings from the user structure
|
||||
updateUI();
|
||||
}
|
||||
|
||||
function updateUI() {
|
||||
|
||||
if (structure.realname.save) {
|
||||
realnameInput.value = structure.realname.name;
|
||||
checkBoxRealname.checked = true;
|
||||
}
|
||||
if (structure.cid.save) {
|
||||
usernameInput.value = structure.cid.id;
|
||||
checkBoxUsername.checked = true;
|
||||
}
|
||||
if (structure.password.save) {
|
||||
passwordInput.value = structure.password.pass;
|
||||
checkBoxPassword.checked = true;
|
||||
}
|
||||
if (structure.passwordhoppie.save) {
|
||||
passwordhoppieInput.value = structure.passwordhoppie.pass;
|
||||
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;
|
||||
if (files.selectedIndex < 0) {
|
||||
files.selectedIndex = 0;
|
||||
} else {
|
||||
files.selectedIndex = structure.file;
|
||||
}
|
||||
await getFiles();
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
// 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();
|
||||
// }
|
@ -1,29 +0,0 @@
|
||||
// Unzip file
|
||||
function decompress(url, DESTINATION_PATH) {
|
||||
let file = url.split('/').pop();
|
||||
var ZIP_FILE_PATH = DESTINATION_PATH + "\\" + file;
|
||||
DESTINATION_PATH += "\\" + file.split('.')[0];
|
||||
console.log(DESTINATION_PATH);
|
||||
var unzipper = new DecompressZip(ZIP_FILE_PATH);
|
||||
|
||||
// Add the error event listener
|
||||
unzipper.on('error', function(err) {
|
||||
console.log('Caught an error', err);
|
||||
});
|
||||
|
||||
// Notify when everything is extracted
|
||||
unzipper.on('extract', function(log) {
|
||||
console.log('Finished extracting', log);
|
||||
});
|
||||
|
||||
// Notify "progress" of the decompressed files
|
||||
unzipper.on('progress', function(fileIndex, fileCount) {
|
||||
document.getElementById('progressbar').value = (0.5 + ((fileIndex + 1) / fileCount) / 2) * 100
|
||||
console.log(0.5 + ((fileIndex + 1) / fileCount) / 2);
|
||||
});
|
||||
|
||||
// Start extraction of the content
|
||||
unzipper.extract({
|
||||
path: DESTINATION_PATH
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user