mirror of
https://github.com/JustusPlays78/SectorFileUpdater.git
synced 2025-04-29 19:24:24 +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
|
||||||
logs
|
logs
|
||||||
*.log
|
*.log
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "updater",
|
"name": "sectorfile_updater",
|
||||||
"productName": "updater",
|
"productName": "Sectorfile Updater",
|
||||||
"version": "1.0.0",
|
"version": "0.0.1",
|
||||||
"description": "My Electron application description",
|
"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",
|
"main": "src/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "electron-forge start",
|
"start": "electron-forge start",
|
||||||
@ -12,16 +12,15 @@
|
|||||||
"lint": "echo \"No linting configured\""
|
"lint": "echo \"No linting configured\""
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": {
|
"authors": [
|
||||||
"name": "Julian",
|
"Julian <JustusPlays78@gmail.com>",
|
||||||
"email": "JustusPlays78@gmail.com"
|
"Paul <paul@pabr.de>"
|
||||||
},
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"config": {
|
"config": {
|
||||||
"forge": {
|
"forge": {
|
||||||
"packagerConfig": {},
|
"packagerConfig": {},
|
||||||
"makers": [
|
"makers": [{
|
||||||
{
|
|
||||||
"name": "@electron-forge/maker-squirrel",
|
"name": "@electron-forge/maker-squirrel",
|
||||||
"config": {
|
"config": {
|
||||||
"name": "updater"
|
"name": "updater"
|
||||||
|
@ -4,3 +4,26 @@ body {
|
|||||||
max-width: 38rem;
|
max-width: 38rem;
|
||||||
padding: 2rem;
|
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" />
|
<link rel="stylesheet" href="index.css" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<button id="download">Download</button>
|
|
||||||
<button id="dirs">Select Directory</button>
|
|
||||||
<button id="extract">Extract ZIP</button>
|
<button id="extract">Extract ZIP</button>
|
||||||
<p id="ouput">Output Test here</p>
|
|
||||||
|
|
||||||
<p>Input URL</p>
|
<p>Input URL</p>
|
||||||
<input type="text" id="urlBox" name="name" size="80" readonly />
|
<input type="text" id="urlBox" name="name" size="80" readonly />
|
||||||
@ -20,10 +17,33 @@
|
|||||||
<button id="update">Check for update</button>
|
<button id="update">Check for update</button>
|
||||||
|
|
||||||
<select name="Dropme Down" id="gng"></select>
|
<select name="Dropme Down" id="gng"></select>
|
||||||
<button id="getFiles">Get Files</button>
|
|
||||||
<select name="Dropme Down #2" id="files"></select>
|
<select name="Dropme Down #2" id="files"></select>
|
||||||
|
|
||||||
<button id="test">Test BTN</button>
|
<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>
|
<script src="./renderer.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -58,12 +58,12 @@ const createWindow = () => {
|
|||||||
}*/
|
}*/
|
||||||
|
|
||||||
// Select Directory
|
// Select Directory
|
||||||
ipcMain.on('select-dirs', async(event, arg) => {
|
ipcMain.on('app-path', 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("path selected", filepath.filePaths);
|
mainWindow.webContents.send("app-path", filepath.filePaths);
|
||||||
// Save directory to file
|
// Save directory to file
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,104 +1,104 @@
|
|||||||
const { ipcRenderer, dialog } = require('electron');
|
const { ipcRenderer, dialog, app } = require('electron');
|
||||||
const superagent = require('superagent').agent();
|
const superagent = require('superagent').agent();
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var DecompressZip = require('decompress-zip');
|
var DecompressZip = require('decompress-zip');
|
||||||
|
const { version } = require('os');
|
||||||
|
|
||||||
// Global Variabels
|
// 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";
|
// CheckBox Events
|
||||||
let userFile = "\\userfile.json";
|
let checkBoxUsername = document.getElementById('saveuser');
|
||||||
var userjson = {
|
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,
|
region: 0,
|
||||||
file: 0,
|
file: 0,
|
||||||
|
installcreds: false, // Not yet implemented
|
||||||
|
installhoppie: false, // Not yet implemented
|
||||||
cid: {
|
cid: {
|
||||||
save: true,
|
save: true,
|
||||||
id: 0
|
id: -1
|
||||||
},
|
},
|
||||||
password: {
|
password: {
|
||||||
save: true,
|
save: true,
|
||||||
pass: "NaN"
|
pass: ""
|
||||||
},
|
},
|
||||||
currentInstalledAirac: 0
|
passwordhoppie: {
|
||||||
};
|
save: true,
|
||||||
|
pass: ""
|
||||||
var systemJson = {
|
},
|
||||||
userpath: ""
|
currentInstalledAirac: 0,
|
||||||
|
version: "v1"
|
||||||
};
|
};
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function() { // Seems to work (tm)
|
document.addEventListener('DOMContentLoaded', function() { // Seems to work (tm)
|
||||||
firstStart();
|
firstStart();
|
||||||
save();
|
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
|
let systemsettings = "system.json";
|
||||||
let firstStart = () => {
|
let settings = "settings.json";
|
||||||
try {
|
var filepath;
|
||||||
const data = fs.readFileSync(systempath, 'utf8');
|
async function firstStart() {
|
||||||
} catch (err) {
|
await ipcRenderer.send('app-path');
|
||||||
// Create file
|
await ipcRenderer.on("app-path", async(event, path) => {
|
||||||
fs.writeFile(systempath, JSON.stringify(systemJson), { flag: 'wx' }, function(err) {
|
filepath = path;
|
||||||
if (err) throw err;
|
// 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
|
||||||
|
|
||||||
var systemReadJson = JSON.parse(fs.readFileSync(systempath, 'utf8'));
|
} else {
|
||||||
|
fs.writeFileSync(systemstructure.path + "\\" + settings, JSON.stringify(structure, null, 4), 'utf8');
|
||||||
try {
|
gng.selectedIndex = structure.region;
|
||||||
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;
|
|
||||||
if (files.selectedIndex < 0) {
|
if (files.selectedIndex < 0) {
|
||||||
files.selectedIndex = 0;
|
files.selectedIndex = 0;
|
||||||
} else {
|
} else {
|
||||||
files.selectedIndex = userReadJson.file;
|
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();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
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
|
// Save Event
|
||||||
gng.addEventListener("change", () => {
|
gng.addEventListener("change", () => {
|
||||||
@ -109,14 +109,38 @@ files.addEventListener("change", () => {
|
|||||||
save();
|
save();
|
||||||
});
|
});
|
||||||
|
|
||||||
let save = () => {
|
function save() {
|
||||||
var systemReadJson = JSON.parse(fs.readFileSync(systempath, 'utf8'));
|
// WORK HERE, new files
|
||||||
var userReadJson = JSON.parse(fs.readFileSync(systemReadJson.userpath + userFile, 'utf8'));
|
// Read config
|
||||||
userReadJson.region = gng.selectedIndex;
|
structure = JSON.parse(fs.readFileSync(systempath.path + userFile, 'utf8'));
|
||||||
userReadJson.file = files.selectedIndex;
|
structure.region = gng.selectedIndex;
|
||||||
fs.writeFile(systemReadJson.userpath + userFile, JSON.stringify(userReadJson), function(err) {
|
structure.file = files.selectedIndex;
|
||||||
if (err) throw err;
|
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
|
// Check update
|
||||||
@ -130,16 +154,14 @@ updateBtn.addEventListener('click', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Remove all files when changing Region --> WIP no nicht
|
// Remove all files when changing Region --> WIP no nicht
|
||||||
const removeFileItems = () => {
|
function removeFileItems() {
|
||||||
var i, L = dropDownFiles.options.length - 1;
|
var i, L = dropDownFiles.options.length - 1;
|
||||||
for (i = L; i >= 0; i--) {
|
for (i = L; i >= 0; i--) {
|
||||||
dropDownFiles.remove(i);
|
dropDownFiles.remove(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const getUpdates = async() => {
|
async function getUpdates() {
|
||||||
|
|
||||||
|
|
||||||
// Get all GNG Options
|
// Get all GNG Options
|
||||||
const courses = await superagent.get('https://files.aero-nav.com/');
|
const courses = await superagent.get('https://files.aero-nav.com/');
|
||||||
let text = courses.text.split("Download Pages").pop();
|
let text = courses.text.split("Download Pages").pop();
|
||||||
@ -170,14 +192,7 @@ const getUpdates = async() => {
|
|||||||
getFiles();
|
getFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check Files
|
async function getFiles() {
|
||||||
let getFilesBtn = document.getElementById('getFiles');
|
|
||||||
getFilesBtn.addEventListener('click', (e) => {
|
|
||||||
hrefLinks = getFiles();
|
|
||||||
console.log("leaveme alone " + hrefLinks);
|
|
||||||
});
|
|
||||||
|
|
||||||
const getFiles = async() => {
|
|
||||||
removeFileItems();
|
removeFileItems();
|
||||||
// Get all GNG Package Options
|
// Get all GNG Package Options
|
||||||
let region = "https://files.aero-nav.com/" + dropDownGNG.options[dropDownGNG.selectedIndex].text;
|
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)
|
console.log(source)
|
||||||
const zipFile = source.split('/').pop();
|
const zipFile = source.split('/').pop();
|
||||||
|
|
||||||
@ -248,7 +263,7 @@ let downloadFile = (source, path) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Unzip file
|
// Unzip file
|
||||||
let decompress = (url, DESTINATION_PATH) => {
|
function decompress(url, DESTINATION_PATH) {
|
||||||
let file = url.split('/').pop()
|
let file = url.split('/').pop()
|
||||||
var ZIP_FILE_PATH = DESTINATION_PATH + "\\" + file;
|
var ZIP_FILE_PATH = DESTINATION_PATH + "\\" + file;
|
||||||
DESTINATION_PATH += "\\" + file.split('.')[0];
|
DESTINATION_PATH += "\\" + file.split('.')[0];
|
||||||
@ -276,3 +291,32 @@ let decompress = (url, DESTINATION_PATH) => {
|
|||||||
path: DESTINATION_PATH
|
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