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); }