mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-11 00:54:06 +08:00
去除转换 dash 的函数
This commit is contained in:
parent
2b68aadf8d
commit
3eb65d3bf4
61
preload.js
61
preload.js
@ -1,9 +1,7 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const os = require('os');
|
|
||||||
const { spawn } = require("child_process")
|
|
||||||
const { shell } = require('electron');
|
const { shell } = require('electron');
|
||||||
const { dialog } = require('electron').remote
|
const { dialog, BrowserWindow, nativeImage } = require('electron').remote
|
||||||
const { BrowserWindow } = require('electron').remote
|
const path = require("path")
|
||||||
|
|
||||||
getDirname = () => __dirname;
|
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) => {
|
messageBox = (options, callback) => {
|
||||||
dialog.showMessageBox(BrowserWindow.getFocusedWindow(), options, index => {
|
dialog.showMessageBox(BrowserWindow.getFocusedWindow(), options, index => {
|
||||||
callback(index);
|
callback(index);
|
||||||
@ -27,48 +35,3 @@ messageBox = (options, callback) => {
|
|||||||
exists = path => {
|
exists = path => {
|
||||||
return fs.existsSync(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(/<Token>.*?<Name>(.*?)<\/Name><Type>(.*?)<\/Type>.*?<Path>(.*?>)*(.*?)<\/Path>\s+.*?<\/Token>/g, `{"name":"$1","type":"$2","path":"$4"},`);
|
|
||||||
data = data.replace(/<\?xml.*?>\s+<Tokens.*?>([\s|\S]*?),\s+<\/Tokens>/, '[$1]');
|
|
||||||
fs.writeFile(output, data, 'utf8', err => {
|
|
||||||
err && console.log(err);
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user