I want to develop a software which can help me manage the .exe file paths to my games. It is expected to run on Windows.
But unfortunately, my games may have the following 2 format:
- ascii + Chinese Character (GBK-encoding), e.g. D:/MyGames/魔女的夜宴/启动.exe
- ascii + Japanese Character (shift-JIS encoding), e.g. D:/MyGames/アンレス テルミナリア/エンジン設定.exe
How can I deal with the different encoding problem?
I tried in C++17. It seems that it works on read/write, but I have no idea how to call an exe file.
using namespace std::string_literals;
namespace filesys = std::filesystem;
//using Char = char16_t;
//using String = std::u16string;
using Char = wchar_t;
using String = std::wstring;
void checkExist(const filesys::path& path) {
std::cout << " existence: " << filesys::exists(path) << '\n';
}
int main () {
std::setlocale(LC_ALL, "");
std::locale::global(std::locale(""));
String str_en(L"../test-english.txt");
String str_zh(L"../test-中文路径.txt");
String str_jp(L"../test-日本語パス.txt");
filesys::path path(str_en);
filesys::path path_zh(str_zh);
filesys::path path_jp(str_jp);
checkExist(path);
checkExist(path_zh);
checkExist(path_jp);
/* Output: See below
*/
filesys::path output_path("read_result.txt");
std::string s;
std::ofstream of(output_path);
getline(std::ifstream(path), s);
of << s << std::endl;
getline(std::ifstream(path_zh), s);
of << s << std::endl;
getline(std::ifstream(path_jp), s);
of << s << std::endl;
/* read_result.txt: See below
*/
wchar_t a[]=L"abc测试测试";
std::wofstream of("write_output.txt");
of << a;
/* write_output.txt: See below
*/
}
My file tree
.
├── CMakeLists.txt
├── cmake-build-debug-mingw
├── cmake-build-debug-visual-studio
├── main.cpp
├── test-english.txt
├── test-中文路径.txt
└── test-日本語パス.txt
MinGW compiler | MSVC compiler | |
---|---|---|
Output | existence: 1 existence: 1 existence: 1 |
existence: 1 existence: 0 existence: 0 |
read_result.txt | "Eng success" "Ch success" "Jap success" |
"Eng success" "Eng success" "Eng success" |
write_output.txt | "" | "abc测试测试" |
Emmm... Maybe I should take think about completing it in Python?