feat(V1.1.1): 软件授权(license)——MAC 绑定 .lic 校验,未授权禁用导出
- 新增 lib/license/license_service.dart:读取 exe 同级 license/*.lic,按算法由本机 MAC 计算期望授权串比对 - 算法:MAC 去分隔符 → A=01..Z=26(数字 00..09)→ 末尾加 26 → 整串倒序 - 未授权时「导出 SVG / PNG」置灰,并在导出入口二次拦截 - 关于页:显示授权状态、本机 MAC、授权申请邮箱 liuyu65@126.com,并可「提交授权申请」(唤起邮件客户端发送 MAC+发件人信息) - 新增 license/ 目录(含说明);构建脚本把 license/ 复制到 dist/ - 新增 tools/keygen(Win32 图形界面 keygen.exe + 构建脚本)用于生成 .lic - 版本 1.1.1+3;新增授权算法单元测试;重新构建 dist
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
@echo off
|
||||
rem Build keygen.exe (Win32 GUI) with MSVC cl.exe.
|
||||
rem Edit VS_VCVARS below if your Visual Studio lives elsewhere.
|
||||
setlocal
|
||||
|
||||
set VS_VCVARS=C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools\VC\Auxiliary\Build\vcvars64.bat
|
||||
if not exist "%VS_VCVARS%" set VS_VCVARS=C:\Program Files\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvars64.bat
|
||||
if not exist "%VS_VCVARS%" (
|
||||
echo [error] vcvars64.bat not found. Edit VS_VCVARS in this script.
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
call "%VS_VCVARS%" >nul
|
||||
cd /d "%~dp0"
|
||||
|
||||
rem /utf-8: source (and the Chinese UI strings) are UTF-8.
|
||||
cl /nologo /O2 /EHsc /utf-8 /DUNICODE /D_UNICODE keygen.cpp /link /SUBSYSTEM:WINDOWS comctl32.lib /OUT:keygen.exe
|
||||
if errorlevel 1 (
|
||||
echo Build failed.
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
del /q keygen.obj >nul 2>nul
|
||||
echo.
|
||||
echo Build OK: %~dp0keygen.exe
|
||||
endlocal
|
||||
@@ -0,0 +1,202 @@
|
||||
// keygen.cpp -- Win32 GUI license key generator for 时序图设计器.
|
||||
//
|
||||
// Enter a MAC address (e.g. AA-BB-CC-DD-EE-FF), press "生成", and copy the
|
||||
// resulting single-line license string into a .lic file under the app's
|
||||
// `license` folder.
|
||||
//
|
||||
// Algorithm (must match lib/license/license_service.dart):
|
||||
// 1. strip every non-alphanumeric char, upper-case -> AABBCCDDEEFF
|
||||
// 2. each char: 'A'..'Z' -> 01..26, '0'..'9' -> 00..09 (2 digits)
|
||||
// -> 010102020303040405050606
|
||||
// 3. append the literal "26" -> ...060626
|
||||
// 4. reverse the whole string -> 62606050504040303020201010
|
||||
//
|
||||
// Build: see build.bat (uses MSVC cl.exe, /SUBSYSTEM:WINDOWS).
|
||||
|
||||
#ifndef UNICODE
|
||||
#define UNICODE
|
||||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
#include <commctrl.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
#pragma comment(lib, "user32.lib")
|
||||
#pragma comment(lib, "gdi32.lib")
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr int kIdMac = 1001;
|
||||
constexpr int kIdGen = 1002;
|
||||
constexpr int kIdResult = 1003;
|
||||
constexpr int kIdCopy = 1004;
|
||||
|
||||
HWND g_mac = nullptr;
|
||||
HWND g_result = nullptr;
|
||||
|
||||
std::wstring EncodeMac(const std::wstring& mac) {
|
||||
std::wstring clean;
|
||||
for (wchar_t ch : mac) {
|
||||
if ((ch >= L'0' && ch <= L'9') || (ch >= L'a' && ch <= L'z') ||
|
||||
(ch >= L'A' && ch <= L'Z')) {
|
||||
clean.push_back(static_cast<wchar_t>(towupper(ch)));
|
||||
}
|
||||
}
|
||||
std::wstring fwd;
|
||||
for (wchar_t ch : clean) {
|
||||
int v = -1;
|
||||
if (ch >= L'0' && ch <= L'9') {
|
||||
v = ch - L'0';
|
||||
} else if (ch >= L'A' && ch <= L'Z') {
|
||||
v = ch - L'A' + 1;
|
||||
}
|
||||
if (v < 0) continue;
|
||||
fwd.push_back(static_cast<wchar_t>(L'0' + (v / 10)));
|
||||
fwd.push_back(static_cast<wchar_t>(L'0' + (v % 10)));
|
||||
}
|
||||
fwd += L"26";
|
||||
std::wstring rev(fwd.rbegin(), fwd.rend());
|
||||
return rev;
|
||||
}
|
||||
|
||||
std::wstring GetText(HWND h) {
|
||||
const int len = GetWindowTextLengthW(h);
|
||||
std::wstring s(len > 0 ? len : 0, L'\0');
|
||||
if (len > 0) GetWindowTextW(h, &s[0], len + 1);
|
||||
return s;
|
||||
}
|
||||
|
||||
void DoGenerate() {
|
||||
const std::wstring mac = GetText(g_mac);
|
||||
const std::wstring lic = EncodeMac(mac);
|
||||
SetWindowTextW(g_result, lic.c_str());
|
||||
}
|
||||
|
||||
void DoCopy(HWND owner) {
|
||||
const std::wstring lic = GetText(g_result);
|
||||
if (lic.empty()) return;
|
||||
if (!OpenClipboard(owner)) return;
|
||||
EmptyClipboard();
|
||||
const size_t bytes = (lic.size() + 1) * sizeof(wchar_t);
|
||||
HGLOBAL mem = GlobalAlloc(GMEM_MOVEABLE, bytes);
|
||||
if (mem != nullptr) {
|
||||
void* dst = GlobalLock(mem);
|
||||
if (dst != nullptr) {
|
||||
memcpy(dst, lic.c_str(), bytes);
|
||||
GlobalUnlock(mem);
|
||||
SetClipboardData(CF_UNICODETEXT, mem);
|
||||
}
|
||||
}
|
||||
CloseClipboard();
|
||||
}
|
||||
|
||||
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
|
||||
switch (msg) {
|
||||
case WM_CREATE: {
|
||||
HFONT font = static_cast<HFONT>(GetStockObject(DEFAULT_GUI_FONT));
|
||||
auto label = [&](const wchar_t* text, int x, int y, int w, int h) {
|
||||
HWND c = CreateWindowExW(0, L"STATIC", text, WS_CHILD | WS_VISIBLE, x,
|
||||
y, w, h, hwnd, nullptr, nullptr, nullptr);
|
||||
SendMessageW(c, WM_SETFONT, reinterpret_cast<WPARAM>(font), TRUE);
|
||||
};
|
||||
label(L"MAC 地址(例如 AA-BB-CC-DD-EE-FF):", 16, 16, 360, 20);
|
||||
g_mac = CreateWindowExW(WS_EX_CLIENTEDGE, L"EDIT", L"", WS_CHILD |
|
||||
WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL, 16, 40,
|
||||
420, 28, hwnd, reinterpret_cast<HMENU>(static_cast<INT_PTR>(kIdMac)),
|
||||
nullptr, nullptr);
|
||||
SendMessageW(g_mac, WM_SETFONT, reinterpret_cast<WPARAM>(font), TRUE);
|
||||
|
||||
HWND gen = CreateWindowExW(0, L"BUTTON", L"生成授权串",
|
||||
WS_CHILD | WS_VISIBLE | WS_TABSTOP |
|
||||
BS_DEFPUSHBUTTON,
|
||||
448, 40, 120, 28, hwnd,
|
||||
reinterpret_cast<HMENU>(static_cast<INT_PTR>(kIdGen)), nullptr,
|
||||
nullptr);
|
||||
SendMessageW(gen, WM_SETFONT, reinterpret_cast<WPARAM>(font), TRUE);
|
||||
|
||||
label(L"授权串(保存为 .lic 文件,放入 license 文件夹):", 16, 84, 460, 20);
|
||||
g_result = CreateWindowExW(WS_EX_CLIENTEDGE, L"EDIT", L"",
|
||||
WS_CHILD | WS_VISIBLE | ES_READONLY |
|
||||
ES_AUTOHSCROLL,
|
||||
16, 108, 552, 28, hwnd,
|
||||
reinterpret_cast<HMENU>(static_cast<INT_PTR>(kIdResult)), nullptr,
|
||||
nullptr);
|
||||
SendMessageW(g_result, WM_SETFONT, reinterpret_cast<WPARAM>(font), TRUE);
|
||||
|
||||
HWND copy = CreateWindowExW(0, L"BUTTON", L"复制",
|
||||
WS_CHILD | WS_VISIBLE | WS_TABSTOP, 16, 150,
|
||||
120, 30, hwnd,
|
||||
reinterpret_cast<HMENU>(static_cast<INT_PTR>(kIdCopy)), nullptr,
|
||||
nullptr);
|
||||
SendMessageW(copy, WM_SETFONT, reinterpret_cast<WPARAM>(font), TRUE);
|
||||
|
||||
label(L"提示:生成后把结果粘贴到 license\\<机器名>.lic(仅一行)。",
|
||||
16, 192, 560, 20);
|
||||
return 0;
|
||||
}
|
||||
case WM_COMMAND: {
|
||||
switch (LOWORD(wparam)) {
|
||||
case kIdGen:
|
||||
DoGenerate();
|
||||
return 0;
|
||||
case kIdCopy:
|
||||
DoCopy(hwnd);
|
||||
return 0;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WM_CLOSE:
|
||||
DestroyWindow(hwnd);
|
||||
return 0;
|
||||
case WM_DESTROY:
|
||||
PostQuitMessage(0);
|
||||
return 0;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return DefWindowProcW(hwnd, msg, wparam, lparam);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int WINAPI wWinMain(HINSTANCE instance, HINSTANCE, PWSTR, int show) {
|
||||
INITCOMMONCONTROLSEX icc{};
|
||||
icc.dwSize = sizeof(icc);
|
||||
icc.dwICC = ICC_STANDARD_CLASSES;
|
||||
InitCommonControlsEx(&icc);
|
||||
|
||||
WNDCLASSEXW wc{};
|
||||
wc.cbSize = sizeof(wc);
|
||||
wc.style = CS_HREDRAW | CS_VREDRAW;
|
||||
wc.lpfnWndProc = WndProc;
|
||||
wc.hInstance = instance;
|
||||
wc.hCursor = LoadCursor(nullptr, IDC_ARROW);
|
||||
wc.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_WINDOW + 1);
|
||||
wc.lpszClassName = L"SeqStudioKeygen";
|
||||
RegisterClassExW(&wc);
|
||||
|
||||
const int w = 600, h = 260;
|
||||
const int x = (GetSystemMetrics(SM_CXSCREEN) - w) / 2;
|
||||
const int y = (GetSystemMetrics(SM_CYSCREEN) - h) / 2;
|
||||
HWND hwnd = CreateWindowExW(0, wc.lpszClassName, L"时序图设计器 · 授权码生成器",
|
||||
WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU |
|
||||
WS_MINIMIZEBOX,
|
||||
x, y, w, h, nullptr, nullptr, instance, nullptr);
|
||||
if (hwnd == nullptr) return 1;
|
||||
|
||||
ShowWindow(hwnd, show);
|
||||
UpdateWindow(hwnd);
|
||||
|
||||
MSG msg;
|
||||
while (GetMessageW(&msg, nullptr, 0, 0)) {
|
||||
if (!IsDialogMessageW(hwnd, &msg)) {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessageW(&msg);
|
||||
}
|
||||
}
|
||||
return static_cast<int>(msg.wParam);
|
||||
}
|
||||
Binary file not shown.
Reference in New Issue
Block a user