mirror of
https://github.com/JustusPlays78/SectorFileUpdater.git
synced 2025-04-29 10:10:57 +00:00
self merge
This commit is contained in:
parent
b6d23d2380
commit
62459081de
@ -12,10 +12,18 @@
|
|||||||
<p id="ouput">Output Test here</p>
|
<p id="ouput">Output Test here</p>
|
||||||
|
|
||||||
<p>Input URL</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>
|
<p>Input Directory</p>
|
||||||
<input type="text" id="dirBox" name="name" size="80">
|
<input type="text" id="dirBox" name="name" size="80" readonly>
|
||||||
<progress id="progressbar" max="100" value="0"></progress>
|
<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>
|
||||||
|
|
||||||
<script src="./renderer.js"></script>
|
<script src="./renderer.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -5,6 +5,11 @@ const path = require('path');
|
|||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
const yaml = require('js-yaml');
|
const yaml = require('js-yaml');
|
||||||
var DecompressZip = require('decompress-zip');
|
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.
|
// Handle creating/removing shortcuts on Windows when installing/uninstalling.
|
||||||
// eslint-disable-next-line global-require
|
// eslint-disable-next-line global-require
|
||||||
@ -65,8 +70,8 @@ const createWindow = () => {
|
|||||||
ipcMain.on('select-dirs', async(event, arg) => {
|
ipcMain.on('select-dirs', async(event, arg) => {
|
||||||
filepath = await dialog.showOpenDialog(mainWindow, {
|
filepath = await dialog.showOpenDialog(mainWindow, {
|
||||||
properties: ['openDirectory']
|
properties: ['openDirectory']
|
||||||
})
|
});
|
||||||
console.log('directories selected', filepath.filePaths)
|
console.log('directories selected', filepath.filePaths);
|
||||||
mainWindow.webContents.send("filepath", filepath.filePaths);
|
mainWindow.webContents.send("filepath", filepath.filePaths);
|
||||||
// Save directory to file
|
// Save directory to file
|
||||||
});
|
});
|
||||||
@ -75,6 +80,29 @@ const createWindow = () => {
|
|||||||
ipcMain.on("download", (event, info) => {
|
ipcMain.on("download", (event, info) => {
|
||||||
// https://dms.pabr.de/s/SpBiQYADTNak7R5/download
|
// https://dms.pabr.de/s/SpBiQYADTNak7R5/download
|
||||||
info.properties.onProgress = status => mainWindow.webContents.send("download progress", status);
|
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)
|
download(BrowserWindow.getFocusedWindow(), info.url, info.properties)
|
||||||
.then(dl => mainWindow.webContents.send("download complete", dl.getSavePath()));
|
.then(dl => mainWindow.webContents.send("download complete", dl.getSavePath()));
|
||||||
});
|
});
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
const { ipcRenderer, dialog } = require('electron');
|
const { ipcRenderer, dialog } = require('electron');
|
||||||
var DecompressZip = require('decompress-zip');
|
const superagent = require('superagent').agent();
|
||||||
|
var fs = require('fs');
|
||||||
|
|
||||||
|
// Global Variabels
|
||||||
|
let hrefLinks = "";
|
||||||
|
|
||||||
|
|
||||||
ipcRenderer.on("download complete", (event, file) => {
|
ipcRenderer.on("download complete", (event, file) => {
|
||||||
console.log(file); // Full file path
|
console.log(file); // Full file path
|
||||||
@ -11,33 +16,225 @@ ipcRenderer.on("download progress", (event, progress) => {
|
|||||||
document.getElementById('progressbar').value = cleanProgressInPercentages;
|
document.getElementById('progressbar').value = cleanProgressInPercentages;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let fileSelect = document.getElementById('files');
|
||||||
let donwloadBtn = document.getElementById('download');
|
let donwloadBtn = document.getElementById('download');
|
||||||
donwloadBtn.addEventListener('click', (e) => {
|
donwloadBtn.addEventListener('click', (e) => {
|
||||||
let directoryPath = document.getElementById('dirBox');
|
let directoryPath = document.getElementById('dirBox');
|
||||||
let urlPath = document.getElementById('urlBox');
|
let urlPath = document.getElementById('urlBox');
|
||||||
ipcRenderer.send("download", {
|
ipcRenderer.send("download", {
|
||||||
url: urlPath.value,
|
url: hrefLinks[fileSelect.options.selectedIndex],
|
||||||
properties: { directory: directoryPath.value }
|
properties: {
|
||||||
|
directory: directoryPath.value
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
let directoryBtn = document.getElementById('dirs');
|
let directoryBtn = document.getElementById('dirs');
|
||||||
directoryBtn.addEventListener('click', (e) => {
|
directoryBtn.addEventListener('click', (e) => {
|
||||||
window.postMessage({
|
ipcRenderer.send('select-dirs');
|
||||||
type: 'select-dirs'
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcRenderer.on("filepath", (event, file) => {
|
ipcRenderer.on("filepath", (event, file) => {
|
||||||
document.getElementById('dirBox').innerText = file;
|
document.getElementById('dirBox').value = file;
|
||||||
});
|
});
|
||||||
|
|
||||||
let extractBtn = document.getElementById('extract');
|
// Check update
|
||||||
extractBtn.addEventListener('click', () => {
|
let dropDownGNG = document.getElementById('gng');
|
||||||
let directoryPath = document.getElementById('dirBox');
|
let dropDownFiles = document.getElementById('files');
|
||||||
let urlPath = document.getElementById('urlBox');
|
|
||||||
ipcRenderer.send("extract", {
|
let updateBtn = document.getElementById('update');
|
||||||
url: urlPath.value,
|
updateBtn.addEventListener('click', (e) => {
|
||||||
properties: { directory: directoryPath.value }
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user