697 lines
36 KiB
C++
697 lines
36 KiB
C++
// shell9.cpp —— DuiLib 版 Windows 验证壳(多套结构不同的皮肤)
|
|||
|
|
//
|
||
|
|
// 与平台验证方式严格对齐(/api/v1/app/<appKey>/login):
|
||
|
|
// POST {username, password, device_id, device_name, device_type, instance_id}
|
||
|
|
// 即「账号(或卡密)+ 密码 + 设备绑定」,不是只填一个卡密框。
|
||
|
|
//
|
||
|
|
// 对外接口不变:
|
||
|
|
// int VerifyMain(void *oep, const char *cfgjson);
|
||
|
|
// int VerifyShellVersion(void); // 9
|
||
|
|
// const char *VerifyShellThemes(void); // 主题清单
|
||
|
|
#include <windows.h>
|
||
|
|
#include <winhttp.h>
|
||
|
|
#include <shlobj.h>
|
||
|
|
#include <shellapi.h>
|
||
|
|
#include <stdio.h>
|
||
|
|
#include <stdlib.h>
|
||
|
|
#include <string.h>
|
||
|
|
#include <string>
|
||
|
|
|
||
|
|
#include "UIlib.h"
|
||
|
|
#include "Utils/WinImplBase.h"
|
||
|
|
|
||
|
|
#pragma comment(lib, "winhttp.lib")
|
||
|
|
|
||
|
|
using namespace DuiLib;
|
||
|
|
|
||
|
|
/* ============================== cfg ============================== */
|
||
|
|
static char g_cfg[4096];
|
||
|
|
static char g_api[512];
|
||
|
|
static char g_name[128] = "\xE6\xBC\x94\xE7\xA4\xBA\xE7\xA8\x8B\xE5\xBA\x8F"; // 演示程序
|
||
|
|
static char g_theme[32] = "dark";
|
||
|
|
static char g_device[64] = "";
|
||
|
|
static char g_instance[64] = "";
|
||
|
|
static int g_deviceAuto = 1;
|
||
|
|
|
||
|
|
static int json_str(const char *src, const char *key, char *out, int cap) {
|
||
|
|
char pat[64]; snprintf(pat, sizeof(pat), "\"%s\"", key);
|
||
|
|
const char *p = strstr(src, pat);
|
||
|
|
if (!p) return 0;
|
||
|
|
p = strchr(p + strlen(pat), ':');
|
||
|
|
if (!p) return 0;
|
||
|
|
while (*p && *p != '"') p++;
|
||
|
|
if (!*p) return 0;
|
||
|
|
p++;
|
||
|
|
int i = 0;
|
||
|
|
while (*p && *p != '"' && i < cap - 1) out[i++] = *p++;
|
||
|
|
out[i] = 0;
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
static int json_int(const char *src, const char *key, int def) {
|
||
|
|
char pat[64]; snprintf(pat, sizeof(pat), "\"%s\"", key);
|
||
|
|
const char *p = strstr(src, pat);
|
||
|
|
if (!p) return def;
|
||
|
|
p = strchr(p + strlen(pat), ':');
|
||
|
|
if (!p) return def;
|
||
|
|
return atoi(p + 1);
|
||
|
|
}
|
||
|
|
|
||
|
|
static void make_machine_id(char *out, int cap);
|
||
|
|
static void load_cfg(const char *json);
|
||
|
|
|
||
|
|
/* ============================ 工具 ============================ */
|
||
|
|
static std::wstring U8(const char *s) {
|
||
|
|
if (!s) return L"";
|
||
|
|
int n = ::MultiByteToWideChar(CP_UTF8, 0, s, -1, NULL, 0);
|
||
|
|
std::wstring w(n > 0 ? n - 1 : 0, L'\0');
|
||
|
|
if (n > 1) ::MultiByteToWideChar(CP_UTF8, 0, s, -1, &w[0], n);
|
||
|
|
return w;
|
||
|
|
}
|
||
|
|
|
||
|
|
static std::string W2U8(const std::wstring &w) {
|
||
|
|
if (w.empty()) return std::string();
|
||
|
|
int n = ::WideCharToMultiByte(CP_UTF8, 0, w.c_str(), -1, NULL, 0, NULL, NULL);
|
||
|
|
std::string s(n > 0 ? n - 1 : 0, '\0');
|
||
|
|
if (n > 1) ::WideCharToMultiByte(CP_UTF8, 0, w.c_str(), -1, &s[0], n, NULL, NULL);
|
||
|
|
return s;
|
||
|
|
}
|
||
|
|
|
||
|
|
// MachineGuid + 系统盘卷序列号 → 稳定机器码(重装系统才变)
|
||
|
|
static void make_machine_id(char *out, int cap) {
|
||
|
|
wchar_t guid[128] = {0};
|
||
|
|
HKEY hk = NULL;
|
||
|
|
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Cryptography",
|
||
|
|
0, KEY_READ | KEY_WOW64_64KEY, &hk) == ERROR_SUCCESS) {
|
||
|
|
DWORD sz = sizeof(guid) - sizeof(wchar_t), type = 0;
|
||
|
|
RegQueryValueExW(hk, L"MachineGuid", NULL, &type, (LPBYTE)guid, &sz);
|
||
|
|
RegCloseKey(hk);
|
||
|
|
}
|
||
|
|
DWORD serial = 0;
|
||
|
|
GetVolumeInformationW(L"C:\\", NULL, 0, &serial, NULL, NULL, NULL, 0);
|
||
|
|
unsigned int h1 = 2166136261u, h2 = 3735928559u;
|
||
|
|
for (const wchar_t *p = guid; *p; p++) {
|
||
|
|
h1 = (h1 ^ (unsigned int)(*p & 0xFF)) * 16777619u;
|
||
|
|
h2 = (h2 ^ (unsigned int)(*p >> 8)) * 16777619u;
|
||
|
|
}
|
||
|
|
h1 = (h1 ^ serial) * 16777619u;
|
||
|
|
h2 = (h2 ^ (serial >> 16)) * 16777619u;
|
||
|
|
snprintf(out, cap, "%04X-%04X-%04X", h1 & 0xFFFF, (h1 >> 16) & 0xFFFF, h2 & 0xFFFF);
|
||
|
|
}
|
||
|
|
|
||
|
|
static std::wstring AccountIniPath() {
|
||
|
|
wchar_t app[MAX_PATH] = {0};
|
||
|
|
::SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, 0, app);
|
||
|
|
std::wstring dir = std::wstring(app) + L"\\vfy";
|
||
|
|
::CreateDirectoryW(dir.c_str(), NULL);
|
||
|
|
return dir + L"\\account.ini";
|
||
|
|
}
|
||
|
|
|
||
|
|
static void SaveAccount(const std::wstring &user, bool remember) {
|
||
|
|
std::wstring p = AccountIniPath();
|
||
|
|
::WritePrivateProfileStringW(L"login", L"remember", remember ? L"1" : L"0", p.c_str());
|
||
|
|
if (remember) ::WritePrivateProfileStringW(L"login", L"user", user.c_str(), p.c_str());
|
||
|
|
}
|
||
|
|
|
||
|
|
static std::wstring LoadAccount(bool &remember) {
|
||
|
|
std::wstring p = AccountIniPath();
|
||
|
|
wchar_t buf[256] = {0};
|
||
|
|
::GetPrivateProfileStringW(L"login", L"remember", L"0", buf, 256, p.c_str());
|
||
|
|
remember = (buf[0] == L'1');
|
||
|
|
wchar_t user[256] = {0};
|
||
|
|
::GetPrivateProfileStringW(L"login", L"user", L"", user, 256, p.c_str());
|
||
|
|
return remember ? std::wstring(user) : std::wstring();
|
||
|
|
}
|
||
|
|
|
||
|
|
/* --------------------------- 皮肤 ---------------------------
|
||
|
|
* 7 套在「结构」上彼此不同,字段集统一按平台验证方式:
|
||
|
|
* 账号(账号或卡密)/ 密码 / 记住账号 / 设备信息 / 登录 / 状态行 / 注册·卡密充值·忘记密码
|
||
|
|
* 注意:老 DuiLib 的 Edit 是「真 EDIT 子窗口」,必须用 nativebkcolor 指定它自己的底色,
|
||
|
|
* 否则聚焦时会出现刺眼的白条(这是它构造里写死 0xFFFFFFFF 导致的)。
|
||
|
|
*/
|
||
|
|
|
||
|
|
// 1) 竖排标准 · 深色
|
||
|
|
static const char *kSkinDark =
|
||
|
|
"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
|
||
|
|
"<Window size=\"440,404\" caption=\"0,0,-1,44\" mininfo=\"440,404\" bkcolor=\"#FF16161A\">"
|
||
|
|
" <VerticalLayout bkcolor=\"#FF16161A\" bordercolor=\"#FF33333A\" bordersize=\"1\">"
|
||
|
|
" <HorizontalLayout height=\"44\" bkcolor=\"#FF1F1F26\">"
|
||
|
|
" <Label text=\"登录以继续\" textcolor=\"#FFEDEDF0\" font=\"1\" inset=\"20,0,0,0\" />"
|
||
|
|
" <Button name=\"btnClose\" text=\"X\" width=\"44\" textcolor=\"#FF9A9AA5\" bkcolor=\"#FF1F1F26\" />"
|
||
|
|
" </HorizontalLayout>"
|
||
|
|
" <VerticalLayout inset=\"24,18,24,16\">"
|
||
|
|
" <Label name=\"lblApp\" text=\"演示程序\" textcolor=\"#FF6FB6E8\" height=\"26\" font=\"1\" />"
|
||
|
|
" <Label text=\"请使用账号或卡密登录\" textcolor=\"#FFB2B2BC\" height=\"20\" />"
|
||
|
|
" <HorizontalLayout height=\"14\" />"
|
||
|
|
" <Label text=\"账号\" textcolor=\"#FFB2B2BC\" height=\"18\" />"
|
||
|
|
" <Edit name=\"editUser\" height=\"40\" bkcolor=\"#FF3C3C49\" nativebkcolor=\"#FF3C3C49\" textcolor=\"#FFF2F2F5\" bordercolor=\"#FF4E4E5C\" inset=\"10,0,0,0\" />"
|
||
|
|
" <HorizontalLayout height=\"10\" />"
|
||
|
|
" <Label text=\"密码\" textcolor=\"#FFB2B2BC\" height=\"18\" />"
|
||
|
|
" <Edit name=\"editPass\" height=\"40\" bkcolor=\"#FF3C3C49\" nativebkcolor=\"#FF3C3C49\" textcolor=\"#FFF2F2F5\" bordercolor=\"#FF4E4E5C\" inset=\"10,0,0,0\" password=\"true\" />"
|
||
|
|
" <HorizontalLayout height=\"10\" />"
|
||
|
|
" <HorizontalLayout height=\"22\">"
|
||
|
|
" <HorizontalLayout height=\"22\"><Label name=\"chkBox\" mouse=\"true\" width=\"14\" height=\"14\" bkcolor=\"#00000000\" bordercolor=\"#FFB2B2BC\" bordersize=\"1\" /><Label width=\"8\" /><Button name=\"btnRemember\" text=\"记住账号\" textcolor=\"#FFB2B2BC\" bkcolor=\"#00000000\" width=\"120\" /></HorizontalLayout>"
|
||
|
|
" </HorizontalLayout>"
|
||
|
|
" <HorizontalLayout height=\"12\" />"
|
||
|
|
" <Button name=\"btnLogin\" text=\"登 录\" height=\"44\" bkcolor=\"#FF146FB8\" textcolor=\"#FFFFFFFF\" font=\"1\" />"
|
||
|
|
" <Label name=\"lblTip\" text=\"\" textcolor=\"#FFD98A8A\" height=\"26\" inset=\"0,6,0,0\" />"
|
||
|
|
" <Label name=\"lblDevice\" text=\"设备\" textcolor=\"#FF62626E\" height=\"18\" />"
|
||
|
|
" <HorizontalLayout height=\"24\">"
|
||
|
|
" <Button name=\"btnLinkReg\" text=\"注册账号\" width=\"96\" textcolor=\"#FF8FB4D8\" bkcolor=\"#00000000\" />"
|
||
|
|
" <Button name=\"btnLinkCard\" text=\"卡密充值\" width=\"96\" textcolor=\"#FF8FB4D8\" bkcolor=\"#00000000\" />"
|
||
|
|
" <Button name=\"btnLinkForgot\" text=\"忘记密码\" width=\"96\" textcolor=\"#FF8FB4D8\" bkcolor=\"#00000000\" />"
|
||
|
|
" </HorizontalLayout>"
|
||
|
|
" </VerticalLayout>"
|
||
|
|
" </VerticalLayout>"
|
||
|
|
"</Window>";
|
||
|
|
|
||
|
|
// 2) 竖排标准 · 浅色
|
||
|
|
static const char *kSkinLight =
|
||
|
|
"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
|
||
|
|
"<Window size=\"440,404\" caption=\"0,0,-1,44\" mininfo=\"440,404\" bkcolor=\"#FFFBFBFD\">"
|
||
|
|
" <VerticalLayout bkcolor=\"#FFFBFBFD\" bordercolor=\"#FFDCDCE2\" bordersize=\"1\">"
|
||
|
|
" <HorizontalLayout height=\"44\" bkcolor=\"#FFFFFFFF\">"
|
||
|
|
" <Label text=\"登录以继续\" textcolor=\"#FF1F1F24\" font=\"1\" inset=\"20,0,0,0\" />"
|
||
|
|
" <Button name=\"btnClose\" text=\"X\" width=\"44\" textcolor=\"#FF6B6B74\" bkcolor=\"#FFFFFFFF\" />"
|
||
|
|
" </HorizontalLayout>"
|
||
|
|
" <VerticalLayout inset=\"24,18,24,16\">"
|
||
|
|
" <Label name=\"lblApp\" text=\"演示程序\" textcolor=\"#FF1B6FD6\" height=\"26\" font=\"1\" />"
|
||
|
|
" <Label text=\"请使用账号或卡密登录\" textcolor=\"#FF454C58\" height=\"20\" />"
|
||
|
|
" <HorizontalLayout height=\"14\" />"
|
||
|
|
" <Label text=\"账号\" textcolor=\"#FF454C58\" height=\"18\" />"
|
||
|
|
" <Edit name=\"editUser\" height=\"40\" bkcolor=\"#FFFFFFFF\" nativebkcolor=\"#FFFFFFFF\" textcolor=\"#FF1F1F24\" bordercolor=\"#FFC9C9D2\" inset=\"10,0,0,0\" />"
|
||
|
|
" <HorizontalLayout height=\"10\" />"
|
||
|
|
" <Label text=\"密码\" textcolor=\"#FF454C58\" height=\"18\" />"
|
||
|
|
" <Edit name=\"editPass\" height=\"40\" bkcolor=\"#FFFFFFFF\" nativebkcolor=\"#FFFFFFFF\" textcolor=\"#FF1F1F24\" bordercolor=\"#FFC9C9D2\" inset=\"10,0,0,0\" password=\"true\" />"
|
||
|
|
" <HorizontalLayout height=\"10\" />"
|
||
|
|
" <HorizontalLayout height=\"22\">"
|
||
|
|
" <HorizontalLayout height=\"22\"><Label name=\"chkBox\" mouse=\"true\" width=\"14\" height=\"14\" bkcolor=\"#00000000\" bordercolor=\"#FF7A7A85\" bordersize=\"1\" /><Label width=\"8\" /><Button name=\"btnRemember\" text=\"记住账号\" textcolor=\"#FF454C58\" bkcolor=\"#00000000\" width=\"120\" /></HorizontalLayout>"
|
||
|
|
" </HorizontalLayout>"
|
||
|
|
" <HorizontalLayout height=\"12\" />"
|
||
|
|
" <Button name=\"btnLogin\" text=\"登录\" height=\"44\" bkcolor=\"#FF1568C8\" textcolor=\"#FFFFFFFF\" font=\"1\" />"
|
||
|
|
" <Label name=\"lblTip\" text=\"\" textcolor=\"#FFC0392B\" height=\"30\" inset=\"0,8,0,0\" />"
|
||
|
|
" <Label name=\"lblDevice\" text=\"设备\" textcolor=\"#FF8A8F99\" height=\"18\" />"
|
||
|
|
" <HorizontalLayout height=\"24\">"
|
||
|
|
" <Button name=\"btnLinkReg\" text=\"注册账号\" width=\"96\" textcolor=\"#FF8FB4D8\" bkcolor=\"#00000000\" />"
|
||
|
|
" <Button name=\"btnLinkCard\" text=\"卡密充值\" width=\"96\" textcolor=\"#FF8FB4D8\" bkcolor=\"#00000000\" />"
|
||
|
|
" <Button name=\"btnLinkForgot\" text=\"忘记密码\" width=\"96\" textcolor=\"#FF8FB4D8\" bkcolor=\"#00000000\" />"
|
||
|
|
" </HorizontalLayout>"
|
||
|
|
" </VerticalLayout>"
|
||
|
|
" </VerticalLayout>"
|
||
|
|
"</Window>";
|
||
|
|
|
||
|
|
// 3) 左右分栏:左品牌竖栏 + 右表单
|
||
|
|
static const char *kSkinSplit =
|
||
|
|
"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
|
||
|
|
"<Window size=\"620,400\" caption=\"0,0,0,0\" mininfo=\"620,400\" bkcolor=\"#FF14161B\">"
|
||
|
|
" <HorizontalLayout bkcolor=\"#FF14161B\" bordercolor=\"#FF2A2E36\" bordersize=\"1\">"
|
||
|
|
" <VerticalLayout width=\"196\" bkcolor=\"#FF1B2230\">"
|
||
|
|
" <Label text=\"VFY\" textcolor=\"#FF4CC2FF\" font=\"1\" height=\"64\" inset=\"26,22,0,0\" />"
|
||
|
|
" <Label text=\"软件授权\" textcolor=\"#FFC4CFDC\" height=\"26\" inset=\"26,0,0,0\" />"
|
||
|
|
" <Label text=\"SOFTWARE LICENSE\" textcolor=\"#FF63707E\" height=\"20\" inset=\"26,0,0,0\" />"
|
||
|
|
" <VerticalLayout />"
|
||
|
|
" <Label text=\"设备绑定 · 异常登录自动锁定\" textcolor=\"#FF4C5A68\" height=\"40\" inset=\"26,0,0,26\" multiline=\"true\" />"
|
||
|
|
" </VerticalLayout>"
|
||
|
|
" <VerticalLayout>"
|
||
|
|
" <HorizontalLayout height=\"40\">"
|
||
|
|
" <Label text=\"\" />"
|
||
|
|
" <Button name=\"btnClose\" text=\"X\" width=\"40\" textcolor=\"#FF8E9BAA\" bkcolor=\"#FF14161B\" />"
|
||
|
|
" </HorizontalLayout>"
|
||
|
|
" <VerticalLayout inset=\"28,6,28,18\">"
|
||
|
|
" <Label name=\"lblApp\" text=\"演示程序\" textcolor=\"#FFF0F5FA\" height=\"28\" font=\"1\" />"
|
||
|
|
" <Label text=\"请使用账号或卡密登录\" textcolor=\"#FF8794A3\" height=\"20\" />"
|
||
|
|
" <HorizontalLayout height=\"10\" />"
|
||
|
|
" <Edit name=\"editUser\" height=\"40\" bkcolor=\"#FF262B34\" nativebkcolor=\"#FF262B34\" textcolor=\"#FFF2F6FA\" bordercolor=\"#FF2E343D\" inset=\"10,0,0,0\" />"
|
||
|
|
" <HorizontalLayout height=\"10\" />"
|
||
|
|
" <Edit name=\"editPass\" height=\"40\" bkcolor=\"#FF262B34\" nativebkcolor=\"#FF262B34\" textcolor=\"#FFF2F6FA\" bordercolor=\"#FF2E343D\" inset=\"10,0,0,0\" password=\"true\" />"
|
||
|
|
" <HorizontalLayout height=\"8\" />"
|
||
|
|
" <HorizontalLayout height=\"22\">"
|
||
|
|
" <HorizontalLayout height=\"22\"><Label name=\"chkBox\" mouse=\"true\" width=\"14\" height=\"14\" bkcolor=\"#00000000\" bordercolor=\"#FF8794A3\" bordersize=\"1\" /><Label width=\"8\" /><Button name=\"btnRemember\" text=\"记住账号\" textcolor=\"#FF8794A3\" bkcolor=\"#00000000\" width=\"120\" /></HorizontalLayout>"
|
||
|
|
" </HorizontalLayout>"
|
||
|
|
" <HorizontalLayout height=\"10\" />"
|
||
|
|
" <Button name=\"btnLogin\" text=\"登录\" height=\"42\" bkcolor=\"#FF2C7BE5\" textcolor=\"#FFFFFFFF\" font=\"1\" />"
|
||
|
|
" <Label name=\"lblTip\" text=\"\" textcolor=\"#FFE08585\" height=\"28\" inset=\"0,6,0,0\" />"
|
||
|
|
" </VerticalLayout>"
|
||
|
|
" <Label name=\"lblDevice\" text=\"设备\" textcolor=\"#FF5E6B78\" height=\"18\" />"
|
||
|
|
" <HorizontalLayout height=\"24\">"
|
||
|
|
" <Button name=\"btnLinkReg\" text=\"注册账号\" width=\"96\" textcolor=\"#FF8FB4D8\" bkcolor=\"#00000000\" />"
|
||
|
|
" <Button name=\"btnLinkCard\" text=\"卡密充值\" width=\"96\" textcolor=\"#FF8FB4D8\" bkcolor=\"#00000000\" />"
|
||
|
|
" <Button name=\"btnLinkForgot\" text=\"忘记密码\" width=\"96\" textcolor=\"#FF8FB4D8\" bkcolor=\"#00000000\" />"
|
||
|
|
" </HorizontalLayout>"
|
||
|
|
" </VerticalLayout>"
|
||
|
|
" </HorizontalLayout>"
|
||
|
|
"</Window>";
|
||
|
|
|
||
|
|
// 4) 宽扁卡片:顶部强调色条 + 双列(左说明 / 右表单)
|
||
|
|
static const char *kSkinCard =
|
||
|
|
"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
|
||
|
|
"<Window size=\"680,392\" caption=\"0,0,-1,80\" mininfo=\"680,392\" bkcolor=\"#FFF5F6F9\">"
|
||
|
|
" <VerticalLayout bkcolor=\"#FFF5F6F9\" bordercolor=\"#FFD7DBE3\" bordersize=\"1\">"
|
||
|
|
" <HorizontalLayout height=\"80\" bkcolor=\"#FF3B2BD6\">"
|
||
|
|
" <VerticalLayout inset=\"0,0,0,0\">"
|
||
|
|
" <Label text=\"登录以继续\" textcolor=\"#FFFFFFFF\" font=\"1\" height=\"36\" inset=\"26,18,0,0\" />"
|
||
|
|
" <Label name=\"lblApp\" text=\"演示程序\" textcolor=\"#FFD9D4FF\" height=\"22\" inset=\"26,0,0,0\" />"
|
||
|
|
" </VerticalLayout>"
|
||
|
|
" <Button name=\"btnClose\" text=\"X\" width=\"46\" textcolor=\"#FFEDEBFF\" bkcolor=\"#FF3B2BD6\" />"
|
||
|
|
" </HorizontalLayout>"
|
||
|
|
" <HorizontalLayout inset=\"26,22,26,20\">"
|
||
|
|
" <VerticalLayout width=\"264\">"
|
||
|
|
" <Label text=\"账号安全\" textcolor=\"#FF2A2F3A\" height=\"24\" font=\"1\" />"
|
||
|
|
" <Label text=\"登录后账号与本机设备绑定,\" textcolor=\"#FF4B5563\" height=\"20\" />"
|
||
|
|
" <Label text=\"超出设备上限时请先下线一台。\" textcolor=\"#FF4B5563\" height=\"20\" />"
|
||
|
|
" <VerticalLayout height=\"10\" />"
|
||
|
|
" <VerticalLayout />"
|
||
|
|
" </VerticalLayout>"
|
||
|
|
" <VerticalLayout width=\"28\" />"
|
||
|
|
" <VerticalLayout>"
|
||
|
|
" <Label text=\"账号或卡密\" textcolor=\"#FF4B5563\" height=\"18\" />"
|
||
|
|
" <Edit name=\"editUser\" height=\"40\" bkcolor=\"#FFFFFFFF\" nativebkcolor=\"#FFFFFFFF\" textcolor=\"#FF1F2430\" bordercolor=\"#FFC9D1DC\" inset=\"10,0,0,0\" />"
|
||
|
|
" <HorizontalLayout height=\"10\" />"
|
||
|
|
" <Label text=\"密码\" textcolor=\"#FF4B5563\" height=\"18\" />"
|
||
|
|
" <Edit name=\"editPass\" height=\"40\" bkcolor=\"#FFFFFFFF\" nativebkcolor=\"#FFFFFFFF\" textcolor=\"#FF1F2430\" bordercolor=\"#FFC9D1DC\" inset=\"10,0,0,0\" password=\"true\" />"
|
||
|
|
" <HorizontalLayout height=\"8\" />"
|
||
|
|
" <HorizontalLayout height=\"22\"><Label name=\"chkBox\" mouse=\"true\" width=\"14\" height=\"14\" bkcolor=\"#00000000\" bordercolor=\"#FF4B5563\" bordersize=\"1\" /><Label width=\"8\" /><Button name=\"btnRemember\" text=\"记住账号\" textcolor=\"#FF4B5563\" bkcolor=\"#00000000\" width=\"120\" /></HorizontalLayout>"
|
||
|
|
" <HorizontalLayout height=\"10\" />"
|
||
|
|
" <Button name=\"btnLogin\" text=\"登录\" height=\"42\" bkcolor=\"#FF3B2BD6\" textcolor=\"#FFFFFFFF\" font=\"1\" />"
|
||
|
|
" <Label name=\"lblTip\" text=\"\" textcolor=\"#FFC0392B\" height=\"26\" inset=\"0,6,0,0\" />"
|
||
|
|
" </VerticalLayout>"
|
||
|
|
" </HorizontalLayout>"
|
||
|
|
" <Label name=\"lblDevice\" text=\"设备\" textcolor=\"#FF8A8F99\" height=\"18\" />"
|
||
|
|
" <HorizontalLayout height=\"24\">"
|
||
|
|
" <Button name=\"btnLinkReg\" text=\"注册账号\" width=\"96\" textcolor=\"#FF3B2BD6\" bkcolor=\"#00000000\" />"
|
||
|
|
" <Button name=\"btnLinkCard\" text=\"卡密充值\" width=\"96\" textcolor=\"#FF3B2BD6\" bkcolor=\"#00000000\" />"
|
||
|
|
" <Button name=\"btnLinkForgot\" text=\"忘记密码\" width=\"96\" textcolor=\"#FF3B2BD6\" bkcolor=\"#00000000\" />"
|
||
|
|
" </HorizontalLayout>"
|
||
|
|
" </VerticalLayout>"
|
||
|
|
"</Window>";
|
||
|
|
|
||
|
|
// 5) 工业蓝:标签 + 输入 横排两行,双按钮
|
||
|
|
static const char *kSkinIndustrial =
|
||
|
|
"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
|
||
|
|
"<Window size=\"560,376\" caption=\"0,0,-1,46\" mininfo=\"560,376\" bkcolor=\"#FF0A1520\">"
|
||
|
|
" <VerticalLayout bkcolor=\"#FF0A1520\" bordercolor=\"#FF1F4E79\" bordersize=\"1\">"
|
||
|
|
" <HorizontalLayout height=\"46\" bkcolor=\"#FF10304C\">"
|
||
|
|
" <Label text=\"AUTHORIZATION\" textcolor=\"#FF7FD1FF\" font=\"1\" inset=\"18,0,0,0\" />"
|
||
|
|
" <Button name=\"btnClose\" text=\"X\" width=\"46\" textcolor=\"#FFBEE3FF\" bkcolor=\"#FF10304C\" />"
|
||
|
|
" </HorizontalLayout>"
|
||
|
|
" <VerticalLayout inset=\"22,16,22,16\">"
|
||
|
|
" <Label name=\"lblApp\" text=\"演示程序\" textcolor=\"#FF8FC4E6\" height=\"26\" font=\"1\" />"
|
||
|
|
" <HorizontalLayout height=\"10\" />"
|
||
|
|
" <HorizontalLayout height=\"42\" bkcolor=\"#FF14304A\">"
|
||
|
|
" <Label text=\"账号\" textcolor=\"#FF7FA8C4\" width=\"72\" inset=\"12,0,0,0\" />"
|
||
|
|
" <Edit name=\"editUser\" bkcolor=\"#FF14304A\" nativebkcolor=\"#FF14304A\" textcolor=\"#FFEAF6FF\" inset=\"4,0,0,0\" />"
|
||
|
|
" </HorizontalLayout>"
|
||
|
|
" <HorizontalLayout height=\"8\" />"
|
||
|
|
" <HorizontalLayout height=\"42\" bkcolor=\"#FF14304A\">"
|
||
|
|
" <Label text=\"密码\" textcolor=\"#FF7FA8C4\" width=\"72\" inset=\"12,0,0,0\" />"
|
||
|
|
" <Edit name=\"editPass\" bkcolor=\"#FF14304A\" nativebkcolor=\"#FF14304A\" textcolor=\"#FFEAF6FF\" inset=\"4,0,0,0\" password=\"true\" />"
|
||
|
|
" </HorizontalLayout>"
|
||
|
|
" <HorizontalLayout height=\"10\">"
|
||
|
|
" <HorizontalLayout height=\"22\"><Label name=\"chkBox\" mouse=\"true\" width=\"14\" height=\"14\" bkcolor=\"#00000000\" bordercolor=\"#FF7FA8C4\" bordersize=\"1\" /><Label width=\"8\" /><Button name=\"btnRemember\" text=\"记住账号\" textcolor=\"#FF7FA8C4\" bkcolor=\"#00000000\" width=\"120\" /></HorizontalLayout>"
|
||
|
|
" </HorizontalLayout>"
|
||
|
|
" <HorizontalLayout height=\"12\" />"
|
||
|
|
" <HorizontalLayout height=\"44\">"
|
||
|
|
" <Button name=\"btnLogin\" text=\"登录\" bkcolor=\"#FF1F6FB2\" textcolor=\"#FFFFFFFF\" font=\"1\" />"
|
||
|
|
" <HorizontalLayout width=\"12\" />"
|
||
|
|
" <Button name=\"btnQuit\" text=\"退出\" width=\"120\" bkcolor=\"#FF1B3247\" textcolor=\"#FFBEE3FF\" />"
|
||
|
|
" </HorizontalLayout>"
|
||
|
|
" <Label name=\"lblTip\" text=\"\" textcolor=\"#FFE0A0A0\" height=\"30\" inset=\"0,8,0,0\" />"
|
||
|
|
" <Label name=\"lblDevice\" text=\"设备\" textcolor=\"#FF5F89A6\" height=\"18\" />"
|
||
|
|
" <HorizontalLayout height=\"24\">"
|
||
|
|
" <Button name=\"btnLinkReg\" text=\"注册账号\" width=\"96\" textcolor=\"#FF8FB4D8\" bkcolor=\"#00000000\" />"
|
||
|
|
" <Button name=\"btnLinkCard\" text=\"卡密充值\" width=\"96\" textcolor=\"#FF8FB4D8\" bkcolor=\"#00000000\" />"
|
||
|
|
" <Button name=\"btnLinkForgot\" text=\"忘记密码\" width=\"96\" textcolor=\"#FF8FB4D8\" bkcolor=\"#00000000\" />"
|
||
|
|
" </HorizontalLayout>"
|
||
|
|
" </VerticalLayout>"
|
||
|
|
" </VerticalLayout>"
|
||
|
|
"</Window>";
|
||
|
|
|
||
|
|
// 6) 终端风
|
||
|
|
static const char *kSkinTerminal =
|
||
|
|
"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
|
||
|
|
"<Window size=\"580,392\" caption=\"0,0,-1,38\" mininfo=\"580,392\" bkcolor=\"#FF16211A\">"
|
||
|
|
" <VerticalLayout bkcolor=\"#FF16211A\" bordercolor=\"#FF2B3A2D\" bordersize=\"1\">"
|
||
|
|
" <HorizontalLayout height=\"38\" bkcolor=\"#FF101710\">"
|
||
|
|
" <Label text=\"vfy@local:~$\" textcolor=\"#FF54C97A\" inset=\"14,0,0,0\" />"
|
||
|
|
" <Button name=\"btnClose\" text=\"X\" width=\"38\" textcolor=\"#FF7FB08C\" bkcolor=\"#FF101710\" />"
|
||
|
|
" </HorizontalLayout>"
|
||
|
|
" <VerticalLayout inset=\"16,12,16,14\">"
|
||
|
|
" <Label name=\"lblApp\" text=\"# 演示程序\" textcolor=\"#FF7FE39B\" height=\"24\" />"
|
||
|
|
" <Label text=\"# 用例:输入账号与密码后回车\" textcolor=\"#FF4E7A5C\" height=\"20\" />"
|
||
|
|
" <HorizontalLayout height=\"10\" />"
|
||
|
|
" <HorizontalLayout height=\"40\" bordercolor=\"#FF2B3A2D\" bordersize=\"1\">"
|
||
|
|
" <Label text=\"账号\" textcolor=\"#FF54C97A\" width=\"62\" inset=\"12,0,0,0\" />"
|
||
|
|
" <Edit name=\"editUser\" bkcolor=\"#FF16211A\" nativebkcolor=\"#FF16211A\" textcolor=\"#FFD7F5DF\" />"
|
||
|
|
" </HorizontalLayout>"
|
||
|
|
" <HorizontalLayout height=\"8\" />"
|
||
|
|
" <HorizontalLayout height=\"40\" bordercolor=\"#FF2B3A2D\" bordersize=\"1\">"
|
||
|
|
" <Label text=\"密码\" textcolor=\"#FF54C97A\" width=\"62\" inset=\"12,0,0,0\" />"
|
||
|
|
" <Edit name=\"editPass\" bkcolor=\"#FF16211A\" nativebkcolor=\"#FF16211A\" textcolor=\"#FFD7F5DF\" password=\"true\" />"
|
||
|
|
" </HorizontalLayout>"
|
||
|
|
" <HorizontalLayout height=\"8\">"
|
||
|
|
" <HorizontalLayout height=\"22\"><Label name=\"chkBox\" mouse=\"true\" width=\"14\" height=\"14\" bkcolor=\"#00000000\" bordercolor=\"#FF5E8A6C\" bordersize=\"1\" /><Label width=\"8\" /><Button name=\"btnRemember\" text=\"记住账号\" textcolor=\"#FF5E8A6C\" bkcolor=\"#00000000\" width=\"120\" /></HorizontalLayout>"
|
||
|
|
" </HorizontalLayout>"
|
||
|
|
" <VerticalLayout />"
|
||
|
|
" <Button name=\"btnLogin\" text=\"[ 执行登录 ]\" height=\"40\" bkcolor=\"#FF16261A\" textcolor=\"#FF7FE39B\" bordercolor=\"#FF2B3A2D\" bordersize=\"1\" />"
|
||
|
|
" <Label name=\"lblTip\" text=\"\" textcolor=\"#FFD98A8A\" height=\"28\" inset=\"0,6,0,0\" />"
|
||
|
|
" <Label name=\"lblDevice\" text=\"设备\" textcolor=\"#FF4E7A5C\" height=\"18\" />"
|
||
|
|
" <HorizontalLayout height=\"24\">"
|
||
|
|
" <Button name=\"btnLinkReg\" text=\"注册账号\" width=\"96\" textcolor=\"#FF8FB4D8\" bkcolor=\"#00000000\" />"
|
||
|
|
" <Button name=\"btnLinkCard\" text=\"卡密充值\" width=\"96\" textcolor=\"#FF8FB4D8\" bkcolor=\"#00000000\" />"
|
||
|
|
" <Button name=\"btnLinkForgot\" text=\"忘记密码\" width=\"96\" textcolor=\"#FF8FB4D8\" bkcolor=\"#00000000\" />"
|
||
|
|
" </HorizontalLayout>"
|
||
|
|
" </VerticalLayout>"
|
||
|
|
" </VerticalLayout>"
|
||
|
|
"</Window>";
|
||
|
|
|
||
|
|
// 7) 极简单行:账号 + 密码 + 登录 一行排开
|
||
|
|
static const char *kSkinCompact =
|
||
|
|
"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
|
||
|
|
"<Window size=\"720,168\" caption=\"0,0,-1,36\" mininfo=\"720,168\" bkcolor=\"#FF11151A\">"
|
||
|
|
" <VerticalLayout bkcolor=\"#FF11151A\" bordercolor=\"#FF2A3440\" bordersize=\"1\">"
|
||
|
|
" <HorizontalLayout height=\"36\" bkcolor=\"#FF161C22\">"
|
||
|
|
" <Label text=\"账号登录\" textcolor=\"#FFA8BCCE\" inset=\"16,0,0,0\" />"
|
||
|
|
" <Button name=\"btnClose\" text=\"X\" width=\"38\" textcolor=\"#FFA8BCCE\" bkcolor=\"#FF161C22\" />"
|
||
|
|
" </HorizontalLayout>"
|
||
|
|
" <HorizontalLayout inset=\"16,12,16,10\">"
|
||
|
|
" <VerticalLayout width=\"186\">"
|
||
|
|
" <Label name=\"lblApp\" text=\"演示程序\" textcolor=\"#FFE9F1F8\" height=\"26\" font=\"1\" />"
|
||
|
|
" </VerticalLayout>"
|
||
|
|
" <VerticalLayout>"
|
||
|
|
" <HorizontalLayout height=\"42\">"
|
||
|
|
" <Edit name=\"editUser\" width=\"190\" bkcolor=\"#FF262E38\" nativebkcolor=\"#FF262E38\" textcolor=\"#FFFFFFFF\" bordercolor=\"#FF32404E\" inset=\"10,0,0,0\" />"
|
||
|
|
" <HorizontalLayout width=\"10\" />"
|
||
|
|
" <Edit name=\"editPass\" width=\"190\" bkcolor=\"#FF262E38\" nativebkcolor=\"#FF262E38\" textcolor=\"#FFFFFFFF\" bordercolor=\"#FF32404E\" inset=\"10,0,0,0\" password=\"true\" />"
|
||
|
|
" <HorizontalLayout width=\"10\" />"
|
||
|
|
" <Button name=\"btnLogin\" text=\"登录\" width=\"104\" height=\"42\" bkcolor=\"#FF2E9E6B\" textcolor=\"#FFFFFFFF\" font=\"1\" />"
|
||
|
|
" </HorizontalLayout>"
|
||
|
|
" <HorizontalLayout height=\"26\">"
|
||
|
|
" <HorizontalLayout height=\"22\"><Label name=\"chkBox\" mouse=\"true\" width=\"14\" height=\"14\" bkcolor=\"#00000000\" bordercolor=\"#FF6B7C8C\" bordersize=\"1\" /><Label width=\"8\" /><Button name=\"btnRemember\" text=\"记住账号\" textcolor=\"#FF6B7C8C\" bkcolor=\"#00000000\" width=\"120\" /></HorizontalLayout>"
|
||
|
|
" <Label name=\"lblTip\" text=\"\" textcolor=\"#FFD98A8A\" />"
|
||
|
|
" </HorizontalLayout>"
|
||
|
|
" </VerticalLayout>"
|
||
|
|
" </HorizontalLayout>"
|
||
|
|
" <Label name=\"lblDevice\" text=\"设备\" textcolor=\"#FF6B7C8C\" height=\"18\" />"
|
||
|
|
" <HorizontalLayout height=\"24\">"
|
||
|
|
" <Button name=\"btnLinkReg\" text=\"注册账号\" width=\"96\" textcolor=\"#FF8FB4D8\" bkcolor=\"#00000000\" />"
|
||
|
|
" <Button name=\"btnLinkCard\" text=\"卡密充值\" width=\"96\" textcolor=\"#FF8FB4D8\" bkcolor=\"#00000000\" />"
|
||
|
|
" <Button name=\"btnLinkForgot\" text=\"忘记密码\" width=\"96\" textcolor=\"#FF8FB4D8\" bkcolor=\"#00000000\" />"
|
||
|
|
" </HorizontalLayout>"
|
||
|
|
" </VerticalLayout>"
|
||
|
|
"</Window>";
|
||
|
|
|
||
|
|
struct SkinDef { const char *name; const char *xml; int w, h; };
|
||
|
|
static const SkinDef kSkins[] = {
|
||
|
|
{ "dark", kSkinDark, 440, 404 },
|
||
|
|
{ "light", kSkinLight, 440, 404 },
|
||
|
|
{ "split", kSkinSplit, 620, 400 },
|
||
|
|
{ "card", kSkinCard, 680, 392 },
|
||
|
|
{ "industrial", kSkinIndustrial, 560, 376 },
|
||
|
|
{ "terminal", kSkinTerminal, 580, 392 },
|
||
|
|
{ "compact", kSkinCompact, 720, 168 },
|
||
|
|
{ NULL, NULL, 0, 0 }
|
||
|
|
};
|
||
|
|
|
||
|
|
static const SkinDef *skin_for(const char *theme) {
|
||
|
|
for (int i = 0; kSkins[i].name; i++)
|
||
|
|
if (!_stricmp(theme, kSkins[i].name)) return &kSkins[i];
|
||
|
|
return &kSkins[0];
|
||
|
|
}
|
||
|
|
|
||
|
|
/* ---------------------------- 接口请求 ---------------------------- */
|
||
|
|
// 平台接口:POST /api/v1/app/<appKey>/login
|
||
|
|
// {"username","password","device_id","device_name","device_type","instance_id"}
|
||
|
|
static int api_login(const char *user, const char *pass, char *msg, int cap) {
|
||
|
|
msg[0] = 0;
|
||
|
|
if (!g_api[0]) { snprintf(msg, cap, "配置缺少验证地址"); return 0; }
|
||
|
|
|
||
|
|
const char *rest = g_api;
|
||
|
|
if (!strncmp(g_api, "https://", 8)) rest = g_api + 8;
|
||
|
|
else if (!strncmp(g_api, "http://", 7)) rest = g_api + 7;
|
||
|
|
bool https = (rest != g_api && g_api[4] == 's');
|
||
|
|
|
||
|
|
char host[256] = {0}, path[512] = "/";
|
||
|
|
const char *slash = strchr(rest, '/');
|
||
|
|
if (slash) {
|
||
|
|
int hl = (int)(slash - rest);
|
||
|
|
if (hl > 255) hl = 255;
|
||
|
|
memcpy(host, rest, hl);
|
||
|
|
snprintf(path, sizeof(path), "%s", slash);
|
||
|
|
} else {
|
||
|
|
snprintf(host, sizeof(host), "%s", rest);
|
||
|
|
}
|
||
|
|
unsigned short port = https ? 443 : 80;
|
||
|
|
char *colon = strrchr(host, ':');
|
||
|
|
if (colon) { *colon = 0; port = (unsigned short)atoi(colon + 1); }
|
||
|
|
|
||
|
|
char cname[256] = {0}; DWORD cn = sizeof(cname);
|
||
|
|
::GetComputerNameA(cname, &cn);
|
||
|
|
|
||
|
|
char body[2048];
|
||
|
|
snprintf(body, sizeof(body),
|
||
|
|
"{\"username\":\"%s\",\"password\":\"%s\",\"device_id\":\"%s\","
|
||
|
|
"\"device_name\":\"%s\",\"device_type\":\"windows\",\"instance_id\":\"%s\"}",
|
||
|
|
user, pass, g_device, cname, g_instance);
|
||
|
|
|
||
|
|
std::wstring wHost = U8(host), wPath = U8(path);
|
||
|
|
HINTERNET hS = WinHttpOpen(L"vfy/9.0", WINHTTP_ACCESS_TYPE_NO_PROXY, NULL, NULL, 0);
|
||
|
|
if (!hS) { snprintf(msg, cap, "网络初始化失败"); return 0; }
|
||
|
|
HINTERNET hC = WinHttpConnect(hS, wHost.c_str(), port, 0);
|
||
|
|
HINTERNET hR = hC ? WinHttpOpenRequest(hC, L"POST", wPath.c_str(), NULL, NULL, NULL, 0) : NULL;
|
||
|
|
int ok = 0;
|
||
|
|
if (hR) {
|
||
|
|
WinHttpSendRequest(hR, L"Content-Type: application/json\r\n", (DWORD)-1,
|
||
|
|
(LPVOID)body, (DWORD)strlen(body), (DWORD)strlen(body), 0);
|
||
|
|
WinHttpReceiveResponse(hR, NULL);
|
||
|
|
char resp[4096] = {0};
|
||
|
|
DWORD cl = 0, total = 0;
|
||
|
|
while (WinHttpReadData(hR, resp + total, sizeof(resp) - 1 - total, &cl) && cl > 0) {
|
||
|
|
total += cl;
|
||
|
|
if (total >= sizeof(resp) - 1) break;
|
||
|
|
}
|
||
|
|
resp[total] = 0;
|
||
|
|
if (strstr(resp, "\"code\":0") || strstr(resp, "\"code\":200") || strstr(resp, "\"success\":true")) ok = 1;
|
||
|
|
if (!json_str(resp, "message", msg, cap) || !msg[0]) {
|
||
|
|
if (strstr(resp, "DEVICE_LIMIT")) snprintf(msg, cap, "设备数量已达上限,请先在平台下线一台设备");
|
||
|
|
else if (strstr(resp, "IP_LIMIT")) snprintf(msg, cap, "IP 绑定已达上限,请解绑后再试");
|
||
|
|
else if (ok) snprintf(msg, cap, "登录成功");
|
||
|
|
else snprintf(msg, cap, "账号或密码错误");
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
snprintf(msg, cap, "无法连接验证服务器");
|
||
|
|
}
|
||
|
|
if (hR) WinHttpCloseHandle(hR);
|
||
|
|
if (hC) WinHttpCloseHandle(hC);
|
||
|
|
WinHttpCloseHandle(hS);
|
||
|
|
return ok;
|
||
|
|
}
|
||
|
|
|
||
|
|
/* ---------------------------- 窗口 ---------------------------- */
|
||
|
|
typedef void (*PFN_OEP)(void);
|
||
|
|
static PFN_OEP g_oep = NULL;
|
||
|
|
static int g_logged_in = 0;
|
||
|
|
|
||
|
|
// 从 cfg 的 api 里抽出站点根地址(去掉 /api/v1/... 部分)
|
||
|
|
static std::wstring SiteRoot() {
|
||
|
|
std::string a(g_api);
|
||
|
|
size_t p = a.find("/api/");
|
||
|
|
if (p != std::string::npos) a = a.substr(0, p);
|
||
|
|
return U8(a.c_str());
|
||
|
|
}
|
||
|
|
static bool g_remember = false;
|
||
|
|
|
||
|
|
class CVerifyWnd : public CWindowWnd, public INotifyUI {
|
||
|
|
public:
|
||
|
|
explicit CVerifyWnd(const char *skin) : m_skin(skin) {}
|
||
|
|
|
||
|
|
LPCTSTR GetWindowClassName() const override { return _T("VfyDuiWnd"); }
|
||
|
|
UINT GetClassStyle() const override { return CS_DBLCLKS; }
|
||
|
|
|
||
|
|
void Notify(TNotifyUI &msg) override {
|
||
|
|
if (msg.sType == _T("click")) {
|
||
|
|
CControlUI *p = msg.pSender;
|
||
|
|
LPCTSTR nm = p ? p->GetName().GetData() : NULL;
|
||
|
|
if (!nm) return;
|
||
|
|
if (!_tcsicmp(nm, _T("btnClose")) || !_tcsicmp(nm, _T("btnQuit"))) { ::PostQuitMessage(0); return; }
|
||
|
|
if (!_tcsicmp(nm, _T("btnLogin"))) { DoLogin(); return; }
|
||
|
|
if (!_tcsicmp(nm, _T("btnLinkReg")) || !_tcsicmp(nm, _T("btnLinkCard")) ||
|
||
|
|
!_tcsicmp(nm, _T("btnLinkForgot"))) {
|
||
|
|
std::wstring url = SiteRoot();
|
||
|
|
// 平台只有 /login 与 /register 是公开页:注册直开,其余引导到登录页
|
||
|
|
url += _tcsicmp(nm, _T("btnLinkReg")) == 0 ? L"/register" : L"/login";
|
||
|
|
::ShellExecuteW(NULL, L"open", url.c_str(), NULL, NULL, SW_SHOWNORMAL);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
if (!_tcsicmp(nm, _T("btnRemember"))) {
|
||
|
|
g_remember = !g_remember;
|
||
|
|
UpdateRememberButton();
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
} else if (msg.sType == _T("return")) {
|
||
|
|
DoLogin();
|
||
|
|
} else if (msg.sType == _T("setfocus") || msg.sType == _T("killfocus")) {
|
||
|
|
CControlUI *p = msg.pSender;
|
||
|
|
if (!p) return;
|
||
|
|
LPCTSTR nm = p->GetName().GetData();
|
||
|
|
if (!nm || (_tcsicmp(nm, _T("editUser")) && _tcsicmp(nm, _T("editPass")))) return;
|
||
|
|
bool focus = !_tcsicmp(msg.sType.GetData(), _T("setfocus"));
|
||
|
|
if (CEditUI *e = static_cast<CEditUI *>(p)) {
|
||
|
|
DWORD bg = e->GetBkColor();
|
||
|
|
// 聚焦时把原生 EDIT 窗口底色提亮一档(纯 XML 画不出描边,用亮度做反馈)
|
||
|
|
if (focus) {
|
||
|
|
BYTE r = GetRValue(bg) + 10 > 255 ? 255 : GetRValue(bg) + 10;
|
||
|
|
BYTE g = GetGValue(bg) + 10 > 255 ? 255 : GetGValue(bg) + 10;
|
||
|
|
BYTE b = GetBValue(bg) + 14 > 255 ? 255 : GetBValue(bg) + 14;
|
||
|
|
e->SetNativeEditBkColor(RGB(r, g, b));
|
||
|
|
} else {
|
||
|
|
e->SetNativeEditBkColor(bg);
|
||
|
|
}
|
||
|
|
e->Invalidate();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 自绘勾选框:选中时方框填充主色(老 DuiLib 没有勾选图片资源,只能用色块表达)
|
||
|
|
void UpdateRememberButton() {
|
||
|
|
CLabelUI *box = static_cast<CLabelUI *>(m_pm.FindControl(_T("chkBox")));
|
||
|
|
if (!box) return;
|
||
|
|
box->SetBkColor(g_remember ? 0xFF2C7BE5 : 0x00000000);
|
||
|
|
box->SetBorderColor(g_remember ? 0xFF2C7BE5 : 0xFF5A5A66);
|
||
|
|
box->Invalidate();
|
||
|
|
}
|
||
|
|
|
||
|
|
void DoLogin() {
|
||
|
|
CEditUI *pUser = static_cast<CEditUI *>(m_pm.FindControl(_T("editUser")));
|
||
|
|
CEditUI *pPass = static_cast<CEditUI *>(m_pm.FindControl(_T("editPass")));
|
||
|
|
CLabelUI *pTip = static_cast<CLabelUI *>(m_pm.FindControl(_T("lblTip")));
|
||
|
|
CButtonUI *pBtn = static_cast<CButtonUI *>(m_pm.FindControl(_T("btnLogin")));
|
||
|
|
if (!pUser || !pPass || !pTip) return;
|
||
|
|
|
||
|
|
std::wstring user = pUser->GetText().GetData();
|
||
|
|
std::wstring pass = pPass->GetText().GetData();
|
||
|
|
if (user.empty()) { pTip->SetText(L"请输入账号或卡密"); return; }
|
||
|
|
if (pass.empty()) { pTip->SetText(L"请输入密码"); return; }
|
||
|
|
|
||
|
|
SaveAccount(user, g_remember);
|
||
|
|
|
||
|
|
if (pBtn) { pBtn->SetText(L"验证中…"); pBtn->SetEnabled(false); }
|
||
|
|
pTip->SetText(L"正在连接验证服务器…");
|
||
|
|
|
||
|
|
char msg[1024] = {0};
|
||
|
|
int ok = api_login(W2U8(user).c_str(), W2U8(pass).c_str(), msg, sizeof(msg));
|
||
|
|
if (ok) {
|
||
|
|
g_logged_in = 1;
|
||
|
|
pTip->SetText(L"验证成功,正在启动程序…");
|
||
|
|
::SetTimer(m_hWnd, 1, 600, NULL);
|
||
|
|
} else {
|
||
|
|
pTip->SetText(U8(msg).c_str());
|
||
|
|
if (pBtn) { pBtn->SetText(L"登 录"); pBtn->SetEnabled(true); }
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) override {
|
||
|
|
if (uMsg == WM_CREATE) {
|
||
|
|
m_pm.Init(m_hWnd);
|
||
|
|
CDialogBuilder builder;
|
||
|
|
std::wstring xml = U8(m_skin);
|
||
|
|
CControlUI *pRoot = builder.Create(xml.c_str(), (UINT)0, NULL, &m_pm);
|
||
|
|
if (!pRoot) { ::MessageBoxW(m_hWnd, L"界面加载失败", L"验证", MB_ICONERROR); return 0; }
|
||
|
|
m_pm.AttachDialog(pRoot);
|
||
|
|
m_pm.AddNotifier(this);
|
||
|
|
|
||
|
|
if (CLabelUI *p = static_cast<CLabelUI *>(m_pm.FindControl(_T("lblApp"))))
|
||
|
|
p->SetText(U8(g_name).c_str());
|
||
|
|
|
||
|
|
std::wstring devText = L"设备 ";
|
||
|
|
devText += U8(g_device);
|
||
|
|
if (CLabelUI *p = static_cast<CLabelUI *>(m_pm.FindControl(_T("lblDevice"))))
|
||
|
|
p->SetText(devText.c_str());
|
||
|
|
|
||
|
|
bool remember = false;
|
||
|
|
std::wstring saved = LoadAccount(remember);
|
||
|
|
g_remember = remember;
|
||
|
|
UpdateRememberButton();
|
||
|
|
if (CEditUI *pUser = static_cast<CEditUI *>(m_pm.FindControl(_T("editUser")))) {
|
||
|
|
if (!saved.empty()) pUser->SetText(saved.c_str());
|
||
|
|
pUser->SetFocus();
|
||
|
|
}
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
if (uMsg == WM_TIMER && wParam == 1) {
|
||
|
|
::KillTimer(m_hWnd, 1);
|
||
|
|
::ShowWindow(m_hWnd, SW_HIDE);
|
||
|
|
if (g_oep) g_oep();
|
||
|
|
::PostQuitMessage(0);
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
if (uMsg == WM_DESTROY) { ::PostQuitMessage(0); return 0; }
|
||
|
|
|
||
|
|
LRESULT lr = 0;
|
||
|
|
if (m_pm.MessageHandler(uMsg, wParam, lParam, lr)) return lr;
|
||
|
|
return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
|
||
|
|
}
|
||
|
|
|
||
|
|
CPaintManagerUI m_pm;
|
||
|
|
const char *m_skin;
|
||
|
|
};
|
||
|
|
|
||
|
|
static int RunShell(void *oep) {
|
||
|
|
g_oep = (PFN_OEP)oep;
|
||
|
|
const SkinDef *sk = skin_for(g_theme);
|
||
|
|
|
||
|
|
CPaintManagerUI::SetInstance(::GetModuleHandle(NULL));
|
||
|
|
::CoInitialize(NULL);
|
||
|
|
|
||
|
|
CVerifyWnd wnd(sk->xml);
|
||
|
|
UINT style = WS_POPUP | WS_CLIPCHILDREN;
|
||
|
|
UINT exstyle = WS_EX_TOPMOST | WS_EX_APPWINDOW;
|
||
|
|
|
||
|
|
wnd.Create(NULL, L"软件授权验证", style, exstyle, 0, 0, sk->w, sk->h);
|
||
|
|
wnd.CenterWindow();
|
||
|
|
::ShowWindow(wnd, SW_SHOW);
|
||
|
|
|
||
|
|
CPaintManagerUI::MessageLoop();
|
||
|
|
::CoUninitialize();
|
||
|
|
return g_logged_in ? 0 : 6;
|
||
|
|
}
|
||
|
|
|
||
|
|
/* ---------------------------- 对外接口 ---------------------------- */
|
||
|
|
static void load_cfg(const char *json) {
|
||
|
|
snprintf(g_cfg, sizeof(g_cfg), "%s", json ? json : "");
|
||
|
|
json_str(g_cfg, "api", g_api, sizeof(g_api));
|
||
|
|
json_str(g_cfg, "name", g_name, sizeof(g_name));
|
||
|
|
g_deviceAuto = json_int(g_cfg, "device_auto", 1);
|
||
|
|
|
||
|
|
char mid[64] = {0};
|
||
|
|
make_machine_id(mid, sizeof(mid));
|
||
|
|
snprintf(g_instance, sizeof(g_instance), "%s", mid);
|
||
|
|
|
||
|
|
if (!json_str(g_cfg, "device", g_device, sizeof(g_device)) || !g_device[0]) {
|
||
|
|
if (g_deviceAuto) snprintf(g_device, sizeof(g_device), "%s", mid);
|
||
|
|
else snprintf(g_device, sizeof(g_device), "%s", "UNKNOWN-DEVICE");
|
||
|
|
}
|
||
|
|
if (!json_str(g_cfg, "theme", g_theme, sizeof(g_theme))) snprintf(g_theme, sizeof(g_theme), "dark");
|
||
|
|
}
|
||
|
|
|
||
|
|
#ifdef SHELL_EXE
|
||
|
|
int APIENTRY WinMain(HINSTANCE, HINSTANCE, LPSTR lpCmdLine, int) {
|
||
|
|
const char *cfg = (lpCmdLine && lpCmdLine[0]) ? lpCmdLine : getenv("VFY_CFG");
|
||
|
|
if (!cfg || !cfg[0]) cfg = "{\"theme\":\"dark\"}";
|
||
|
|
load_cfg(cfg);
|
||
|
|
return RunShell(NULL);
|
||
|
|
}
|
||
|
|
#else
|
||
|
|
extern "C" __declspec(dllexport) int VerifyMain(void *oep, const char *cfgjson) {
|
||
|
|
load_cfg(cfgjson);
|
||
|
|
return RunShell(oep);
|
||
|
|
}
|
||
|
|
extern "C" __declspec(dllexport) int VerifyShellVersion(void) { return 9; }
|
||
|
|
extern "C" __declspec(dllexport) const char *VerifyShellThemes(void) {
|
||
|
|
return "dark,light,split,card,industrial,terminal,compact";
|
||
|
|
}
|
||
|
|
BOOL WINAPI DllMain(HINSTANCE h, DWORD reason, LPVOID) {
|
||
|
|
if (reason == DLL_PROCESS_ATTACH) DisableThreadLibraryCalls(h);
|
||
|
|
return TRUE;
|
||
|
|
}
|
||
|
|
#endif
|