From 92f9737e277319decff297011fa8351a1892b79a Mon Sep 17 00:00:00 2001 From: octopus_yan Date: Sat, 16 Nov 2024 00:20:01 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=89=A7=E8=A1=8C=E5=B8=A6=E7=A9=BA?= =?UTF-8?q?=E6=A0=BC=E8=B7=AF=E5=BE=84=E5=91=BD=E4=BB=A4=E7=9A=84=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dmt/common/util/ProcessesUtil.java | 22 +++++++++++++++++++ .../java/cn/octopusyan/dmt/utils/PBOUtil.java | 14 ++++++------ .../cn/octopusyan/dmt/view/ConsoleLog.java | 6 ++--- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/main/java/cn/octopusyan/dmt/common/util/ProcessesUtil.java b/src/main/java/cn/octopusyan/dmt/common/util/ProcessesUtil.java index b814c48..8752bf2 100644 --- a/src/main/java/cn/octopusyan/dmt/common/util/ProcessesUtil.java +++ b/src/main/java/cn/octopusyan/dmt/common/util/ProcessesUtil.java @@ -52,12 +52,34 @@ public class ProcessesUtil { public static ProcessesUtil init(String workingDirectory) { return init(new File(workingDirectory)); } + public static ProcessesUtil init(File workingDirectory) { ProcessesUtil util = new ProcessesUtil(workingDirectory); set.add(util); return util; } + /** + * 转命令 + * + * @param command 命令模板 + * @param params 参数 + * @return 命令 + */ + public static String format(String command, Object... params) { + + int i = 0; + while (command.contains("{}") && params != null) { + String param = String.valueOf(params[i++]); + + if (param.contains(" ")) + param = STR."\"\{param}\""; + + command = command.replaceFirst("\\{}", param.replace("\\", "\\\\")); + } + return command; + } + public boolean exec(String command) { commandLine = CommandLine.parse(command); try { diff --git a/src/main/java/cn/octopusyan/dmt/utils/PBOUtil.java b/src/main/java/cn/octopusyan/dmt/utils/PBOUtil.java index 86d556d..227cf61 100644 --- a/src/main/java/cn/octopusyan/dmt/utils/PBOUtil.java +++ b/src/main/java/cn/octopusyan/dmt/utils/PBOUtil.java @@ -32,9 +32,9 @@ public class PBOUtil { private static final ProcessesUtil processesUtil = ProcessesUtil.init(Constants.BIN_DIR_PATH); - private static final String UNPACK_COMMAND = STR."\{Constants.PBOC_FILE} unpack -o \{Constants.TMP_DIR_PATH} %s"; - private static final String PACK_COMMAND = STR."\{Constants.PBOC_FILE} pack -o %s %s"; - private static final String CFG_COMMAND = STR."\{Constants.CFG_CONVERT_FILE} %s -dst %s %s"; + private static final String UNPACK_COMMAND = STR."\{Constants.PBOC_FILE} unpack -o \{Constants.TMP_DIR_PATH} {}"; + private static final String PACK_COMMAND = STR."\{Constants.PBOC_FILE} pack -o {} {}"; + private static final String CFG_COMMAND = STR."\{Constants.CFG_CONVERT_FILE} {} -dst {} {}"; private static final String FILE_NAME_STRING_TABLE = "stringtable.csv"; private static final String FILE_NAME_CONFIG_BIN = "config.bin"; @@ -92,7 +92,7 @@ public class PBOUtil { throw new RuntimeException("文件夹创建失败", e); } - String command = String.format(UNPACK_COMMAND, pboFile.getAbsolutePath()); + String command = ProcessesUtil.format(UNPACK_COMMAND, pboFile.getAbsolutePath()); consoleLog.debug(STR."unpack command ==> [\{command}]"); boolean exec = processesUtil.exec(command); if (!exec) @@ -117,7 +117,7 @@ public class PBOUtil { FileUtils.deleteQuietly(packFile); } - String command = String.format(PACK_COMMAND, Constants.TMP_DIR_PATH, unpackPath); + String command = ProcessesUtil.format(PACK_COMMAND, Constants.TMP_DIR_PATH, unpackPath); consoleLog.debug(STR."pack command ==> [\{command}]"); boolean exec = processesUtil.exec(command); @@ -400,7 +400,7 @@ public class PBOUtil { private static String toBinCommand(File cppFile) { String outFilePath = outFilePath(cppFile, ".bin"); outFilePath = outFilePath.replace(Constants.BAK_DIR_PATH, Constants.TMP_DIR_PATH); - return String.format(CFG_COMMAND, "-bin", outFilePath, cppFile.getAbsolutePath()); + return ProcessesUtil.format(CFG_COMMAND, "-bin", outFilePath, cppFile.getAbsolutePath()); } /** @@ -408,7 +408,7 @@ public class PBOUtil { */ private static String toTxtCommand(File binFile) { String outFilePath = outFilePath(binFile, ".cpp"); - return String.format(CFG_COMMAND, "-txt", outFilePath, binFile.getAbsolutePath()); + return ProcessesUtil.format(CFG_COMMAND, "-txt", outFilePath, binFile.getAbsolutePath()); } private static String outFilePath(File file, String suffix) { diff --git a/src/main/java/cn/octopusyan/dmt/view/ConsoleLog.java b/src/main/java/cn/octopusyan/dmt/view/ConsoleLog.java index bb2a6cc..e67f16c 100644 --- a/src/main/java/cn/octopusyan/dmt/view/ConsoleLog.java +++ b/src/main/java/cn/octopusyan/dmt/view/ConsoleLog.java @@ -1,10 +1,10 @@ package cn.octopusyan.dmt.view; +import cn.octopusyan.dmt.common.config.Context; import javafx.application.Platform; import javafx.scene.control.TextArea; import lombok.Getter; import lombok.RequiredArgsConstructor; -import lombok.Setter; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -23,8 +23,6 @@ public class ConsoleLog { private static Logger markerLog; private static TextArea logArea; private final String tag; - @Setter - private static boolean showDebug = false; public static void init(TextArea logArea) { ConsoleLog.logArea = logArea; @@ -56,7 +54,7 @@ public class ConsoleLog { } public void debug(String message, Object... param) { - if (!showDebug) return; + if (!Context.isDebugMode()) return; printLog(tag, Level.DEBUG, message, param); }