diff --git a/preload.js b/preload.js index 5ff247dd..6fa0b7eb 100644 --- a/preload.js +++ b/preload.js @@ -1,9 +1,7 @@ const fs = require('fs'); -const os = require('os'); -const { spawn } = require("child_process") const { shell } = require('electron'); -const { dialog } = require('electron').remote -const { BrowserWindow } = require('electron').remote +const { dialog, BrowserWindow, nativeImage } = require('electron').remote +const path = require("path") getDirname = () => __dirname; @@ -18,6 +16,16 @@ openFolder = () => { }); } +readFile = file => + new Promise((reslove, reject) => { + fs.readFile(file, 'utf8', (err, data) => { + if (err) reject(err); + reslove(data); + }); + }); + +getLogo = () => nativeImage.createFromPath(path.join(__dirname, 'logo.png')); + messageBox = (options, callback) => { dialog.showMessageBox(BrowserWindow.getFocusedWindow(), options, index => { callback(index); @@ -26,49 +34,4 @@ messageBox = (options, callback) => { exists = path => { return fs.existsSync(path); -} - -sqlite2Json = (input, output) => { - var binPath; - if (os.platform() == 'win32') { - binPath = `${__dirname.replace(/(.*?\.asar)/, "$1.unpacked")}/bin/sqlite3.exe`; - } else { - binPath = `${__dirname.replace(/(.*?\.asar)/, "$1.unpacked")}/bin/sqlite3` - } - const sql = spawn(binPath, [input, "select * from searchIndex", '-header', '-separator', '|||']) - let chunks = []; - sql.stdout.on('data', chunk => { - chunks.push(chunk) - }) - sql.on('close', code => { - let stdout = chunks.join("").split('\n'), - header = stdout[0].split('|||'), - json = [], - dict; - stdout.shift(); - for (var d of stdout) { - if (d) { - d = d.split('|||'); - dict = {} - for (var n = 1; n < d.length; n++) { - dict[header[n].trim()] = d[n].trim() - } - json.push(dict); - } - } - fs.writeFile(output, JSON.stringify(json), 'utf8', err => { - err && console.log(err); - }) - }) -} - -xml2Json = (input, output) => { - fs.readFile(input, 'utf8', (err, data) => { - data = data.replace(/\"/g, """); - data = data.replace(/.*?(.*?)<\/Name>(.*?)<\/Type>.*?(.*?>)*(.*?)<\/Path>\s+.*?<\/Token>/g, `{"name":"$1","type":"$2","path":"$4"},`); - data = data.replace(/<\?xml.*?>\s+([\s|\S]*?),\s+<\/Tokens>/, '[$1]'); - fs.writeFile(output, data, 'utf8', err => { - err && console.log(err); - }) - }) } \ No newline at end of file