mirror of
https://github.com/HolographicHat/Yae.git
synced 2026-03-19 02:49:47 +08:00
fix
This commit is contained in:
@@ -171,7 +171,9 @@ namespace native {
|
||||
|
||||
Value openUrl(const CallbackInfo &info) {
|
||||
Env env = info.Env();
|
||||
wstring url = StringToWString(info[0].As<Napi::String>().Utf8Value());
|
||||
string nUrl = info[0].As<Napi::String>().Utf8Value();
|
||||
wstring url = GetACP() == 936 ? StringToWString(nUrl, CP_UTF8) : StringToWString(nUrl);
|
||||
Log(env, L"openUrl: " + url);
|
||||
HINSTANCE retcode = ShellExecute(GetConsoleWindow(), L"open", url.c_str(), nullptr, nullptr, SW_SHOWNORMAL);
|
||||
return Napi::Number::New(env, (INT_PTR)retcode); // NOLINT(cppcoreguidelines-narrowing-conversions)
|
||||
}
|
||||
|
||||
@@ -1,28 +1,19 @@
|
||||
#include "utils.h"
|
||||
#include "define.h"
|
||||
|
||||
string GBKToUTF8(const wstring& src) {
|
||||
int len = WideCharToMultiByte(CP_UTF8, 0, src.c_str(), -1, nullptr, 0, nullptr, nullptr);
|
||||
auto *buffer = new CHAR[len];
|
||||
WideCharToMultiByte(CP_UTF8, 0, src.c_str(), -1, buffer, len, nullptr, nullptr);
|
||||
string strTemp(buffer);
|
||||
delete[] buffer;
|
||||
return strTemp;
|
||||
}
|
||||
|
||||
wstring StringToWString(const string &src) {
|
||||
int len = MultiByteToWideChar(CP_ACP, 0, src.c_str(), -1, nullptr, 0);
|
||||
wstring StringToWString(const string &src, UINT codePage) {
|
||||
int len = MultiByteToWideChar(codePage, 0, src.c_str(), -1, nullptr, 0);
|
||||
auto *buffer = new WCHAR[len];
|
||||
MultiByteToWideChar(CP_ACP, 0, src.c_str(), -1, buffer, len);
|
||||
MultiByteToWideChar(codePage, 0, src.c_str(), -1, buffer, len);
|
||||
wstring strTemp(buffer);
|
||||
delete[] buffer;
|
||||
return strTemp;
|
||||
}
|
||||
|
||||
string WStringToString(const wstring &src) {
|
||||
int len = WideCharToMultiByte(CP_ACP, 0, src.c_str(), -1, nullptr, 0, nullptr, nullptr);
|
||||
string WStringToString(const wstring &src, UINT codePage) {
|
||||
int len = WideCharToMultiByte(codePage, 0, src.c_str(), -1, nullptr, 0, nullptr, nullptr);
|
||||
auto *buffer = new CHAR[len];
|
||||
WideCharToMultiByte(CP_ACP, 0, src.c_str(), -1, buffer, len, nullptr, nullptr);
|
||||
WideCharToMultiByte(codePage, 0, src.c_str(), -1, buffer, len, nullptr, nullptr);
|
||||
string strTemp(buffer);
|
||||
delete[] buffer;
|
||||
return strTemp;
|
||||
@@ -52,7 +43,7 @@ LSTATUS OpenFile(Env env, Napi::String &result, HWND parent) {
|
||||
open.lStructSize = sizeof(open);
|
||||
if(GetOpenFileName(&open)) {
|
||||
if (GetACP() == 936) {
|
||||
result = Napi::String::New(env, GBKToUTF8(file));
|
||||
result = Napi::String::New(env, WStringToString(file, CP_UTF8));
|
||||
} else {
|
||||
result = Napi::String::New(env, WStringToString(file));
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
#include "define.h"
|
||||
|
||||
string WStringToString(const wstring &src);
|
||||
wstring StringToWString(const string &src);
|
||||
string WStringToString(const wstring &src, UINT codePage = CP_ACP);
|
||||
wstring StringToWString(const string &src, UINT codePage = CP_ACP);
|
||||
LSTATUS OpenFile(Env env, Napi::String &result, HWND parent = GetConsoleWindow());
|
||||
BOOL EnablePrivilege(Env env, const wstring &name);
|
||||
void Log(Env env, const string &msg);
|
||||
|
||||
Reference in New Issue
Block a user