updates, soc, simplify code

This commit is contained in:
PaulaBras 2023-01-14 01:26:26 +01:00
parent b42f3a89fb
commit e51694dc91
13 changed files with 352 additions and 319 deletions

View File

@ -1,12 +1,12 @@
{
"name": "updater",
"version": "1.0.0",
"name": "sectorfile_updater",
"version": "0.0.1",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "updater",
"version": "1.0.0",
"name": "sectorfile_updater",
"version": "0.0.1",
"license": "MIT",
"dependencies": {
"@octokit/core": "^4.0.5",
@ -15,6 +15,7 @@
"electron-squirrel-startup": "^1.0.0",
"http": "^0.0.1-security",
"js-yaml": "^4.1.0",
"simple-git": "^3.15.1",
"superagent": "^8.0.3"
},
"devDependencies": {
@ -544,6 +545,19 @@
"integrity": "sha512-k2Ty1JcVojjJFwrg/ThKi2ujJ7XNLYaFGNB/bWT9wGR+oSMJHMa5w+CUq6p/pVrKeNNgA7pCqEcjSnHVoqJQFw==",
"dev": true
},
"node_modules/@kwsites/file-exists": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@kwsites/file-exists/-/file-exists-1.1.1.tgz",
"integrity": "sha512-m9/5YGR18lIwxSFDwfE3oA7bWuq9kdau6ugN4H2rJeyhFQZcG9AgSHkQtSD15a8WvTgfz9aikZMrKPHvbpqFiw==",
"dependencies": {
"debug": "^4.1.1"
}
},
"node_modules/@kwsites/promise-deferred": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@kwsites/promise-deferred/-/promise-deferred-1.1.1.tgz",
"integrity": "sha512-GaHYm+c0O9MjZRu0ongGBRbinu8gVAMd2UZjji6jVmqKtZluZnptXGWhz1E8j8D2HJ3f/yMxKAUC0b+57wncIw=="
},
"node_modules/@malept/cross-spawn-promise": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@malept/cross-spawn-promise/-/cross-spawn-promise-2.0.0.tgz",
@ -5600,6 +5614,20 @@
"integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==",
"dev": true
},
"node_modules/simple-git": {
"version": "3.15.1",
"resolved": "https://registry.npmjs.org/simple-git/-/simple-git-3.15.1.tgz",
"integrity": "sha512-73MVa5984t/JP4JcQt0oZlKGr42ROYWC3BcUZfuHtT3IHKPspIvL0cZBnvPXF7LL3S/qVeVHVdYYmJ3LOTw4Rg==",
"dependencies": {
"@kwsites/file-exists": "^1.1.1",
"@kwsites/promise-deferred": "^1.1.1",
"debug": "^4.3.4"
},
"funding": {
"type": "github",
"url": "https://github.com/steveukx/git-js?sponsor=1"
}
},
"node_modules/smart-buffer": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz",
@ -6854,6 +6882,19 @@
"integrity": "sha512-k2Ty1JcVojjJFwrg/ThKi2ujJ7XNLYaFGNB/bWT9wGR+oSMJHMa5w+CUq6p/pVrKeNNgA7pCqEcjSnHVoqJQFw==",
"dev": true
},
"@kwsites/file-exists": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@kwsites/file-exists/-/file-exists-1.1.1.tgz",
"integrity": "sha512-m9/5YGR18lIwxSFDwfE3oA7bWuq9kdau6ugN4H2rJeyhFQZcG9AgSHkQtSD15a8WvTgfz9aikZMrKPHvbpqFiw==",
"requires": {
"debug": "^4.1.1"
}
},
"@kwsites/promise-deferred": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@kwsites/promise-deferred/-/promise-deferred-1.1.1.tgz",
"integrity": "sha512-GaHYm+c0O9MjZRu0ongGBRbinu8gVAMd2UZjji6jVmqKtZluZnptXGWhz1E8j8D2HJ3f/yMxKAUC0b+57wncIw=="
},
"@malept/cross-spawn-promise": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@malept/cross-spawn-promise/-/cross-spawn-promise-2.0.0.tgz",
@ -10686,6 +10727,16 @@
"integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==",
"dev": true
},
"simple-git": {
"version": "3.15.1",
"resolved": "https://registry.npmjs.org/simple-git/-/simple-git-3.15.1.tgz",
"integrity": "sha512-73MVa5984t/JP4JcQt0oZlKGr42ROYWC3BcUZfuHtT3IHKPspIvL0cZBnvPXF7LL3S/qVeVHVdYYmJ3LOTw4Rg==",
"requires": {
"@kwsites/file-exists": "^1.1.1",
"@kwsites/promise-deferred": "^1.1.1",
"debug": "^4.3.4"
}
},
"smart-buffer": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz",

View File

@ -20,7 +20,8 @@
"config": {
"forge": {
"packagerConfig": {},
"makers": [{
"makers": [
{
"name": "@electron-forge/maker-squirrel",
"config": {
"name": "updater"
@ -50,6 +51,7 @@
"electron-squirrel-startup": "^1.0.0",
"http": "^0.0.1-security",
"js-yaml": "^4.1.0",
"simple-git": "^3.15.1",
"superagent": "^8.0.3"
},
"devDependencies": {
@ -60,4 +62,4 @@
"@electron-forge/maker-zip": "^6.0.0-beta.66",
"electron": "^21.0.1"
}
}
}

View File

@ -0,0 +1,24 @@
var systemstructure = {
path: ""
};
var structure = {
region: 0,
file: 0,
installcreds: false, // Not yet implemented
installhoppie: false, // Not yet implemented
cid: {
save: true,
id: -1
},
password: {
save: true,
pass: ""
},
passwordhoppie: {
save: true,
pass: ""
},
currentInstalledAirac: 0,
version: "v1"
};

20
updater/src/download.js Normal file
View File

@ -0,0 +1,20 @@
function downloadFile(source, path) {
console.log(source);
const zipFile = source.split('/').pop();
superagent
.get(source).set("Referer", "http://files.aero-nav.com/")
.on('error', function(error) {
console.log(error);
})
.pipe(fs.createWriteStream(path + "\\" + zipFile))
.on('finish', function() {
// add code below to here
});
}
function createFolder(folder) {
if (!fs.existsSync(folder)) {
fs.mkdirSync(folder);
}
};

40
updater/src/getFiles.js Normal file
View File

@ -0,0 +1,40 @@
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 => {
var option = document.createElement("option");
option.text = item;
dropDownGNG.add(option);
});
getFiles();
}
async function getFiles() {
await removeFileItems();
let region = "https://files.aero-nav.com/" + dropDownGNG.options[dropDownGNG.selectedIndex].text;
let courses = await superagent.get(region);
let text = courses.text.split("Released</th><th colspan='2'>Download</th></tr>").pop();
text = text.split("<h1>AIRAC <small>News</small></h1>")[0];
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 hrefLinks = rows.filter((row, index) => index % 5 === 4).map(row => row.match(/href="(.*?)"/)[1]);
removeFileItems();
fileNames.forEach((fileName, index) => {
let option = document.createElement("option");
option.text = fileName;
option.version = versionNumbers[index];
option.href = hrefLinks[index];
dropDownFiles.add(option);
});
if (structure.file != -1) {
dropDownFiles.selectedIndex = structure.file;
}
return hrefLinks;
}

0
updater/src/git_ops.js Normal file
View File

View File

@ -0,0 +1,19 @@
// Global Variabels
let dirBox = document.getElementById('dirBox');
let usernameInput = document.getElementById('username');
let passwordInput = document.getElementById('password');
let passwordhoppieInput = document.getElementById('passwordhoppie');
let saveCredBtn = document.getElementById('savecred');
// CheckBox Events
let checkBoxUsername = document.getElementById('saveuser');
let checkBoxPassword = document.getElementById('savepw');
let checkBoxSavepwhoppie = document.getElementById('savepwhoppie');
// Check update
let dropDownGNG = document.getElementById('gng');
let dropDownFiles = document.getElementById('files');
saveCredBtn.addEventListener('click', (e) => {
save();
});

View File

@ -1,11 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<head>
<meta charset="UTF-8" />
<title>Sectorfile Updater</title>
<link rel="stylesheet" href="index.css" />
</head>
<body>
</head>
<body>
<button id="extract">Extract ZIP</button>
<p>Input Directory</p>
<input type="text" id="dirBox" name="name" size="80" readonly />
@ -19,40 +21,44 @@
<button id="test">Test BTN</button>
<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>
<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>
</div>
<script src="./renderer.js"></script>
</body>
</html>
<script src="./html_elements.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>
</body>
</html>

View File

@ -3,106 +3,12 @@ const superagent = require('superagent').agent();
var fs = require('fs');
var DecompressZip = require('decompress-zip');
// Global Variabels
let dirBox = document.getElementById('dirBox');
let usernameInput = document.getElementById('username');
let passwordInput = document.getElementById('password');
let passwordhoppieInput = document.getElementById('passwordhoppie');
let saveCredBtn = document.getElementById('savecred');
// CheckBox Events
let checkBoxUsername = document.getElementById('saveuser');
let checkBoxPassword = document.getElementById('savepw');
let checkBoxSavepwhoppie = document.getElementById('savepwhoppie');
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
var systemstructure = {
path: ""
};
var structure = {
region: 0,
file: 0,
installcreds: false, // Not yet implemented
installhoppie: false, // Not yet implemented
cid: {
save: true,
id: -1
},
password: {
save: true,
pass: ""
},
passwordhoppie: {
save: true,
pass: ""
},
currentInstalledAirac: 0,
version: "v1"
};
document.addEventListener('DOMContentLoaded', function() { // Seems to work (tm)
firstStart();
}, false);
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;
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'));
} else {
await changeUserpath();
}
if (await fs.existsSync(systemstructure.path + "\\" + settings)) {
structure = JSON.parse(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();
}
// Save Event
gng.addEventListener("change", () => {
@ -113,47 +19,6 @@ files.addEventListener("change", () => {
save();
});
function save() {
// WORK HERE, new files
// Read config
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 (checkBoxUsername.checked == true) {
structure.cid.id = usernameInput.value;
structure.cid.save = true;
} else {
structure.cid.id = -1;
structure.cid.save = false;
}
if (checkBoxPassword.checked == true) {
structure.password.pass = passwordInput.value;
structure.password.save = true;
} else {
structure.password.pass = "";
structure.password.save = false;
}
if (checkBoxSavepwhoppie.checked == true) {
structure.passwordhoppie.pass = passwordhoppieInput.value;
structure.passwordhoppie.save = true;
} else {
structure.passwordhoppie.pass = "";
structure.passwordhoppie.save = false;
}
// WIP
//structure.currentInstalledAirac = currentAirac;
//structure.version = airacversion;
// Save config
fs.writeFileSync(systemstructure.path + "\\" + settings, JSON.stringify(structure, null, 4), 'utf8');
};
// Check update
let dropDownGNG = document.getElementById('gng');
let dropDownFiles = document.getElementById('files');
let updateBtn = document.getElementById('update');
updateBtn.addEventListener('click', () => {
removeFileItems();
@ -168,143 +33,6 @@ function removeFileItems() {
}
}
async function getUpdates() {
// Get all GNG Options
const courses = await superagent.get('https://files.aero-nav.com/');
let text = courses.text.split("Download Pages").pop();
let textArray = text.split("\n");
let liste = "";
let firstElement = "<b>";
let lastElement = "</b>";
textArray.forEach(element => {
if (element.includes(firstElement)) {
liste += element.substring(
element.indexOf(firstElement) + firstElement.length,
element.indexOf(lastElement, element.indexOf(firstElement))) +
"\n";
}
});
const listeArray = liste.split("\n");
// Add to html selector
listeArray.pop();
listeArray.forEach(optionsAdd);
// Add Elements to Drop Down
function optionsAdd(item) {
var option = document.createElement("option");
option.text = item;
dropDownGNG.add(option);
}
getFiles();
}
async function getFiles() {
await removeFileItems();
// Get all GNG Package Options
let region = "https://files.aero-nav.com/" + dropDownGNG.options[dropDownGNG.selectedIndex].text;
let courses = await superagent.get(region);
let text = courses.text.split("Released</th><th colspan='2'>Download</th></tr>").pop();
text = text.split("<h1>AIRAC <small>News</small></h1>")[0];
let rows = "";
for (var i = 0; i < text.length; i++) {
if (text[i] + text[i + 1] + text[i + 2] + text[i + 3] === "<td>") {
let i2 = i + 4;
while (text[i2] + text[i2 + 1] + text[i2 + 2] + text[i2 + 3] + text[i2 + 4] !== "</td>") {
rows += text[i2];
i2++;
}
rows += "\n";
}
}
//console.log(rows); // For debugging only
// All Rows in Table
const listeArray = rows.split("\n");
listeArray.pop();
let fileNames = "";
// Select only Package names
for (var i = 1; i < listeArray.length; i = i + 5) {
fileNames += listeArray[i] + "\n";
}
const fileNamesArray = fileNames.split("\n");
fileNamesArray.pop();
let firstElement = "href=";
let lastElement = "class=";
let hrefLinksList = "";
for (var i = 4; i < listeArray.length; i = i + 5) {
hrefLinksList += listeArray[i].substring(
listeArray[i].indexOf(firstElement) + firstElement.length + 1,
listeArray[i].indexOf(lastElement) - 2) + "\n";
}
const hrefLinksArray = hrefLinksList.split("\n");
hrefLinksArray.pop();
removeFileItems();
// Add Elements to Drop Down
for (let i = 0; i < fileNamesArray.length; i++) {
var option = document.createElement("option");
option.text = fileNamesArray[i];
option.href = hrefLinksArray[i];
dropDownFiles.add(option);
}
if (structure.file != -1) {
dropDownFiles.selectedIndex = structure.file;
}
//files.selectedIndex = structure.file;
return hrefLinksArray;
}
function downloadFile(source, path) {
console.log(source)
const zipFile = source.split('/').pop();
superagent
.get(source).set("Referer", "http://files.aero-nav.com/")
.on('error', function(error) {
console.log(error);
})
.pipe(fs.createWriteStream(path + "\\" + zipFile))
.on('finish', function() {
// add code below to here
});
}
// 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
});
}
function changeUserpath() {
ipcRenderer.send('app-path');
}
@ -331,8 +59,4 @@ 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)
});
saveCredBtn.addEventListener('click', (e) => {
save();
});

36
updater/src/save.js Normal file
View File

@ -0,0 +1,36 @@
function save() {
// WORK HERE, new files
// Read config
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 (checkBoxUsername.checked == true) {
structure.cid.id = usernameInput.value;
structure.cid.save = true;
} else {
structure.cid.id = -1;
structure.cid.save = false;
}
if (checkBoxPassword.checked == true) {
structure.password.pass = passwordInput.value;
structure.password.save = true;
} else {
structure.password.pass = "";
structure.password.save = false;
}
if (checkBoxSavepwhoppie.checked == true) {
structure.passwordhoppie.pass = passwordhoppieInput.value;
structure.passwordhoppie.save = true;
} else {
structure.passwordhoppie.pass = "";
structure.passwordhoppie.save = false;
}
// WIP
//structure.currentInstalledAirac = currentAirac;
//structure.version = airacversion;
// Save config
fs.writeFileSync(systemstructure.path + "\\" + settings, JSON.stringify(structure, null, 4), 'utf8');
};

61
updater/src/startup.js Normal file
View File

@ -0,0 +1,61 @@
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;
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'));
} else {
await changeUserpath();
}
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;
} 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();
}

29
updater/src/unzip.js Normal file
View File

@ -0,0 +1,29 @@
// 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
});
}

View File

@ -303,6 +303,18 @@
"resolved" "https://registry.npmjs.org/@gar/promisify/-/promisify-1.1.3.tgz"
"version" "1.1.3"
"@kwsites/file-exists@^1.1.1":
"integrity" "sha512-m9/5YGR18lIwxSFDwfE3oA7bWuq9kdau6ugN4H2rJeyhFQZcG9AgSHkQtSD15a8WvTgfz9aikZMrKPHvbpqFiw=="
"resolved" "https://registry.npmjs.org/@kwsites/file-exists/-/file-exists-1.1.1.tgz"
"version" "1.1.1"
dependencies:
"debug" "^4.1.1"
"@kwsites/promise-deferred@^1.1.1":
"integrity" "sha512-GaHYm+c0O9MjZRu0ongGBRbinu8gVAMd2UZjji6jVmqKtZluZnptXGWhz1E8j8D2HJ3f/yMxKAUC0b+57wncIw=="
"resolved" "https://registry.npmjs.org/@kwsites/promise-deferred/-/promise-deferred-1.1.1.tgz"
"version" "1.1.1"
"@malept/cross-spawn-promise@^1.0.0":
"integrity" "sha512-RTBGWL5FWQcg9orDOCcp4LvItNzUPcyEU9bwaeJX0rJ1IQxzucC48Y0/sQLp/g6t99IQgAlGIaesJS+gTn7tVQ=="
"resolved" "https://registry.npmjs.org/@malept/cross-spawn-promise/-/cross-spawn-promise-1.1.1.tgz"
@ -3102,6 +3114,15 @@
"resolved" "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz"
"version" "3.0.7"
"simple-git@^3.15.1":
"integrity" "sha512-73MVa5984t/JP4JcQt0oZlKGr42ROYWC3BcUZfuHtT3IHKPspIvL0cZBnvPXF7LL3S/qVeVHVdYYmJ3LOTw4Rg=="
"resolved" "https://registry.npmjs.org/simple-git/-/simple-git-3.15.1.tgz"
"version" "3.15.1"
dependencies:
"@kwsites/file-exists" "^1.1.1"
"@kwsites/promise-deferred" "^1.1.1"
"debug" "^4.3.4"
"smart-buffer@^4.2.0":
"integrity" "sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg=="
"resolved" "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz"