mirror of
https://github.com/octopusYan/dayz-mod-translator.git
synced 2024-11-21 11:46:43 +08:00
Compare commits
6 Commits
9edc015af0
...
c6ad66bb59
Author | SHA1 | Date | |
---|---|---|---|
c6ad66bb59 | |||
92f9737e27 | |||
227f565991 | |||
76968cfd49 | |||
5ac5297184 | |||
1dc6e95340 |
@ -53,7 +53,7 @@
|
||||
```
|
||||
2. 运行
|
||||
```bash
|
||||
mvn clean javafx:run
|
||||
mvn clean javafx:run -Pdev
|
||||
```
|
||||
|
||||
#### 打包
|
||||
@ -64,7 +64,7 @@
|
||||
```
|
||||
2. 运行
|
||||
```bash
|
||||
mvn clean package
|
||||
mvn clean package -Pbuild
|
||||
```
|
||||
|
||||
### 可能会用到
|
||||
|
47
pom.xml
47
pom.xml
@ -6,8 +6,8 @@
|
||||
|
||||
<groupId>cn.octopusyan</groupId>
|
||||
<artifactId>dmt</artifactId>
|
||||
<version>0.0.2</version>
|
||||
<name>dmt</name>
|
||||
<version>0.1.2</version>
|
||||
<name>DayzModTranslator</name>
|
||||
|
||||
<organization>
|
||||
<name>octopus_yan</name>
|
||||
@ -172,14 +172,41 @@
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<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>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
@ -233,7 +260,7 @@
|
||||
<configuration>
|
||||
<options>
|
||||
<option>--enable-preview</option>
|
||||
<!-- <option>-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005</option>-->
|
||||
<option>${debug.option}</option>
|
||||
</options>
|
||||
</configuration>
|
||||
</execution>
|
||||
|
@ -16,6 +16,8 @@ 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;
|
||||
@ -39,11 +41,15 @@ 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 -> {
|
||||
|
@ -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 {
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
/**
|
||||
* 帮助
|
||||
*/
|
||||
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");
|
||||
}
|
||||
|
||||
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文件
|
||||
*/
|
||||
@ -289,27 +268,55 @@ public class MainController extends BaseController<MainViewModel> {
|
||||
}
|
||||
}
|
||||
|
||||
public void startTranslate() {
|
||||
viewModel.startTranslate();
|
||||
}
|
||||
// ======================================{ private }========================================
|
||||
|
||||
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();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开文件
|
||||
|
@ -37,10 +37,14 @@ public class AboutController extends BaseController<AboutViewModel> {
|
||||
}
|
||||
|
||||
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() {
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,15 @@
|
||||
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;
|
||||
@ -24,13 +27,14 @@ 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} %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";
|
||||
@ -42,14 +46,20 @@ 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) {
|
||||
consoleLog.error("Util 初始化失败", e);
|
||||
log.error("Util 初始化失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -82,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)
|
||||
@ -107,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);
|
||||
@ -390,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());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -398,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) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@ 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;
|
||||
|
@ -1,5 +1,5 @@
|
||||
#root #titleBox {
|
||||
-fx-padding: 0 0 0 120;
|
||||
-fx-padding: 0 0 0 70;
|
||||
-fx-background-color: -color-neutral-muted;
|
||||
}
|
||||
|
||||
@ -9,6 +9,6 @@
|
||||
}
|
||||
|
||||
#root #infoBox {
|
||||
-fx-spacing: 25;
|
||||
-fx-padding: 50 0 0 120;
|
||||
-fx-spacing: 20;
|
||||
-fx-padding: 30 0 0 70;
|
||||
}
|
@ -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="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">
|
||||
<Label fx:id="title" text="title"/>
|
||||
@ -21,5 +21,9 @@
|
||||
<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>
|
||||
|
@ -35,6 +35,11 @@
|
||||
</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"/>
|
||||
|
Loading…
Reference in New Issue
Block a user