i18n: UTF-8 protocol capability + Unicode rendering on server
This commit is contained in:
@@ -1468,8 +1468,24 @@ std::string CWebService::BuildDeviceListJson(const std::string& username) {
|
||||
CString version = ctx->GetClientData(ONLINELIST_VERSION);
|
||||
device["version"] = AnsiToUtf8(version);
|
||||
|
||||
// 活动窗口编码由客户端能力位决定:新客户端是 UTF-8,老客户端是 CP_ACP(默认 936)。
|
||||
// 不能像其它字段那样无脑 AnsiToUtf8——会把新客户端的 UTF-8 字节再当 GBK 双重编码。
|
||||
CString activeWindow = ctx->GetClientData(ONLINELIST_LOGINTIME);
|
||||
device["activeWindow"] = AnsiToUtf8(activeWindow);
|
||||
std::string activeWindowU8;
|
||||
if (!activeWindow.IsEmpty()) {
|
||||
UINT cp = GetClientEncoding(ctx);
|
||||
int wlen = MultiByteToWideChar(cp, 0, activeWindow, -1, NULL, 0);
|
||||
if (wlen > 1) {
|
||||
std::wstring w(wlen - 1, L'\0');
|
||||
MultiByteToWideChar(cp, 0, activeWindow, -1, &w[0], wlen);
|
||||
int u8len = WideCharToMultiByte(CP_UTF8, 0, w.c_str(), -1, NULL, 0, NULL, NULL);
|
||||
if (u8len > 1) {
|
||||
activeWindowU8.resize(u8len - 1);
|
||||
WideCharToMultiByte(CP_UTF8, 0, w.c_str(), -1, &activeWindowU8[0], u8len, NULL, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
device["activeWindow"] = activeWindowU8;
|
||||
device["online"] = true;
|
||||
|
||||
// Add device group to response
|
||||
|
||||
Reference in New Issue
Block a user