mirror of
https://github.com/HolographicHat/Yae.git
synced 2026-05-20 20:55:46 +08:00
support gbk encoding
This commit is contained in:
@@ -1,26 +1,31 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "define.h"
|
#include "define.h"
|
||||||
|
|
||||||
wstring StringToWString(const string &src) {
|
string GBKToUTF8(const wstring& src) {
|
||||||
wstring result;
|
int len = WideCharToMultiByte(CP_UTF8, 0, src.c_str(), -1, nullptr, 0, nullptr, nullptr);
|
||||||
int len = MultiByteToWideChar(CP_ACP, 0, src.c_str(), src.size(), nullptr, 0); // NOLINT(cppcoreguidelines-narrowing-conversions)
|
auto *buffer = new CHAR[len];
|
||||||
auto *buffer = new WCHAR[len + 1];
|
WideCharToMultiByte(CP_UTF8, 0, src.c_str(), -1, buffer, len, nullptr, nullptr);
|
||||||
MultiByteToWideChar(CP_ACP, 0, src.c_str(), src.size(), buffer, len); // NOLINT(cppcoreguidelines-narrowing-conversions)
|
string strTemp(buffer);
|
||||||
buffer[len] = '\0';
|
|
||||||
result.append(buffer);
|
|
||||||
delete[] buffer;
|
delete[] buffer;
|
||||||
return result;
|
return strTemp;
|
||||||
|
}
|
||||||
|
|
||||||
|
wstring StringToWString(const string &src) {
|
||||||
|
int len = MultiByteToWideChar(CP_ACP, 0, src.c_str(), -1, nullptr, 0);
|
||||||
|
auto *buffer = new WCHAR[len];
|
||||||
|
MultiByteToWideChar(CP_ACP, 0, src.c_str(), -1, buffer, len);
|
||||||
|
wstring strTemp(buffer);
|
||||||
|
delete[] buffer;
|
||||||
|
return strTemp;
|
||||||
}
|
}
|
||||||
|
|
||||||
string WStringToString(const wstring &src) {
|
string WStringToString(const wstring &src) {
|
||||||
string result;
|
int len = WideCharToMultiByte(CP_ACP, 0, src.c_str(), -1, nullptr, 0, nullptr, nullptr);
|
||||||
int len = WideCharToMultiByte(CP_ACP, 0, src.c_str(), src.size(), nullptr, 0, nullptr, nullptr); // NOLINT(cppcoreguidelines-narrowing-conversions)
|
auto *buffer = new CHAR[len];
|
||||||
char *buffer = new char[len + 1];
|
WideCharToMultiByte(CP_ACP, 0, src.c_str(), -1, buffer, len, nullptr, nullptr);
|
||||||
WideCharToMultiByte(CP_ACP, 0, src.c_str(), src.size(), buffer, len, nullptr, nullptr); // NOLINT(cppcoreguidelines-narrowing-conversions)
|
string strTemp(buffer);
|
||||||
buffer[len] = '\0';
|
|
||||||
result.append(buffer);
|
|
||||||
delete[] buffer;
|
delete[] buffer;
|
||||||
return result;
|
return strTemp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Log(Env env, const string &msg) {
|
void Log(Env env, const string &msg) {
|
||||||
@@ -46,7 +51,11 @@ LSTATUS OpenFile(Env env, Napi::String &result, HWND parent) {
|
|||||||
open.lpstrFilter = L"国服/国际服主程序 (YuanShen/GenshinImpact.exe)\0YuanShen.exe;GenshinImpact.exe\0";
|
open.lpstrFilter = L"国服/国际服主程序 (YuanShen/GenshinImpact.exe)\0YuanShen.exe;GenshinImpact.exe\0";
|
||||||
open.lStructSize = sizeof(open);
|
open.lStructSize = sizeof(open);
|
||||||
if(GetOpenFileName(&open)) {
|
if(GetOpenFileName(&open)) {
|
||||||
result = Napi::String::New(env, WStringToString(file));
|
if (GetACP() == 936) {
|
||||||
|
result = Napi::String::New(env, GBKToUTF8(file));
|
||||||
|
} else {
|
||||||
|
result = Napi::String::New(env, WStringToString(file));
|
||||||
|
}
|
||||||
return ERROR_SUCCESS;
|
return ERROR_SUCCESS;
|
||||||
} else {
|
} else {
|
||||||
return ERROR_ERRORS_ENCOUNTERED;
|
return ERROR_ERRORS_ENCOUNTERED;
|
||||||
|
|||||||
Reference in New Issue
Block a user