Compare commits

..

No commits in common. "c6ad66bb593c8e61b1c8e83e7590baddea9606c5" and "9edc015af064b0bb0fa6a3a65c2558068fc33780" have entirely different histories.

12 changed files with 101 additions and 185 deletions

View File

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

47
pom.xml
View File

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

View File

@ -16,8 +16,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
@ -41,15 +39,11 @@ public class Context {
@Getter
private static final Map<String, BaseController<?>> controllers = new HashMap<>();
private Context() {
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() {
return type -> {

View File

@ -52,34 +52,12 @@ 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 {

View File

@ -146,6 +146,54 @@ 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();
});
}
/**
* 打开文件选择器
*/
@ -167,13 +215,6 @@ public class MainController extends BaseController<MainViewModel> {
ViewUtil.openDecorated("翻译设置", "setup/translate-view");
}
/**
* 帮助
*/
public void openHelp() {
Context.openUrl("https://www.52pojie.cn/thread-1891962-1-1.html");
}
/**
* 关于
*/
@ -181,26 +222,6 @@ public class MainController extends BaseController<MainViewModel> {
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文件
*/
@ -268,56 +289,28 @@ public class MainController extends BaseController<MainViewModel> {
}
}
// ======================================{ private }========================================
/**
* 设置文件拖拽效果
*/
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();
});
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();
}
// ======================================{ }========================================
/**
* 打开文件
*/

View File

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

View File

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

View File

@ -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,6 +23,8 @@ 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;
@ -54,7 +56,7 @@ public class ConsoleLog {
}
public void debug(String message, Object... param) {
if (!Context.isDebugMode()) return;
if (!showDebug) return;
printLog(tag, Level.DEBUG, message, param);
}

View File

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

View File

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

View File

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

View File

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