2023-01-16 01:18:52 +01:00
|
|
|
const unzipper = require('unzipper');
|
|
|
|
|
|
|
|
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;
|
2023-01-14 01:26:26 +01:00
|
|
|
const zipFile = source.split('/').pop();
|
2023-01-16 01:18:52 +01:00
|
|
|
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 });
|
2023-01-14 01:26:26 +01:00
|
|
|
|
2023-01-16 01:18:52 +01:00
|
|
|
const request = superagent
|
|
|
|
.get(source)
|
|
|
|
.set("Referer", "http://files.aero-nav.com/")
|
2023-01-14 01:26:26 +01:00
|
|
|
.on('error', function(error) {
|
|
|
|
console.log(error);
|
2023-01-16 01:18:52 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
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))
|
2023-01-14 01:26:26 +01:00
|
|
|
.on('finish', function() {
|
2023-01-16 01:18:52 +01:00
|
|
|
// 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);
|
|
|
|
});
|
2023-01-14 01:26:26 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function createFolder(folder) {
|
|
|
|
if (!fs.existsSync(folder)) {
|
|
|
|
fs.mkdirSync(folder);
|
|
|
|
}
|
2023-01-16 01:18:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
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}`);
|
|
|
|
}
|