Compare commits

...

6 Commits

12 changed files with 181 additions and 97 deletions

View File

@ -53,7 +53,7 @@
``` ```
2. 运行 2. 运行
```bash ```bash
mvn clean javafx:run mvn clean javafx:run -Pdev
``` ```
#### 打包 #### 打包
@ -64,7 +64,7 @@
``` ```
2. 运行 2. 运行
```bash ```bash
mvn clean package mvn clean package -Pbuild
``` ```
### 可能会用到 ### 可能会用到

47
pom.xml
View File

@ -6,8 +6,8 @@
<groupId>cn.octopusyan</groupId> <groupId>cn.octopusyan</groupId>
<artifactId>dmt</artifactId> <artifactId>dmt</artifactId>
<version>0.0.2</version> <version>0.1.2</version>
<name>dmt</name> <name>DayzModTranslator</name>
<organization> <organization>
<name>octopus_yan</name> <name>octopus_yan</name>
@ -172,14 +172,41 @@
</pluginRepository> </pluginRepository>
</pluginRepositories> </pluginRepositories>
<build> <profiles>
<resources> <profile>
<resource> <id>dev</id>
<directory>src/main/resources</directory> <properties>
<filtering>true</filtering> <debug.option>-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005</debug.option>
</resource> </properties>
</resources> <build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
</profile>
<profile>
<id>build</id>
<properties>
<debug.option/>
</properties>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>bin/</exclude>
</excludes>
</resource>
</resources>
</build>
</profile>
</profiles>
<build>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
@ -233,7 +260,7 @@
<configuration> <configuration>
<options> <options>
<option>--enable-preview</option> <option>--enable-preview</option>
<!-- <option>-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005</option>--> <option>${debug.option}</option>
</options> </options>
</configuration> </configuration>
</execution> </execution>

View File

@ -16,6 +16,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.File; import java.io.File;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.net.URL; import java.net.URL;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -39,11 +41,15 @@ public class Context {
@Getter @Getter
private static final Map<String, BaseController<?>> controllers = new HashMap<>(); private static final Map<String, BaseController<?>> controllers = new HashMap<>();
private Context() { private Context() {
throw new IllegalStateException("Utility class"); throw new IllegalStateException("Utility class");
} }
public static boolean isDebugMode() {
RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
return runtimeMXBean.getInputArguments().toString().contains("-agentlib:jdwp");
}
// 获取控制工厂 // 获取控制工厂
public static Callback<Class<?>, Object> getControlFactory() { public static Callback<Class<?>, Object> getControlFactory() {
return type -> { return type -> {

View File

@ -52,12 +52,34 @@ public class ProcessesUtil {
public static ProcessesUtil init(String workingDirectory) { public static ProcessesUtil init(String workingDirectory) {
return init(new File(workingDirectory)); return init(new File(workingDirectory));
} }
public static ProcessesUtil init(File workingDirectory) { public static ProcessesUtil init(File workingDirectory) {
ProcessesUtil util = new ProcessesUtil(workingDirectory); ProcessesUtil util = new ProcessesUtil(workingDirectory);
set.add(util); set.add(util);
return 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) { public boolean exec(String command) {
commandLine = CommandLine.parse(command); commandLine = CommandLine.parse(command);
try { try {

View File

@ -146,54 +146,6 @@ public class MainController extends BaseController<MainViewModel> {
); );
} }
/**
* 设置文件拖拽效果
*/
private void setDragAction(Pane fileBox) {
// 进入
fileBox.setOnDragEntered(dragEvent -> {
var dragboard = dragEvent.getDragboard();
if (dragboard.hasFiles() && isPboFile(dragboard.getFiles().getFirst())) {
selectFileBox.setVisible(true);
dragFileView.setVisible(true);
}
});
//离开
fileBox.setOnDragExited(_ -> {
selectFileBox.setVisible(false);
dragFileView.setVisible(false);
});
//
fileBox.setOnDragOver(dragEvent -> {
var dragboard = dragEvent.getDragboard();
if (dragEvent.getGestureSource() != fileBox && dragboard.hasFiles()) {
/* allow for both copying and moving, whatever user chooses */
dragEvent.acceptTransferModes(TransferMode.COPY_OR_MOVE);
}
dragEvent.consume();
});
// 松手
fileBox.setOnDragDropped(dragEvent -> {
dragFileView.setVisible(false);
var db = dragEvent.getDragboard();
boolean success = false;
var file = db.getFiles().getFirst();
if (db.hasFiles() && isPboFile(file)) {
selectFile(file);
success = true;
}
/* 让源知道字符串是否已成功传输和使用 */
dragEvent.setDropCompleted(success);
dragEvent.consume();
});
}
/** /**
* 打开文件选择器 * 打开文件选择器
*/ */
@ -215,6 +167,13 @@ public class MainController extends BaseController<MainViewModel> {
ViewUtil.openDecorated("翻译设置", "setup/translate-view"); ViewUtil.openDecorated("翻译设置", "setup/translate-view");
} }
/**
* 帮助
*/
public void openHelp() {
Context.openUrl("https://www.52pojie.cn/thread-1891962-1-1.html");
}
/** /**
* 关于 * 关于
*/ */
@ -222,6 +181,26 @@ public class MainController extends BaseController<MainViewModel> {
ViewUtil.openDecorated("关于", "about-view"); ViewUtil.openDecorated("关于", "about-view");
} }
public void startTranslate() {
viewModel.startTranslate();
}
public void startPack() {
viewModel.pack();
}
public void selectAllLog() {
logArea.selectAll();
}
public void copyLog() {
logArea.copy();
}
public void clearLog() {
logArea.clear();
}
/** /**
* 显示加载PBO文件 * 显示加载PBO文件
*/ */
@ -289,27 +268,55 @@ public class MainController extends BaseController<MainViewModel> {
} }
} }
public void startTranslate() { // ======================================{ private }========================================
viewModel.startTranslate();
}
public void startPack() { /**
viewModel.pack(); * 设置文件拖拽效果
} */
private void setDragAction(Pane fileBox) {
public void selectAllLog() { // 进入
logArea.selectAll(); fileBox.setOnDragEntered(dragEvent -> {
} var dragboard = dragEvent.getDragboard();
if (dragboard.hasFiles() && isPboFile(dragboard.getFiles().getFirst())) {
selectFileBox.setVisible(true);
dragFileView.setVisible(true);
}
});
public void copyLog() { //离开
logArea.copy(); fileBox.setOnDragExited(_ -> {
} selectFileBox.setVisible(false);
dragFileView.setVisible(false);
});
public void clearLog() { //
logArea.clear(); fileBox.setOnDragOver(dragEvent -> {
} var dragboard = dragEvent.getDragboard();
if (dragEvent.getGestureSource() != fileBox && dragboard.hasFiles()) {
/* allow for both copying and moving, whatever user chooses */
dragEvent.acceptTransferModes(TransferMode.COPY_OR_MOVE);
}
dragEvent.consume();
});
// ======================================{ }======================================== // 松手
fileBox.setOnDragDropped(dragEvent -> {
dragFileView.setVisible(false);
var db = dragEvent.getDragboard();
boolean success = false;
var file = db.getFiles().getFirst();
if (db.hasFiles() && isPboFile(file)) {
selectFile(file);
success = true;
}
/* 让源知道字符串是否已成功传输和使用 */
dragEvent.setDropCompleted(success);
dragEvent.consume();
});
}
/** /**
* 打开文件 * 打开文件

View File

@ -37,10 +37,14 @@ public class AboutController extends BaseController<AboutViewModel> {
} }
public void openGitee() { public void openGitee() {
Context.openUrl("https://gitee.com/octopus_yan/dayz-mod-translator"); Context.openUrl("https://gitee.com/octopus_yan/dayz-mod-translator/releases");
} }
public void openGithub() { public void openGithub() {
Context.openUrl("https://github.com/octopusYan/dayz-mod-translator"); Context.openUrl("https://github.com/octopusYan/dayz-mod-translator/releases");
}
public void openForum() {
Context.openUrl("https://www.52pojie.cn/thread-1891962-1-1.html");
} }
} }

View File

@ -1,12 +1,15 @@
package cn.octopusyan.dmt.utils; package cn.octopusyan.dmt.utils;
import cn.octopusyan.dmt.common.config.Constants; import cn.octopusyan.dmt.common.config.Constants;
import cn.octopusyan.dmt.common.config.Context;
import cn.octopusyan.dmt.common.util.ProcessesUtil; import cn.octopusyan.dmt.common.util.ProcessesUtil;
import cn.octopusyan.dmt.model.WordItem; import cn.octopusyan.dmt.model.WordItem;
import cn.octopusyan.dmt.view.ConsoleLog; import cn.octopusyan.dmt.view.ConsoleLog;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.io.LineIterator; import org.apache.commons.io.LineIterator;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -24,13 +27,14 @@ import java.util.stream.Collectors;
* @author octopus_yan * @author octopus_yan
*/ */
public class PBOUtil { public class PBOUtil {
private static final Logger log = LoggerFactory.getLogger(PBOUtil.class);
public static final ConsoleLog consoleLog = ConsoleLog.getInstance(PBOUtil.class); public static final ConsoleLog consoleLog = ConsoleLog.getInstance(PBOUtil.class);
private static final ProcessesUtil processesUtil = ProcessesUtil.init(Constants.BIN_DIR_PATH); 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 UNPACK_COMMAND = STR."\"\{Constants.PBOC_FILE}\" unpack -o \"\{Constants.TMP_DIR_PATH}\" {}";
private static final String PACK_COMMAND = STR."\{Constants.PBOC_FILE} pack -o %s %s"; private static final String PACK_COMMAND = STR."\"\{Constants.PBOC_FILE}\" pack -o {} {}";
private static final String CFG_COMMAND = STR."\{Constants.CFG_CONVERT_FILE} %s -dst %s %s"; 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_STRING_TABLE = "stringtable.csv";
private static final String FILE_NAME_CONFIG_BIN = "config.bin"; private static final String FILE_NAME_CONFIG_BIN = "config.bin";
@ -42,14 +46,20 @@ public class PBOUtil {
public static void init() { public static void init() {
String srcFilePath = Objects.requireNonNull(PBOUtil.class.getResource("/bin")).getPath();
try { try {
File destDir = new File(Constants.BIN_DIR_PATH); File destDir = new File(Constants.BIN_DIR_PATH);
if (destDir.exists()) return;
if (!Context.isDebugMode())
throw new RuntimeException("Util 初始化失败");
String srcFilePath = Resources.getResource("bin").getPath();
FileUtils.forceMkdir(destDir); FileUtils.forceMkdir(destDir);
FileUtils.copyDirectory(new File(srcFilePath), destDir); FileUtils.copyDirectory(new File(srcFilePath), destDir);
} catch (IOException e) { } catch (IOException e) {
consoleLog.error("Util 初始化失败", e); log.error("Util 初始化失败", e);
} }
} }
@ -82,7 +92,7 @@ public class PBOUtil {
throw new RuntimeException("文件夹创建失败", e); 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}]"); consoleLog.debug(STR."unpack command ==> [\{command}]");
boolean exec = processesUtil.exec(command); boolean exec = processesUtil.exec(command);
if (!exec) if (!exec)
@ -107,7 +117,7 @@ public class PBOUtil {
FileUtils.deleteQuietly(packFile); 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}]"); consoleLog.debug(STR."pack command ==> [\{command}]");
boolean exec = processesUtil.exec(command); boolean exec = processesUtil.exec(command);
@ -390,7 +400,7 @@ public class PBOUtil {
private static String toBinCommand(File cppFile) { private static String toBinCommand(File cppFile) {
String outFilePath = outFilePath(cppFile, ".bin"); String outFilePath = outFilePath(cppFile, ".bin");
outFilePath = outFilePath.replace(Constants.BAK_DIR_PATH, Constants.TMP_DIR_PATH); 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());
} }
/** /**
@ -398,7 +408,7 @@ public class PBOUtil {
*/ */
private static String toTxtCommand(File binFile) { private static String toTxtCommand(File binFile) {
String outFilePath = outFilePath(binFile, ".cpp"); 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) { private static String outFilePath(File file, String suffix) {

View File

@ -1,10 +1,10 @@
package cn.octopusyan.dmt.view; package cn.octopusyan.dmt.view;
import cn.octopusyan.dmt.common.config.Context;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.scene.control.TextArea; import javafx.scene.control.TextArea;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -23,8 +23,6 @@ public class ConsoleLog {
private static Logger markerLog; private static Logger markerLog;
private static TextArea logArea; private static TextArea logArea;
private final String tag; private final String tag;
@Setter
private static boolean showDebug = false;
public static void init(TextArea logArea) { public static void init(TextArea logArea) {
ConsoleLog.logArea = logArea; ConsoleLog.logArea = logArea;
@ -56,7 +54,7 @@ public class ConsoleLog {
} }
public void debug(String message, Object... param) { public void debug(String message, Object... param) {
if (!showDebug) return; if (!Context.isDebugMode()) return;
printLog(tag, Level.DEBUG, message, param); printLog(tag, Level.DEBUG, message, param);
} }

View File

@ -17,6 +17,7 @@ module cn.octopusyan.dmt {
requires java.prefs; requires java.prefs;
requires org.kordamp.ikonli.javafx; requires org.kordamp.ikonli.javafx;
requires org.kordamp.ikonli.feather; requires org.kordamp.ikonli.feather;
requires java.management;
exports cn.octopusyan.dmt; exports cn.octopusyan.dmt;
exports cn.octopusyan.dmt.model to com.fasterxml.jackson.databind; exports cn.octopusyan.dmt.model to com.fasterxml.jackson.databind;

View File

@ -1,5 +1,5 @@
#root #titleBox { #root #titleBox {
-fx-padding: 0 0 0 120; -fx-padding: 0 0 0 70;
-fx-background-color: -color-neutral-muted; -fx-background-color: -color-neutral-muted;
} }
@ -9,6 +9,6 @@
} }
#root #infoBox { #root #infoBox {
-fx-spacing: 25; -fx-spacing: 20;
-fx-padding: 50 0 0 120; -fx-padding: 30 0 0 70;
} }

View File

@ -6,7 +6,7 @@
<VBox xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml" <VBox xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml"
fx:controller="cn.octopusyan.dmt.controller.help.AboutController" fx:controller="cn.octopusyan.dmt.controller.help.AboutController"
stylesheets="@../css/about-view.css" stylesheets="@../css/about-view.css"
fx:id="root" prefHeight="400.0" prefWidth="600.0"> fx:id="root" prefHeight="350.0" prefWidth="500.0">
<VBox id="titleBox" alignment="CENTER_LEFT" prefWidth="${root.width}" prefHeight="100"> <VBox id="titleBox" alignment="CENTER_LEFT" prefWidth="${root.width}" prefHeight="100">
<Label fx:id="title" text="title"/> <Label fx:id="title" text="title"/>
@ -21,5 +21,9 @@
<Hyperlink text="Gitee" onAction="#openGitee"/> <Hyperlink text="Gitee" onAction="#openGitee"/>
<Hyperlink text="Github" onAction="#openGithub"/> <Hyperlink text="Github" onAction="#openGithub"/>
</HBox> </HBox>
<HBox spacing="20">
<Label text="发布地址"/>
<Hyperlink text="52pojie.cn" onAction="#openForum"/>
</HBox>
</VBox> </VBox>
</VBox> </VBox>

View File

@ -35,6 +35,11 @@
</MenuItem> </MenuItem>
</Menu> </Menu>
<Menu mnemonicParsing="false" text="帮助"> <Menu mnemonicParsing="false" text="帮助">
<MenuItem text="帮助" onAction="#openHelp">
<graphic>
<FontIcon iconLiteral="fth-help-circle"/>
</graphic>
</MenuItem>
<MenuItem text="关于" onAction="#openAbout"> <MenuItem text="关于" onAction="#openAbout">
<graphic> <graphic>
<FontIcon iconLiteral="fth-info"/> <FontIcon iconLiteral="fth-info"/>