mirror of
https://github.com/JustusPlays78/SectorFileUpdater.git
synced 2025-04-29 10:10:57 +00:00
changed systemsettings, WIP still, new structure
This commit is contained in:
parent
ea47cc5414
commit
4882b82529
4
updater/.gitignore
vendored
4
updater/.gitignore
vendored
@ -1,3 +1,7 @@
|
||||
# Programm JSON files
|
||||
systemfile.json
|
||||
settings.json
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
|
@ -1,8 +1,8 @@
|
||||
{
|
||||
"name": "updater",
|
||||
"productName": "updater",
|
||||
"version": "1.0.0",
|
||||
"description": "My Electron application description",
|
||||
"name": "sectorfile_updater",
|
||||
"productName": "Sectorfile Updater",
|
||||
"version": "0.0.1",
|
||||
"description": "This application allows users to easily update and maintain their sector files. It offers a simple, intuitive interface for downloading and installing the latest version of sector files, ensuring that users have access to the most accurate and up-to-date data. With automatic update checks and notifications, users can rest assured that their sector files are always up-to-date and ready for use.",
|
||||
"main": "src/index.js",
|
||||
"scripts": {
|
||||
"start": "electron-forge start",
|
||||
@ -12,16 +12,15 @@
|
||||
"lint": "echo \"No linting configured\""
|
||||
},
|
||||
"keywords": [],
|
||||
"author": {
|
||||
"name": "Julian",
|
||||
"email": "JustusPlays78@gmail.com"
|
||||
},
|
||||
"authors": [
|
||||
"Julian <JustusPlays78@gmail.com>",
|
||||
"Paul <paul@pabr.de>"
|
||||
],
|
||||
"license": "MIT",
|
||||
"config": {
|
||||
"forge": {
|
||||
"packagerConfig": {},
|
||||
"makers": [
|
||||
{
|
||||
"makers": [{
|
||||
"name": "@electron-forge/maker-squirrel",
|
||||
"config": {
|
||||
"name": "updater"
|
||||
@ -61,4 +60,4 @@
|
||||
"@electron-forge/maker-zip": "^6.0.0-beta.66",
|
||||
"electron": "^21.0.1"
|
||||
}
|
||||
}
|
||||
}
|
@ -3,4 +3,27 @@ body {
|
||||
margin: auto;
|
||||
max-width: 38rem;
|
||||
padding: 2rem;
|
||||
}
|
||||
|
||||
.tooltip {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
border-bottom: 1px dotted black;
|
||||
}
|
||||
|
||||
.tooltip .tooltiptext {
|
||||
visibility: hidden;
|
||||
width: 450px;
|
||||
background-color: black;
|
||||
color: #fff;
|
||||
text-align: center;
|
||||
border-radius: 6px;
|
||||
padding: 5px 0;
|
||||
/* Position the tooltip */
|
||||
position: absolute;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.tooltip:hover .tooltiptext {
|
||||
visibility: visible;
|
||||
}
|
@ -6,10 +6,7 @@
|
||||
<link rel="stylesheet" href="index.css" />
|
||||
</head>
|
||||
<body>
|
||||
<button id="download">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" readonly />
|
||||
@ -20,10 +17,33 @@
|
||||
<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="test">Test BTN</button>
|
||||
|
||||
<div id="login">
|
||||
<div class="tooltip">
|
||||
<p>Username</p>
|
||||
<input type="text" id="username" />
|
||||
<input type="checkbox" id="saveuser" />
|
||||
<p>Password</p>
|
||||
<input type="password" id="password" />
|
||||
<input type="checkbox" id="savepw" />
|
||||
<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>
|
||||
</div>
|
||||
|
||||
<script src="./renderer.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -58,12 +58,12 @@ const createWindow = () => {
|
||||
}*/
|
||||
|
||||
// Select Directory
|
||||
ipcMain.on('select-dirs', async(event, arg) => {
|
||||
ipcMain.on('app-path', async(event, arg) => {
|
||||
filepath = await dialog.showOpenDialog(mainWindow, {
|
||||
properties: ['openDirectory']
|
||||
});
|
||||
console.log('directories selected', filepath.filePaths);
|
||||
mainWindow.webContents.send("path selected", filepath.filePaths);
|
||||
mainWindow.webContents.send("app-path", filepath.filePaths);
|
||||
// Save directory to file
|
||||
});
|
||||
|
||||
|
@ -1,104 +1,104 @@
|
||||
const { ipcRenderer, dialog } = require('electron');
|
||||
const { ipcRenderer, dialog, app } = require('electron');
|
||||
const superagent = require('superagent').agent();
|
||||
var fs = require('fs');
|
||||
var DecompressZip = require('decompress-zip');
|
||||
const { version } = require('os');
|
||||
|
||||
// Global Variabels
|
||||
let dirBox = document.getElementById('dirs');
|
||||
let usernameInput = document.getElementById('username');
|
||||
let passwordInput = document.getElementById('password');
|
||||
let passwordhoppieInput = document.getElementById('passwordhoppie');
|
||||
|
||||
let systempath = "systemfile.json";
|
||||
let userFile = "\\userfile.json";
|
||||
var userjson = {
|
||||
// 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));
|
||||
let systempath = "systemfile.json"; // soll weg
|
||||
let userFile = "userfile.json"; // soll weg
|
||||
var systemstructure = {
|
||||
path: ""
|
||||
};
|
||||
var structure = {
|
||||
region: 0,
|
||||
file: 0,
|
||||
installcreds: false, // Not yet implemented
|
||||
installhoppie: false, // Not yet implemented
|
||||
cid: {
|
||||
save: true,
|
||||
id: 0
|
||||
id: -1
|
||||
},
|
||||
password: {
|
||||
save: true,
|
||||
pass: "NaN"
|
||||
pass: ""
|
||||
},
|
||||
currentInstalledAirac: 0
|
||||
};
|
||||
|
||||
var systemJson = {
|
||||
userpath: ""
|
||||
passwordhoppie: {
|
||||
save: true,
|
||||
pass: ""
|
||||
},
|
||||
currentInstalledAirac: 0,
|
||||
version: "v1"
|
||||
};
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() { // Seems to work (tm)
|
||||
firstStart();
|
||||
save();
|
||||
}, false);
|
||||
|
||||
let systemsettings = "system.json";
|
||||
let settings = "settings.json";
|
||||
var filepath;
|
||||
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();
|
||||
}
|
||||
await console.log(systemstructure);
|
||||
await console.log("test");
|
||||
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;
|
||||
}
|
||||
dirBox.value = systemstructure.path;
|
||||
// GET INFO
|
||||
|
||||
let firstStart = () => {
|
||||
try {
|
||||
const data = fs.readFileSync(systempath, 'utf8');
|
||||
} catch (err) {
|
||||
// Create file
|
||||
fs.writeFile(systempath, JSON.stringify(systemJson), { flag: 'wx' }, function(err) {
|
||||
if (err) throw err;
|
||||
});
|
||||
}
|
||||
} 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
|
||||
|
||||
var systemReadJson = JSON.parse(fs.readFileSync(systempath, 'utf8'));
|
||||
|
||||
try {
|
||||
const data = fs.readFileSync(systemReadJson.userpath + userFile, 'utf8');
|
||||
userjson = data;
|
||||
} catch (err) {
|
||||
// Create file
|
||||
changeUserpath();
|
||||
} finally {
|
||||
var userReadJson = JSON.parse(fs.readFileSync(systemReadJson.userpath + userFile, 'utf8'));
|
||||
getUpdates();
|
||||
// Set from file does not work
|
||||
gng.selectedIndex = userReadJson.region;
|
||||
}
|
||||
await getUpdates();
|
||||
gng.selectedIndex = structure.region;
|
||||
if (files.selectedIndex < 0) {
|
||||
files.selectedIndex = 0;
|
||||
} else {
|
||||
files.selectedIndex = userReadJson.file;
|
||||
files.selectedIndex = structure.file;
|
||||
}
|
||||
await getFiles();
|
||||
save();
|
||||
}
|
||||
}
|
||||
let changeUserpath = () => {
|
||||
ipcRenderer.send('select-dirs'); // DOES NOT WORK!
|
||||
}
|
||||
ipcRenderer.on("path selected", (event, value) => {
|
||||
var systemReadJson = JSON.parse(fs.readFileSync(systempath, 'utf8'));
|
||||
systemReadJson.userpath = value[0];
|
||||
fs.writeFile(systemReadJson.userpath + userFile, JSON.stringify(userjson), function(err) {
|
||||
if (err) throw err;
|
||||
});
|
||||
fs.writeFile(systempath, JSON.stringify(systemReadJson), function(err) {
|
||||
if (err) throw err;
|
||||
});
|
||||
})
|
||||
|
||||
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(systempath, 'utf8'));
|
||||
var userReadJson = JSON.parse(fs.readFileSync(systemReadJson.userpath + userFile, 'utf8'));
|
||||
downloadFile(files.options[files.selectedIndex].href, systemReadJson.userpath);
|
||||
});
|
||||
let directoryBtn = document.getElementById('dirs');
|
||||
directoryBtn.addEventListener('click', (e) => {});
|
||||
ipcRenderer.on("filepath", (event, file) => {
|
||||
document.getElementById('dirBox').value = file;
|
||||
});
|
||||
|
||||
let testBtn = document.getElementById('test');
|
||||
testBtn.addEventListener('click', (e) => {
|
||||
var systemReadJson = JSON.parse(fs.readFileSync(systempath, 'utf8'));
|
||||
var userReadJson = JSON.parse(fs.readFileSync(systemReadJson.userpath + userFile, 'utf8'));
|
||||
decompress(files.options[files.selectedIndex].href, systemReadJson.userpath)
|
||||
});
|
||||
}
|
||||
|
||||
// Save Event
|
||||
gng.addEventListener("change", () => {
|
||||
@ -109,14 +109,38 @@ files.addEventListener("change", () => {
|
||||
save();
|
||||
});
|
||||
|
||||
let save = () => {
|
||||
var systemReadJson = JSON.parse(fs.readFileSync(systempath, 'utf8'));
|
||||
var userReadJson = JSON.parse(fs.readFileSync(systemReadJson.userpath + userFile, 'utf8'));
|
||||
userReadJson.region = gng.selectedIndex;
|
||||
userReadJson.file = files.selectedIndex;
|
||||
fs.writeFile(systemReadJson.userpath + userFile, JSON.stringify(userReadJson), function(err) {
|
||||
if (err) throw err;
|
||||
});
|
||||
function save() {
|
||||
// WORK HERE, new files
|
||||
// Read config
|
||||
structure = JSON.parse(fs.readFileSync(systempath.path + userFile, 'utf8'));
|
||||
structure.region = gng.selectedIndex;
|
||||
structure.file = files.selectedIndex;
|
||||
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 + "\\" + userFile, JSON.stringify(structure, null, 4), 'utf8');
|
||||
};
|
||||
|
||||
// Check update
|
||||
@ -130,16 +154,14 @@ updateBtn.addEventListener('click', () => {
|
||||
});
|
||||
|
||||
// Remove all files when changing Region --> WIP no nicht
|
||||
const removeFileItems = () => {
|
||||
function removeFileItems() {
|
||||
var i, L = dropDownFiles.options.length - 1;
|
||||
for (i = L; i >= 0; i--) {
|
||||
dropDownFiles.remove(i);
|
||||
}
|
||||
}
|
||||
|
||||
const getUpdates = async() => {
|
||||
|
||||
|
||||
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();
|
||||
@ -170,14 +192,7 @@ const getUpdates = async() => {
|
||||
getFiles();
|
||||
}
|
||||
|
||||
// Check Files
|
||||
let getFilesBtn = document.getElementById('getFiles');
|
||||
getFilesBtn.addEventListener('click', (e) => {
|
||||
hrefLinks = getFiles();
|
||||
console.log("leaveme alone " + hrefLinks);
|
||||
});
|
||||
|
||||
const getFiles = async() => {
|
||||
async function getFiles() {
|
||||
removeFileItems();
|
||||
// Get all GNG Package Options
|
||||
let region = "https://files.aero-nav.com/" + dropDownGNG.options[dropDownGNG.selectedIndex].text;
|
||||
@ -232,7 +247,7 @@ const getFiles = async() => {
|
||||
}
|
||||
|
||||
|
||||
let downloadFile = (source, path) => {
|
||||
function downloadFile(source, path) {
|
||||
console.log(source)
|
||||
const zipFile = source.split('/').pop();
|
||||
|
||||
@ -248,7 +263,7 @@ let downloadFile = (source, path) => {
|
||||
}
|
||||
|
||||
// Unzip file
|
||||
let decompress = (url, DESTINATION_PATH) => {
|
||||
function decompress(url, DESTINATION_PATH) {
|
||||
let file = url.split('/').pop()
|
||||
var ZIP_FILE_PATH = DESTINATION_PATH + "\\" + file;
|
||||
DESTINATION_PATH += "\\" + file.split('.')[0];
|
||||
@ -275,4 +290,33 @@ let decompress = (url, DESTINATION_PATH) => {
|
||||
unzipper.extract({
|
||||
path: DESTINATION_PATH
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function changeUserpath() {
|
||||
ipcRenderer.send('app-path');
|
||||
}
|
||||
|
||||
ipcRenderer.on("app-path", (event, value) => {
|
||||
systemstructure.path = value[0];
|
||||
fs.writeFileSync(systemstructure.path + "\\" + settings, JSON.stringify(structure, null, 4), 'utf8');
|
||||
})
|
||||
|
||||
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(systempath, 'utf8'));
|
||||
// var userReadJson = JSON.parse(fs.readFileSync(systemReadJson.path + userFile, 'utf8'));
|
||||
// downloadFile(files.options[files.selectedIndex].href, systemReadJson.path);
|
||||
// });
|
||||
let testBtn = document.getElementById('test');
|
||||
testBtn.addEventListener('click', (e) => {
|
||||
var systemReadJson = JSON.parse(fs.readFileSync(systempath, 'utf8'));
|
||||
var userReadJson = JSON.parse(fs.readFileSync(systemReadJson.path + userFile, 'utf8'));
|
||||
decompress(files.options[files.selectedIndex].href, systemReadJson.path)
|
||||
});
|
@ -1 +1 @@
|
||||
{"userpath":"F:\\02 Benutzer\\Chef\\Desktop"}
|
||||
{ "path": "F:\\02 Benutzer\\Chef\\Dokumente\\00 Git\\sectorfileupdater\\updater" }
|
Loading…
x
Reference in New Issue
Block a user