mirror of
https://github.com/JustusPlays78/SectorFileUpdater.git
synced 2025-06-28 04:55:16 +00:00
savefile, extract begin, select directory
This commit is contained in:
@ -8,14 +8,14 @@
|
||||
<body>
|
||||
<button id="download" class"button is-primary">Download</button>
|
||||
<button id="dirs">Open</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">
|
||||
<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>
|
||||
<progress id="progressbar" max="100" value="0"></progress>
|
||||
<script src="./renderer.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -3,6 +3,8 @@ 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');
|
||||
|
||||
// Handle creating/removing shortcuts on Windows when installing/uninstalling.
|
||||
// eslint-disable-next-line global-require
|
||||
@ -10,6 +12,22 @@ if (require('electron-squirrel-startup')) {
|
||||
app.quit();
|
||||
}
|
||||
|
||||
var filepath;
|
||||
let data = {
|
||||
cid: {
|
||||
save: true,
|
||||
id: 0
|
||||
},
|
||||
password: {
|
||||
save: true,
|
||||
pass: "NaN"
|
||||
},
|
||||
customUrl: "",
|
||||
currentInstalledAirac: 0
|
||||
};
|
||||
|
||||
|
||||
|
||||
const createWindow = () => {
|
||||
// Create the browser window.
|
||||
const mainWindow = new BrowserWindow({
|
||||
@ -25,13 +43,33 @@ 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)
|
||||
// Save directory to file
|
||||
});
|
||||
|
||||
// Download a file
|
||||
ipcMain.on("download", (event, info) => {
|
||||
@ -42,7 +80,31 @@ const createWindow = () => {
|
||||
});
|
||||
|
||||
|
||||
// Write to a file
|
||||
ipcMain.on("saveFile", () => {
|
||||
let yamlStr = yaml.dump(data);
|
||||
fs.writeFileSync(filepath + 'sectorfileUpdater.yaml', yamlStr, 'utf8');
|
||||
});
|
||||
|
||||
// Unzip content
|
||||
ipcMain.on("extract", (event, directory) => {
|
||||
console.log(directory.directoryPath);
|
||||
var unzipper = new DecompressZip("F:\\Desktop.zip");
|
||||
console.log("Töfte querdrad");
|
||||
unzipper.extract({
|
||||
path: "F:\\test\\" // directory.directoryPath
|
||||
});
|
||||
console.log("Töfte cubique");
|
||||
// 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);
|
||||
});
|
||||
console.log("Töfte donna");
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@ -59,6 +121,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();
|
||||
}
|
||||
@ -70,13 +134,4 @@ app.on('activate', () => {
|
||||
if (BrowserWindow.getAllWindows().length === 0) {
|
||||
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);
|
||||
}
|
||||
});
|
||||
});
|
@ -1 +1,9 @@
|
||||
const { contextBridge, ipcRenderer } = require('electron')
|
||||
const { contextBridge, ipcRenderer } = require('electron')
|
||||
|
||||
process.once('loaded', () => {
|
||||
window.addEventListener('message', evt => {
|
||||
if (evt.data.type === 'select-dirs') {
|
||||
ipcRenderer.send('select-dirs')
|
||||
}
|
||||
})
|
||||
})
|
@ -1,4 +1,5 @@
|
||||
const { ipcRenderer, dialog } = require('electron');
|
||||
var DecompressZip = require('decompress-zip');
|
||||
|
||||
ipcRenderer.on("download complete", (event, file) => {
|
||||
console.log(file); // Full file path
|
||||
@ -10,8 +11,8 @@ ipcRenderer.on("download progress", (event, progress) => {
|
||||
document.getElementById('progressbar').value = cleanProgressInPercentages;
|
||||
});
|
||||
|
||||
let donwloadbtn = document.getElementById('download');
|
||||
donwloadbtn.addEventListener('click', (e) => {
|
||||
let donwloadBtn = document.getElementById('download');
|
||||
donwloadBtn.addEventListener('click', (e) => {
|
||||
let directoryPath = document.getElementById('dirBox');
|
||||
let urlPath = document.getElementById('urlBox');
|
||||
ipcRenderer.send("download", {
|
||||
@ -20,19 +21,20 @@ donwloadbtn.addEventListener('click', (e) => {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
document.getElementById('dirs').addEventListener('click', function() {
|
||||
openFile();
|
||||
});
|
||||
let directoryBtn = document.getElementById('dirs');
|
||||
directoryBtn.addEventListener('click', (e) => {
|
||||
window.postMessage({
|
||||
type: 'select-dirs'
|
||||
})
|
||||
});
|
||||
|
||||
function openFile() {
|
||||
ipcRenderer.send('openFolder', () => {
|
||||
console.log("Event sent.");
|
||||
let extractBtn = document.getElementById('extract');
|
||||
extractBtn.addEventListener('click', (e) => {
|
||||
let directoryPath = document.getElementById('dirBox');
|
||||
let urlPath = document.getElementById('urlBox');
|
||||
ipcRenderer.send("extract", {
|
||||
url: urlPath.value,
|
||||
properties: { directory: directoryPath.value }
|
||||
});
|
||||
}
|
||||
|
||||
ipcRenderer.on('folderData', (event, data) => {
|
||||
console.log(data)
|
||||
})
|
||||
console.log("Töfte");
|
||||
});
|
Reference in New Issue
Block a user