This commit is contained in:
Paul Pabr 2022-12-19 17:59:42 +01:00
commit 6d3b70de3d
11 changed files with 1806 additions and 1200 deletions

View File

@ -6,12 +6,12 @@ Dieses kleine Tool soll GNG Sector Müll beheben. Leider beschäftigt sich jeder
* Select ES Folder
* Version herausfinden / eingeben
* Updates prüfen (file from Server mit Update Möglichkeiten) bspw (vonVersion-nachVersion):
* 2200-2201
* 2200-2202
* 2200-2203
* 2200-2204
* 2200-2205
* 2200-2206
* 2207-2201
* 2207-2202
* 2207-2203
* 2207-2204
* 2207-2205
* 2207-2206
* Update herunterladen und enpacken
* Hierbei werden neue und modifizierte Dateien verändert. (Erkannt wird das vorab mit einem Server script, welches die Fullpackes vergleicht und mittels git vergleicht. Einschränkung hier --diff-filter=ACRTUXBD)
* Inline, wie bei Git ist hier nicht möglich, da nicht git vorrausgesetzt werden kann auf dem Zielcomputer

7
updater/data-out.yaml Normal file
View File

@ -0,0 +1,7 @@
cid:
save: true
id: 0
password:
save: true
pass: NaN
currentInstalledAirac: 0

1696
updater/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -47,8 +47,11 @@
"dependencies": {
"@octokit/core": "^4.0.5",
"decompress-zip": "^0.3.3",
"dir-compare": "^4.0.0",
"electron-dl": "^3.3.1",
"electron-squirrel-startup": "^1.0.0"
"electron-squirrel-startup": "^1.0.0",
"js-yaml": "^4.1.0",
"node-abi": "^3.28.0"
},
"devDependencies": {
"@electron-forge/cli": "^6.0.0-beta.66",

View File

@ -0,0 +1 @@
folderPath: "C:\\Euroscope"

View File

@ -0,0 +1,7 @@
cid:
save: true
id: 1467870
password:
save: false
pass: "Testen123"
currentInstalledAirac: 2205

View File

@ -9,14 +9,25 @@
<button id="download" class="button is-primary">Download</button>
<button id="dirs">Open</button>
<button id="script">Run Shell Script</button>
<button id="download" class"button is-primary">Download</button>
<button id="dirs">Select Directory</button>
<button id="extract">Extract ZIP</button>
<p id="ouput">Output Test here</p>
<p>Input URL</p>
<input type="text" id="urlBox" name="name" size="80">
<input type="text" id="urlBox" name="name" size="80" readonly>
<p>Input Directory</p>
<input type="text" id="dirBox" name="name" size="80">
<progress id="progressbar" max="100" value="70"></progress>
<input type="file" id="dirs" webkitdirectory directory/>
<p id="ouput">Output Test here</p>
<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>
<select name="Dropme Down" id="gng"></select>
<button id="getFiles">Get Files</button>
<select name="Dropme Down #2" id="files"></select>
<button id="git">Do Git Operations</button>
<script src="./renderer.js"></script>
</body>
</html>

View File

@ -3,6 +3,13 @@ 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
@ -10,6 +17,21 @@ if (require('electron-squirrel-startup')) {
app.quit();
}
var filepath;
let data = {
cid: {
save: true,
id: 0
},
password: {
save: true,
pass: "NaN"
},
currentInstalledAirac: 0
};
const createWindow = () => {
// Create the browser window.
const mainWindow = new BrowserWindow({
@ -24,25 +46,90 @@ 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('select-dirs', async(event, arg) => {
const result = await dialog.showOpenDialog(mainWindow, {
filepath = await dialog.showOpenDialog(mainWindow, {
properties: ['openDirectory']
})
console.log('directories selected', result.filePaths)
})
});
console.log('directories selected', filepath.filePaths);
mainWindow.webContents.send("filepath", 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);
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()));
});
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);
});
});
};
@ -59,6 +146,8 @@ 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();
}
@ -71,12 +160,3 @@ app.on('activate', () => {
createWindow();
}
});
// Write to a file
ipcMain.on("saveFile", (event, location, txtVal) => {
fs.writeFile(location, txtVal.toString(), (err) => {
if (!err) { console.log("File.written"); } else {
console.log(err);
}
});
});

View File

@ -1 +1,9 @@
const { contextBridge, ipcRenderer } = require('electron')
process.once('loaded', () => {
window.addEventListener('message', evt => {
if (evt.data.type === 'select-dirs') {
ipcRenderer.send('select-dirs')
}
})
})

View File

@ -1,4 +1,10 @@
const { ipcRenderer, dialog } = require('electron');
const superagent = require('superagent').agent();
var fs = require('fs');
// Global Variabels
let hrefLinks = "";
const shell = require('electron').shell;
ipcRenderer.on("download complete", (event, file) => {
@ -11,35 +17,249 @@ ipcRenderer.on("download progress", (event, progress) => {
document.getElementById('progressbar').value = cleanProgressInPercentages;
});
let donwloadbtn = document.getElementById('download');
donwloadbtn.addEventListener('click', (e) => {
let fileSelect = document.getElementById('files');
let donwloadBtn = document.getElementById('download');
donwloadBtn.addEventListener('click', (e) => {
let directoryPath = document.getElementById('dirBox');
let urlPath = document.getElementById('urlBox');
ipcRenderer.send("download", {
url: urlPath.value,
properties: { directory: directoryPath.value }
url: hrefLinks[fileSelect.options.selectedIndex],
properties: {
directory: directoryPath.value
}
});
});
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('dirs').addEventListener('click', function() {
openFile();
});
let directoryBtn = document.getElementById('dirs');
directoryBtn.addEventListener('click', (e) => {
ipcRenderer.send('select-dirs');
});
function openFile() {
ipcRenderer.send('openFolder', () => {
console.log("Event sent.");
ipcRenderer.on("filepath", (event, file) => {
document.getElementById('dirBox').value = file;
});
// Check update
let dropDownGNG = document.getElementById('gng');
let dropDownFiles = document.getElementById('files');
let updateBtn = document.getElementById('update');
updateBtn.addEventListener('click', (e) => {
removeFileItems();
getUpdates();
});
// Remove all files when changing Region --> WIP no nicht
const removeFileItems = async() => {
var i, L = dropDownFiles.options.length - 1;
for (i = L; i >= 0; i--) {
dropDownFiles.remove(i);
}
}
const getUpdates = async() => {
// Get all GNG Options
let 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);
}
}
// Check Files
let getFilesBtn = document.getElementById('getFiles');
getFilesBtn.addEventListener('click', (e) => {
hrefLinks = getFiles();
console.log("leaveme alone " + hrefLinks);
});
const getFiles = async() => {
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]
//console.log(text);
let rows = "";
// As an idea
// textArray = text.split("\n");
// let liste = "";
// let firstElement = "<td>";
// let lastElement = "</td>";
// textArray.forEach(element => {
// if (element.includes(firstElement)) {
// liste += element.substring(
// element.indexOf(firstElement) + firstElement.length,
// element.indexOf(lastElement, element.indexOf(firstElement))) +
// "\n";
// }
// });
// let outArray2 = liste.split("\n");
// outArray2.pop();
// console.log(outArray2);
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();
fileNamesArray.forEach(optionsAdd);
// Add Elements to Drop Down
function optionsAdd(item) {
var option = document.createElement("option");
option.text = item;
dropDownFiles.add(option);
}
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();
console.log(hrefLinksArray);
return hrefLinksArray;
}
// Download idea from https://damieng.com/blog/2017/03/10/downloading-files-with-progress-in-electron/
download("https://files.aero-nav.com/EDGG/Full_Package_20221104183433-221101-3.zip", "Full_Package_20221104183433-221101-3.zip", (bytes, percent) => console.log(`Downloaded ${bytes} (${percent})`));
//import fs from "fs";
async function download(
sourceUrl,
targetFile,
progressCallback,
length
) {
const request = new Request(sourceUrl, {
headers: new Headers({ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8", "Accept-Language": "en-US,en;q=0.5", "Accept-Encoding": "gzip, deflate, br", "DNT": "1", "Connection": "keep-alive", "Referer": "http://files.aero-nav.com/", "Upgrade-Insecure-Requests": "1", "Sec-Fetch-Dest": "document", "Sec-Fetch-Mode": "navigate", "Sec-Fetch-Site": "cross-site", "Sec-Fetch-User": "?1" }),
});
const response = await fetch(request);
if (!response.ok) {
throw Error(
`Unable to download, server returned ${response.status} ${response.statusText}`
);
}
const body = response.body;
if (body == null) {
throw Error("No response body");
}
const finalLength =
length || parseInt(response.headers.get("Content-Length" || "0"), 10);
const reader = body.getReader();
const writer = fs.createWriteStream(targetFile);
await streamWithProgress(finalLength, reader, writer, progressCallback);
writer.end();
}
async function streamWithProgress(length, reader, writer, progressCallback) {
let bytesDone = 0;
while (true) {
const result = await reader.read();
if (result.done) {
if (progressCallback != null) {
progressCallback(length, 100);
}
return;
}
const chunk = result.value;
if (chunk == null) {
throw Error("Empty chunk received during download");
} else {
writer.write(Buffer.from(chunk));
if (progressCallback != null) {
bytesDone += chunk.byteLength;
const percent =
length === 0 ? null : Math.floor((bytesDone / length) * 100);
progressCallback(bytesDone, percent);
}
}
}
}
// Git Operations
// Vars for git
const options = { compareSize: true, compareContent: true, compareFileAsync: true };
const path1 = 'E:\\git\\v1';
const path2 = 'E:\\git\\v2';
let gitBtn = document.getElementById('git');
gitBtn.addEventListener('click', (e) => {
git();
});
const git = async() => {
const res = dircompare.compareSync(path1, path2, options);
console.log(res.differencesFiles); // Number check :)
print(res);
}
ipcRenderer.on('folderData', (event, data) => {
console.log(data)
})
let shellBtn = document.getElementById('script');
shellBtn.addEventListener('click', (e) => {
shell.openItem("./test.sh")
});

File diff suppressed because it is too large Load Diff