Skip to content

Commit 532a514

Browse files
committed
用s2ws替换xmlCharToWideString里面重复的内容;删除了没有用到的include:Windows.h;修改了README;
1 parent 8876ee8 commit 532a514

File tree

6 files changed

+29
-31
lines changed

6 files changed

+29
-31
lines changed

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
## 编译要求
22

3-
cpp分支是sln格式(CMake在Windows上实在搞不定libxml2),linux和mac的CMake分支基本是同步的。在Windows上建议使用[vcpkg](https://github.com/microsoft/vcpkg)
3+
cpp分支是sln格式。cmake分支当前正在Windows上的优化,Mac和Linux平台暂时还没有测试,应该会缺少一些header。在Windows上建议使用[vcpkg](https://github.com/microsoft/vcpkg)
44
安装依赖。只测试了64位系统(x64-windows和arm64)。
55

66
- C++20
77
- plog
88
- libxml2
99
- fmt
1010

11+
编译前请自行添加cmake命令行参数指向你的`vcpkg.cmake`
12+
,例如`-DCMAKE_TOOLCHAIN_FILE=D:/vcpkg/scripts/buildsystems/vcpkg.cmake`
13+
1114
## 用法
1215

1316
运行`RWSimplifiedPatcher.exe`
@@ -35,8 +38,7 @@ cpp分支是sln格式(CMake在Windows上实在搞不定libxml2),linux和ma
3538
xml的方法翻译了[WallStuff](https://steamcommunity.com/sharedfiles/filedetails/?id=1994340640)
3639
的defs。然后我发现这个xml生成过程是可以自动化的……~~
3740

38-
最近趁休假,重新按照本来应该用的翻译方式[Mod_folder_structure](https://rimworldwiki.com/wiki/Modding_Tutorials/Mod_folder_structure#The
39-
Languages folder)
41+
最近趁休假,重新按照本来应该用的翻译方式[Mod_folder_structure](https://rimworldwiki.com/wiki/Modding_Tutorials/Mod_folder_structure#The_Languages_folder)
4042
,参考[Rimworld Mod教程 第七章:翻译包文件](https://blog.csdn.net/qq_58145131/article/details/123726403)
4143
,重写了程序。
4244

@@ -56,5 +58,6 @@ xml。~~
5658

5759
## Todo
5860

59-
- [ ] 自动读取和成成About.xml
60-
- [ ] ~~[ ] [[notlikely]] GUI~~
61+
- [ ] 自动读取和生成汉化Mod的所有结构
62+
- [ ] Mac平台的wchar_t支持测试
63+
- [ ] 简单的图形界面

README_EN.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
Warning: Hasn't been updated. Please use Google Translate to read README.md
2+
13
## Compile Requirement
24

35
- c++20: for `std::format` and `std::filesystem`

helper/helper.cpp

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,8 @@
11
#include "helper.hpp"
22

3-
std::wstring xmlCharToWideString(const xmlChar *xmlString) {
4-
if (!xmlString) {
5-
PLOGF << "provided string was null";
6-
abort();
7-
}//provided string was null
8-
try {
9-
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> conv;
10-
return conv.from_bytes((const char *) xmlString);
11-
} catch (const std::range_error &e) {
12-
PLOGF << e.what();
13-
abort();//wstring_convert failed
14-
}
15-
}
16-
173
std::wstring s2ws(const std::string &str) {
184
using convert_typeX = std::codecvt_utf8<wchar_t>;
195
std::wstring_convert<convert_typeX, wchar_t> converterX;
20-
216
return converterX.from_bytes(str);
227
}
238

@@ -28,6 +13,19 @@ std::string ws2s(const std::wstring &wstr) {
2813
return converterX.to_bytes(wstr);
2914
}
3015

16+
std::wstring xmlCharToWideString(const xmlChar *xmlString) {
17+
if (!xmlString) {
18+
PLOGF << "provided string was null";
19+
abort();
20+
}
21+
try {
22+
return s2ws((const char *) xmlString);
23+
} catch (const std::exception &e) {
24+
PLOGF << e.what();
25+
abort();//wstring_convert failed
26+
}
27+
}
28+
3129
std::wstring getXPath(xmlNodePtr node) {
3230
auto internal_str = xmlGetNodePath(node);
3331
std::wstring rval = xmlCharToWideString(internal_str);
@@ -78,7 +76,7 @@ std::wstring getDefNameFromXPath(xmlDocPtr doc, const std::wstring &node_xpath)
7876
return L"";
7977
}
8078

81-
std::wstring getliParentTagName(const std::wstring &xpath_containing_li) {
79+
std::wstring get_li_parent_tag_name(const std::wstring &xpath_containing_li) {
8280
std::wregex li_pattern(L"/(\\w*)/li(\\[|/)");
8381
std::wsmatch li_match;
8482
if (std::regex_search(xpath_containing_li, li_match, li_pattern)) {
@@ -87,7 +85,7 @@ std::wstring getliParentTagName(const std::wstring &xpath_containing_li) {
8785
throw std::runtime_error("Invalid xpath: no li found");
8886
}
8987

90-
bool getliNumber(const std::wstring &xpath_containing_li, long *result) {
88+
bool get_li_number(const std::wstring &xpath_containing_li, long *result) {
9189
std::wregex li_number_pattern(LR"(/\w*/li\[(\d*)\]/)");
9290
std::wsmatch li_match;
9391
if (std::regex_search(xpath_containing_li, li_match, li_number_pattern)) {

helper/helper.hpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
#ifdef WIN32
44
#pragma warning(disable : 4996)
5-
6-
#include <Windows.h>
7-
85
#define _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING
96
#define _CRT_SECURE_NO_WARNINGS
107
#endif
@@ -40,9 +37,9 @@ std::vector<xmlNodePtr> getNodeSet(const xmlXPathObject *xpath_result);
4037

4138
std::wstring getDefNameFromXPath(xmlDocPtr doc, const std::wstring &node_xpath);
4239

43-
std::wstring getliParentTagName(const std::wstring &xpath_containing_li);
40+
std::wstring get_li_parent_tag_name(const std::wstring &xpath_containing_li);
4441

45-
bool getliNumber(const std::wstring &xpath_containing_li, long *result);
42+
bool get_li_number(const std::wstring &xpath_containing_li, long *result);
4643

4744
/**
4845
* generate corresponding output directory for this xpath

main.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//
44

55
#ifdef WIN32
6-
#include <Windows.h>
76
#endif
87

98
#include "helper/helper.hpp"
@@ -110,10 +109,10 @@ int main(int argc, char **argv) {
110109
} else {
111110
// 这里处理的就是作为某个li元素里面的label了
112111
// 例子是/Defs/AlienRace.ThingDef_AlienRace/tools/li[1]/label
113-
auto name = getliParentTagName(xpath);
112+
auto name = get_li_parent_tag_name(xpath);
114113
long int li_number;
115114
// 有的li有序号,有的没有
116-
if (getliNumber(xpath, &li_number)) {
115+
if (get_li_number(xpath, &li_number)) {
117116
auto final_tag_name =
118117
// clang-format off
119118
fmt::format(L"<{defName}.{liName}.{liNumber}.{type}>{text}</{defName}.{liName}.{liNumber}.{type}>\n",

replace/replace.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#pragma warning(disable : 4996)
33
#define _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING
44
#define _CRT_SECURE_NO_WARNINGS
5-
#include <Windows.h>
65
#endif
76

87
#include "../helper/helper.hpp"

0 commit comments

Comments
 (0)