From 364394f4f1b50a3a57083502f0cc9943707162d7 Mon Sep 17 00:00:00 2001 From: owentou Date: Tue, 31 Aug 2021 21:44:04 +0800 Subject: [PATCH] 2.3.0-rc2 Signed-off-by: owentou --- .gitignore | 4 +- CHANGELOG.md | 22 +++++-- LICENSE | 2 +- package.json | 5 +- src/log4js.json | 22 +++++++ src/main.js | 160 +++++++++++++++++++++++++++++++++++++++++------- src/setup.js | 16 +++++ yarn.lock | 48 +++++++++++++-- 8 files changed, 243 insertions(+), 36 deletions(-) create mode 100644 src/log4js.json diff --git a/.gitignore b/.gitignore index b54e852..c4a8bd0 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ # *.jar *.war *.ear +*.log /.idea @@ -16,8 +17,7 @@ hs_err_pid* /tools/nwjs_download_cache /tools/nwjs-build.sh - # nodejs modules /node_modules /out -/src/lib \ No newline at end of file +/src/lib diff --git a/CHANGELOG.md b/CHANGELOG.md index 11bcf71..41f3e70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,16 +1,28 @@ 更新记录 ========== +2.3.0-rc2 +------ + +1. 增加 `--log-configure` 选项,用于指定log4js日志配置。增加默认的本地文件日志。 +2. 修复配置文件过大被拆分的BUG +3. 更新依赖库 + + > + electron -> 14.0.0 + > + bootstrap -> 5.1.0 + > + jquery.fancytree -> 2.38.0 + > + electron-packer -> 15.3.0 + 2.3.0-rc1 ------ 1. 更新依赖库 - > electron -> 11.1.1 - > bootstrap -> 5.0.0-beta1 - > jquery.fancytree -> 2.37.0 - > electron-packer -> 15.2.0 - > popper.js 替换为 @popperjs/core + > + electron -> 11.1.1 + > + bootstrap -> 5.0.0-beta1 + > + jquery.fancytree -> 2.37.0 + > + electron-packer -> 15.2.0 + > + popper.js 替换为 @popperjs/core 2. 增加命令行选项 ```--custom-selector/--custom-button ``` 用于增加自定义选择器 3. 允许事件可勾选是否执行 diff --git a/LICENSE b/LICENSE index d30eb7d..420609e 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2020 OWenT +Copyright (c) 2021 xresloader Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/package.json b/package.json index b8c55ff..2a13dcf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xresconv-gui", - "version": "2.3.0-rc1", + "version": "2.3.0-rc2", "publisher": "owent", "description": "xresconv 批量转表工具-GUI\r ==========", "main": "src/setup.js", @@ -19,10 +19,11 @@ "bootstrap": "^5.1.0", "jquery": "^3.6.0", "jquery.fancytree": "^2.38.0", + "log4js": "^6.3.0", "minimatch": "^3.0.4" }, "devDependencies": { - "electron": "^13.2.1", + "electron": "^14.0.0", "electron-packager": "^15.3.0", "gulp": "^4.0.2" }, diff --git a/src/log4js.json b/src/log4js.json new file mode 100644 index 0000000..0bf1019 --- /dev/null +++ b/src/log4js.json @@ -0,0 +1,22 @@ +{ + "appenders": { + "app": { + "type": "file", + "filename": "xresconv-gui.info.log", + "maxLogSize": 10485760, + "numBackups": 3 + }, + "errorFile": { + "type": "file", + "filename": "xresconv-gui.error.log" + }, + "errors": { + "type": "logLevelFilter", + "level": "ERROR", + "appender": "errorFile" + } + }, + "categories": { + "default": { "appenders": [ "app", "errors" ], "level": "DEBUG" } + } +} diff --git a/src/main.js b/src/main.js index a71a7c4..54922e3 100644 --- a/src/main.js +++ b/src/main.js @@ -5,6 +5,7 @@ var xconv_gui_options = { parallelism: 4, parallelism_max: 16, }; +const log4js = require("log4js"); function generate_id() { ++conv_data.id_index; @@ -154,6 +155,12 @@ function logger_append_info_message(msg, module_name) { } logger_append_style_message(msg, module_name, "alert-secondary"); + if (log4js) { + const log = log4js.getLogger(module_name); + if (log) { + log.info(msg); + } + } } function logger_append_notice_message(msg, module_name) { @@ -166,6 +173,12 @@ function logger_append_notice_message(msg, module_name) { } logger_append_style_message(msg, module_name, "alert-primary"); + if (log4js) { + const log = log4js.getLogger(module_name); + if (log) { + log.info(msg); + } + } } function logger_append_warning_message(msg, module_name, need_alert) { @@ -180,6 +193,12 @@ function logger_append_warning_message(msg, module_name, need_alert) { logger_append_style_message(msg, module_name, "alert-warning"); console.warn(msg); + if (log4js) { + const log = log4js.getLogger(module_name); + if (log) { + log.warn(msg); + } + } if (need_alert) { alert_error(msg); } @@ -197,6 +216,12 @@ function logger_append_error_message(msg, module_name, need_alert) { logger_append_style_message(msg, module_name, "alert-danger"); console.error(msg); + if (log4js) { + const log = log4js.getLogger(module_name); + if (log) { + log.error(msg); + } + } if (need_alert) { alert_error(msg); @@ -712,6 +737,24 @@ function setup_custom_selectors() { } catch (err) { logger_append_error_message(err, "CUSTOM SELECTOR"); } + + try { + const { ipcRenderer } = require("electron"); + ipcRenderer.invoke("ipc-get-log4js").then((log_configure) => { + try { + if (log_configure) { + log4js.configure(log_configure); + } else { + log4js.configure(require("./log4js.json")); + } + } catch (err) { + logger_append_error_message(err, "LOG"); + log4js.configure(require("./log4js.json")); + } + }); + } catch (err) { + logger_append_error_message(err, "LOG"); + } } function alert_error(content, title) { @@ -840,6 +883,12 @@ function alert_warning(content, tittle, options) { const hint_dom = conv_list_output_custom_multi.hint_dom; if (hint_dom) { run_log.append(hint_dom); + if (log4js) { + const log = log4js.getLogger("default"); + if (log) { + log.info(hint_dom.text()); + } + } } run_log.scrollTop(run_log.prop("scrollHeight")); } else { @@ -931,7 +980,12 @@ function alert_warning(content, tittle, options) { // $("#conv_list").empty(); // 初始化 - var jdom = $(context); + let jdom; + try { + jdom = $(context); + } catch (e) { + logger_append_error_message(e.toString(), `CONFIGURE: ${current_path}`); + } var include_list = []; // nw.js/electron 获取文件路径 @@ -972,9 +1026,8 @@ function alert_warning(content, tittle, options) { } else if ("proto" == tn) { var protocol_cfg = $("#conv_list_protocol option[value=" + val + "]"); if (protocol_cfg.length > 0) { - $("#conv_list_protocol").get(0).selectedIndex = protocol_cfg.get( - 0 - ).index; + $("#conv_list_protocol").get(0).selectedIndex = + protocol_cfg.get(0).index; } else { var parent_node = $("#conv_list_protocol"); var unknown_node = $("") @@ -1090,9 +1143,8 @@ function alert_warning(content, tittle, options) { '#conv_list_output_type option[value="' + output_matrix[0].type + '"]' ); if (output_type_cfg.length > 0) { - $("#conv_list_output_type").get( - 0 - ).selectedIndex = output_type_cfg.get(0).index; + $("#conv_list_output_type").get(0).selectedIndex = + output_type_cfg.get(0).index; } else { var parent_node = $("#conv_list_output_type"); var unknown_node = $("") @@ -1423,9 +1475,18 @@ function alert_warning(content, tittle, options) { const load_sub_file = function () { return new Promise(function (resolve, reject) { + let buffer_list = []; file_inst.on("data", (content) => { + buffer_list.push(content); + }); + + file_inst.on("end", (content) => { + const buffer = require("buffer"); resolve.apply(this, [ - build_conv_tree(content.toString(), file_path), + build_conv_tree( + buffer.Buffer.concat(buffer_list).toString(), + file_path + ), ]); }); @@ -1653,6 +1714,11 @@ function alert_warning(content, tittle, options) { resolve.apply(this, [arguments]); }); + let logger = null; + if (log4js) { + logger = log4js.getLogger("default"); + } + function run_all_cmds(resolve, reject) { const path = require("path"); const fs = require("fs"); @@ -1660,7 +1726,7 @@ function alert_warning(content, tittle, options) { 'you can download it from https://github.com/xresloader/xresloader/releases'; if (path.isAbsolute(xresloader_path)) { if (!fs.existsSync(xresloader_path)) { - run_log.append(); + //run_log.append(); failed_count += pending_script.length; reject.apply(this, [ `[${work_dir}] ${xresloader_path} not exists, ${download_hint}`, @@ -1678,9 +1744,11 @@ function alert_warning(content, tittle, options) { } function run_one_cmd(xresloader_index, xresloader_proc) { + let msg; if (pending_script.length > 0 && conv_data.run_seq == run_seq) { var cmd = pending_script.pop(); - run_log.append("[CONV " + xresloader_index + "] " + cmd + "\r\n"); + msg = `[CONV ${xresloader_index}] ${cmd}\r\n`; + run_log.append(msg); run_log.scrollTop(run_log.prop("scrollHeight")); xresloader_proc.exec.stdin.write(cmd); @@ -1692,9 +1760,12 @@ function alert_warning(content, tittle, options) { xresloader_proc.timer = null; } - run_log.append( - `[Process ${xresloader_proc.index} close stdin.]\r\n` - ); + msg = `[Process ${xresloader_proc.index} close stdin.]\r\n`; + run_log.append(msg); + } + + if (logger) { + log.info(msg); } } @@ -1706,15 +1777,14 @@ function alert_warning(content, tittle, options) { xresloader_path, "--stdin", ]); - run_log.append( - "[" + - work_dir + - "] Process " + - xresloader_index + - ": " + - xresloader_cmds.join(" ") + - "\r\n" - ); + const msg = `[${work_dir}] Process ${xresloader_index} : ${xresloader_cmds.join( + " " + )}\r\n`; + run_log.append(msg); + if (logger) { + log.info(msg); + } + console.log("start xresloader at " + work_dir); const xresloader_proc = { exec: spawn("java", xresloader_cmds, { @@ -1734,10 +1804,19 @@ function alert_warning(content, tittle, options) { let error_msg; if (signal) { error_msg = `[Process ${xresloader_index} exit with signal ${signal}.]\r\n`; + if (logger) { + log.error(error_msg); + } } else if (code != 0) { error_msg = `[Process ${xresloader_index} exit with code ${code}.]\r\n`; + if (logger) { + log.error(error_msg); + } } else { error_msg = `[Process ${xresloader_index} exit.]\r\n`; + if (logger) { + log.info(error_msg); + } } run_log.append(error_msg); --running_count; @@ -1764,6 +1843,9 @@ function alert_warning(content, tittle, options) { shell_color_to_html(data) + "\r\n" ); + if (logger) { + log.info(data); + } run_log.scrollTop(run_log.prop("scrollHeight")); run_one_cmd(xresloader_index, xresloader_proc); }); @@ -1774,6 +1856,9 @@ function alert_warning(content, tittle, options) { shell_color_to_html(data) + "" ); + if (logger) { + log.error(data); + } run_log.scrollTop(run_log.prop("scrollHeight")); run_one_cmd(xresloader_index, xresloader_proc); }); @@ -1978,12 +2063,18 @@ function alert_warning(content, tittle, options) { ); run_log.addClass("conv_list_run_error"); run_log.removeClass("conv_list_run_running"); + if (logger) { + log.error(`All jobs done, ${failed_count} job(s) failed.`); + } } else { run_log.append( "All jobs done.\r\n" ); run_log.addClass("conv_list_run_success"); run_log.removeClass("conv_list_run_running"); + if (logger) { + log.info("All jobs done."); + } } run_log.scrollTop(run_log.prop("scrollHeight")); }); @@ -2009,6 +2100,11 @@ function alert_warning(content, tittle, options) { dep_msg += '
  • Zulu
  • '; dep_msg += ""; + + let logger = null; + if (log4js) { + logger = log4js.getLogger("default"); + } try { var spawn = require("child_process").spawn; var java_exec = spawn("java", ["-version"], { @@ -2028,6 +2124,10 @@ function alert_warning(content, tittle, options) { '' ); run_log.append(dep_msg); + if (logger) { + logger.error("查询不到java版本号"); + logger.info(dep_msg); + } } else if ( find_java_version && (parseInt(find_java_version[0]) > 1 || @@ -2038,8 +2138,14 @@ function alert_warning(content, tittle, options) { dep_text + "" ); + if (logger) { + logger.error(dep_text); + } if (!dep_text.match(/64-Bit/i)) { run_log.append(dep_msg); + if (logger) { + logger.info(dep_msg); + } } } else { if (dep_text) { @@ -2048,17 +2154,27 @@ function alert_warning(content, tittle, options) { dep_text + "" ); + if (logger) { + logger.info(dep_text); + } } run_log.append( '' ); run_log.append(dep_msg); + if (logger) { + logger.error("检测不到java或java版本号过老"); + logger.info(dep_msg); + } } }); java_exec.stdin.end(); } catch (err) { run_log.append(dep_msg); + if (logger) { + logger.error(dep_msg); + } logger_append_error_message(err); } diff --git a/src/setup.js b/src/setup.js index 43bb099..8ae30bd 100644 --- a/src/setup.js +++ b/src/setup.js @@ -8,6 +8,7 @@ const app_config = { minHeight: 768, icon: `${__dirname}/../doc/logo.ico`, main: `file://${__dirname}/index.html`, + log_configure: null, }; if ("darwin" == os.platform().toLowerCase()) { @@ -33,6 +34,7 @@ const INPUT_PARAMS_MODE = { NONE: 0, INPUT_FILE: 1, CUSTOM_BUTTON: 2, + LOG_CONFIGURE: 3, }; function readCustomSelectors(file_path) { @@ -109,6 +111,11 @@ function createWindow() { param_mode = INPUT_PARAMS_MODE.NONE; break; } + case INPUT_PARAMS_MODE.LOG_CONFIGURE: { + app_config.log_configure = v; + param_mode = INPUT_PARAMS_MODE.NONE; + break; + } default: { if (v == "--input") { param_mode = INPUT_PARAMS_MODE.INPUT_FILE; @@ -116,6 +123,8 @@ function createWindow() { param_mode = INPUT_PARAMS_MODE.CUSTOM_BUTTON; } else if (v == "--debug") { app_config.debug = true; + } else if (v == "--log-configure") { + param_mode = INPUT_PARAMS_MODE.LOG_CONFIGURE; } break; } @@ -146,6 +155,9 @@ function createWindow() { icon: app_config.icon, webPreferences: { nodeIntegration: true, + nodeIntegrationInWorker: true, + nodeIntegrationInSubFrames: true, + contextIsolation: false, }, }); hold = false; @@ -212,6 +224,10 @@ ipcMain.handle("ipc-reload-custom-selectors", (event, _) => { custom_selectors.selectors = []; }); +ipcMain.handle("ipc-get-log4js", async (event, _) => { + return app_config.log_configure; +}); + // This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. diff --git a/yarn.lock b/yarn.lock index 3d4a120..e5e494c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -588,6 +588,16 @@ d@1, d@^1.0.1: es5-ext "^0.10.50" type "^1.0.1" +date-format@^2.1.0: + version "2.1.0" + resolved "https://mirrors.tencent.com/npm/date-format/-/date-format-2.1.0.tgz#31d5b5ea211cf5fd764cd38baf9d033df7e125cf" + integrity sha512-bYQuGLeFxhkxNOF3rcMtiZxvCBAquGzZm6oWA1oZ0g2THUzivaRhv8uOhdr19LmoobSOLoIAxeUK2RdbM8IFTA== + +date-format@^3.0.0: + version "3.0.0" + resolved "https://mirrors.tencent.com/npm/date-format/-/date-format-3.0.0.tgz#eb8780365c7d2b1511078fb491e6479780f3ad95" + integrity sha512-eyTcpKOcamdhWJXj56DpQMo1ylSQpcGtGKXcU0Tb97+K56/CF5amAqqqNj0+KvA0iw2ynxtHWFsPDSClCxe48w== + debug@^2.2.0, debug@^2.3.3, debug@^2.6.8, debug@^2.6.9: version "2.6.9" resolved "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f" @@ -749,10 +759,10 @@ electron-packager@^15.3.0: semver "^7.1.3" yargs-parser "^20.0.0" -electron@^13.2.1: - version "13.2.1" - resolved "https://mirrors.tencent.com/npm/electron/-/electron-13.2.1.tgz#0dc89ed0e3faf327b39571de533ca1ae18878ff1" - integrity sha512-/K0Uw+o3+phbHtrVL6qDFVJqmeRF6EIPwVeUHEH5R8JNy13f4X3RouKjQzVyY/Os8fEqYHGFONWhD6q6g750HQ== +electron@^14.0.0: + version "14.0.0" + resolved "https://mirrors.tencent.com/npm/electron/-/electron-14.0.0.tgz#a096484bfbf71d87fc0fa85a943a7869d6b9bf94" + integrity sha512-O6EI7L1BPIrTpEIFefjjmdbmSn9LtE4mmrv4dfpV4Mqaa8uKuNYQogwZPEvSwaBexb69eb1LQ25n+f+kBcjiRQ== dependencies: "@electron/get" "^1.0.1" "@types/node" "^14.6.2" @@ -1012,6 +1022,11 @@ flagged-respawn@^1.0.0: resolved "https://registry.npmjs.org/flagged-respawn/-/flagged-respawn-1.0.1.tgz#e7de6f1279ddd9ca9aac8a5971d618606b3aab41" integrity sha512-lNaHNVymajmk0OJMBn8fVUAU1BtDeKIqKoVhk4xAALB57aALg6b4W0MfJ/cUE0g9YBXy5XhSlPIpYIJ7HaY/3Q== +flatted@^2.0.1: + version "2.0.2" + resolved "https://mirrors.tencent.com/npm/flatted/-/flatted-2.0.2.tgz#4575b21e2bcee7434aa9be662f4b7b5f9c2b5138" + integrity sha512-r5wGx7YeOwNWNlCA0wQ86zKyDLMQr+/RB8xy74M4hTphfmjlijTSSXGuH8rnvKZnfT9i+75zmd8jcKdMR4O6jA== + flora-colossus@^1.0.0: version "1.0.1" resolved "https://registry.npmjs.org/flora-colossus/-/flora-colossus-1.0.1.tgz#aba198425a8185341e64f9d2a6a96fd9a3cbdb93" @@ -1769,6 +1784,17 @@ lodash@^4.17.10: resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg== +log4js@^6.3.0: + version "6.3.0" + resolved "https://mirrors.tencent.com/npm/log4js/-/log4js-6.3.0.tgz#10dfafbb434351a3e30277a00b9879446f715bcb" + integrity sha512-Mc8jNuSFImQUIateBFwdOQcmC6Q5maU0VVvdC2R6XMb66/VnT+7WS4D/0EeNMZu1YODmJe5NIn2XftCzEocUgw== + dependencies: + date-format "^3.0.0" + debug "^4.1.1" + flatted "^2.0.1" + rfdc "^1.1.4" + streamroller "^2.2.4" + lowercase-keys@^1.0.0, lowercase-keys@^1.0.1: version "1.0.1" resolved "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-1.0.1.tgz#6f9e30b47084d971a7c820ff15a6c5167b74c26f" @@ -2426,6 +2452,11 @@ ret@~0.1.10: resolved "https://registry.npmjs.org/ret/-/ret-0.1.15.tgz#b8a4825d5bdb1fc3f6f53c2bc33f81388681c7bc" integrity sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg== +rfdc@^1.1.4: + version "1.3.0" + resolved "https://mirrors.tencent.com/npm/rfdc/-/rfdc-1.3.0.tgz#d0b7c441ab2720d05dc4cf26e01c89631d9da08b" + integrity sha512-V2hovdzFbOi77/WajaSMXk2OLm+xNIeQdMMuB7icj7bk6zi2F8GGAxigcnDFpJHbNyNcgyJDiP+8nOrY5cZGrA== + roarr@^2.15.3: version "2.15.3" resolved "https://registry.npmjs.org/roarr/-/roarr-2.15.3.tgz#65248a291a15af3ebfd767cbf7e44cb402d1d836" @@ -2635,6 +2666,15 @@ stream-shift@^1.0.0: resolved "https://registry.npmjs.org/stream-shift/-/stream-shift-1.0.1.tgz#d7088281559ab2778424279b0877da3c392d5a3d" integrity sha512-AiisoFqQ0vbGcZgQPY1cdP2I76glaVA/RauYR4G4thNFgkTqr90yXTo4LYX60Jl+sIlPNHHdGSwo01AvbKUSVQ== +streamroller@^2.2.4: + version "2.2.4" + resolved "https://mirrors.tencent.com/npm/streamroller/-/streamroller-2.2.4.tgz#c198ced42db94086a6193608187ce80a5f2b0e53" + integrity sha512-OG79qm3AujAM9ImoqgWEY1xG4HX+Lw+yY6qZj9R1K2mhF5bEmQ849wvrb+4vt4jLMLzwXttJlQbOdPOQVRv7DQ== + dependencies: + date-format "^2.1.0" + debug "^4.1.1" + fs-extra "^8.1.0" + string-width@^1.0.1, string-width@^1.0.2: version "1.0.2" resolved "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz#118bdf5b8cdc51a2a7e70d211e07e2b0b9b107d3"