64 lines
1.6 KiB
JavaScript
64 lines
1.6 KiB
JavaScript
// This file contains function that are Electron/Node specific
|
|
function getFiles(dir, filelist){
|
|
fileList = [];
|
|
var files = fs.readdirSync(dir);
|
|
for(var i of files){
|
|
if (!files.hasOwnProperty(i)) continue;
|
|
var name = dir+'/'+files[i];
|
|
if (!fs.statSync(name).isDirectory()){
|
|
fileList.push(name);
|
|
}
|
|
}
|
|
return fileList;
|
|
}
|
|
|
|
function execute(command) {
|
|
exec(command, {stdio: 'inherit'});
|
|
}
|
|
|
|
function checkDir(directory) {
|
|
// Check whether director exists, if not create it
|
|
if (!fs.existsSync(directory)) {
|
|
// Folder does not exist try to create it
|
|
fs.mkdir(directory,{recursive: true}, (err) => {
|
|
if (err) {
|
|
alert('Cannot create data folder '+directory);
|
|
return(0);
|
|
}
|
|
});
|
|
}
|
|
return(1);
|
|
}
|
|
|
|
function writeAsciiFile(filename,content) {
|
|
// Write string content into ascii file filename
|
|
try { fs.writeFileSync(filename, content, 'utf-8'); }
|
|
catch(e) {
|
|
alert('Failed to save '+filename);
|
|
return(0);
|
|
}
|
|
return(1);
|
|
}
|
|
|
|
function readAsciiFile(filename) {
|
|
// Read ascii file filename and return content in a string
|
|
var content;
|
|
// If an array of filenames was sent take the first one only
|
|
if (Array.isArray(filename)) {filename=filename[0];}
|
|
try {
|
|
content = fs.readFileSync(filename, 'utf8');
|
|
} catch(e) {
|
|
alert('Failed to read '+filename);
|
|
return(0);
|
|
}
|
|
return(content);
|
|
}
|
|
|
|
function appPath() {
|
|
// return the path where the app resides
|
|
// let path = require('app').getAppPath();
|
|
// console.log(path);
|
|
let path = "./";
|
|
return path;
|
|
}
|