This commit is contained in:
HolographicHat
2022-04-17 22:54:35 +08:00
parent a8b6419157
commit 28080dbafd
5 changed files with 20 additions and 27 deletions

View File

@@ -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)
}

View File

@@ -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));
}

View 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);

View File

@@ -36,22 +36,22 @@ const cleanUp = () => {
const c = {
finalName: `${name}-Win7`,
nodeVersion: "14.19.1",
forWin7: false,
sevenZipPath: "\"C:/Program Files/7-Zip/7z.exe\""
};
(async () => {
console.log(c)
const fn = c.forWin7 ? `${name}-Win7` : name
const nv = c.forWin7 ? "14.19.1" : "16.14.2"
log("Generate and compile version info")
generateAndCompileVersionInfo()
log("Modify executable file resources")
const path = `C:/Users/holog/.pkg-cache/v3.3/built-v${c.nodeVersion}-win-x64`
const path = `C:/Users/holog/.pkg-cache/v3.3/built-v${nv}-win-x64`
generateScript(path)
execSync(`rh.exe -script tmp.script`)
cleanUp()
log("Build and compress package")
await pkg.exec(`../app.js -t node${c.nodeVersion.split(".")[0]}-win-x64 -C Brotli --build -o ${c.finalName}.exe`.split(" "))
execSync(`${c.sevenZipPath} a ${c.finalName}.7z ${c.finalName}.exe -mx=9 -myx=9 -mmt=4 -sdel -stl`)
await pkg.exec(`../app.js -t node${nv.split(".")[0]}-win-x64 -C Brotli --build -o ${fn}.exe`.split(" "))
execSync(`${c.sevenZipPath} a ${fn}.7z ${fn}.exe -mx=9 -myx=9 -mmt=4 -sdel -stl`)
log("Done")
})()

View File

@@ -1,7 +1,7 @@
const version = {
code: 7,
name: "1.6",
isDev: false
name: "1.6.50",
isDev: true
}
module.exports = { version }