encode uri to avoid charset problem

This commit is contained in:
HolographicHat
2022-04-17 23:46:11 +08:00
parent 28080dbafd
commit 4417feab53
4 changed files with 7 additions and 11 deletions

View File

@@ -2,8 +2,8 @@ const fs = require("fs")
const axios = require("axios")
const readline = require("readline")
const { randomUUID } = require("crypto")
const { loadCache, log } = require("./utils")
const { openUrl, checkSnapFastcall, copyToClipboard } = require("./native")
const { loadCache, log, openUrl } = require("./utils")
const { checkSnapFastcall, copyToClipboard } = require("./native")
const exportToSeelie = proto => {
const out = { achievements: {} }

View File

@@ -171,9 +171,7 @@ namespace native {
Value openUrl(const CallbackInfo &info) {
Env env = info.Env();
string nUrl = info[0].As<Napi::String>().Utf8Value();
wstring url = GetACP() == 936 ? StringToWString(nUrl, CP_UTF8) : StringToWString(nUrl);
Log(env, L"openUrl: " + url);
wstring url = StringToWString(info[0].As<Napi::String>().Utf8Value());
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

@@ -42,11 +42,7 @@ LSTATUS OpenFile(Env env, Napi::String &result, HWND parent) {
open.lpstrFilter = L"国服/国际服主程序 (YuanShen/GenshinImpact.exe)\0YuanShen.exe;GenshinImpact.exe\0";
open.lStructSize = sizeof(open);
if(GetOpenFileName(&open)) {
if (GetACP() == 936) {
result = Napi::String::New(env, WStringToString(file, CP_UTF8));
} else {
result = Napi::String::New(env, WStringToString(file));
}
result = GetACP() == 936 ? Napi::String::New(env, WStringToString(file, CP_UTF8)) : Napi::String::New(env, WStringToString(file));
return ERROR_SUCCESS;
} else {
return ERROR_ERRORS_ENCOUNTERED;

View File

@@ -122,6 +122,8 @@ const checkPortIsUsing = () => {
}
}
const openUrl = url => native.openUrl(encodeURI(url))
const splitPacket = buf => {
let offset = 0
let arr = []
@@ -290,5 +292,5 @@ class KPacket {
module.exports = {
log, encodeProto, decodeProto, initConfig, splitPacket, upload, brotliCompressSync, brotliDecompressSync,
setupHost, loadCache, debug, checkUpdate, KPacket, checkGameIsRunning, checkPortIsUsing
setupHost, loadCache, debug, checkUpdate, KPacket, checkGameIsRunning, checkPortIsUsing, openUrl
}