Update: 新增 --full/-f,整包模式改由显式标志指定。原判定 clientVersion.empty() 会让 check-update 缺少 version 参数,服务端返回 400「版本号参数错误」。CrownServer/CrownClient: 退出码 3(badVersion) 归入放行,不再打断启动;整包分支补上 --version。CrownClient.rc: 版本 1.0.6.8 -> 1.0.7.8 与服务端对齐,后台无 1.0.6.8 会导致客户端一直被判为版本不认。
148 lines
4.1 KiB
C++
148 lines
4.1 KiB
C++
#include "CrownClient.h"
|
|
#include <QtWidgets/QApplication>
|
|
#include "Global.h"
|
|
#include "Login.h"
|
|
#include <QLocalServer>
|
|
#include <QLocalSocket>
|
|
#include <QProcess>
|
|
#include <QFileInfo>
|
|
#include "AppInstanceManager.h"
|
|
|
|
#include "Utils.h"
|
|
#pragma comment(lib,"D:\\reverse\\vmprotect33\\Lib\\Windows\\VMProtectSDK64.lib")
|
|
|
|
#include "StyleLoader.h"
|
|
|
|
#include "MessageHandle.h"
|
|
|
|
namespace {
|
|
|
|
// 更新服务应用 AppKey,取自 verify 后台 -> 应用 -> AppKey
|
|
const char* kUpdaterAppKey = "abab3280114bfe824acfdbc6255538fb";
|
|
|
|
// Update.exe --check-only 的退出码
|
|
const int kUpdaterNoUpdate = 0; // 已是最新版本
|
|
const int kUpdaterHasUpdate = 1; // 有更新
|
|
const int kUpdaterFailed = 2; // 检查失败(网络/解密/解析异常)
|
|
const int kUpdaterBadVersion = 3; // 服务端版本表里没有当前版本,只能整包重装
|
|
|
|
// 静默检查更新。返回 true 表示主程序可以继续往下走(进入登录),
|
|
// false 表示已经把更新交给 Update.exe,主程序应当退出
|
|
bool CheckAndRunUpdater()
|
|
{
|
|
const QString appDir = QCoreApplication::applicationDirPath();
|
|
const QString updater = appDir + "/Update.exe";
|
|
if (!QFileInfo::exists(updater)) {
|
|
return true; // 没有更新器就保持原有行为
|
|
}
|
|
|
|
const QString exeName = QFileInfo(QCoreApplication::applicationFilePath()).fileName();
|
|
const int code = QProcess::execute(updater, QStringList()
|
|
<< "--check-only"
|
|
<< "--app-key" << kUpdaterAppKey
|
|
<< "--version" << VERSION);
|
|
|
|
if (code == kUpdaterNoUpdate || code == kUpdaterFailed || code == kUpdaterBadVersion) {
|
|
// 已经是最新 / 检查失败 / 服务端不认识当前版本 —— 都放行,避免把用户挡在门外。
|
|
// badVersion 时服务端不会为这个版本返回可用的包信息,强行拉起更新器
|
|
// 只会让用户卡在"版本号参数错误"的界面上
|
|
return true;
|
|
}
|
|
|
|
QStringList args;
|
|
if (code == kUpdaterBadVersion) {
|
|
// 服务端不认识当前版本,补丁包无从生成,直接整包覆盖安装到程序所在目录。
|
|
// 仍要带上 --version:更新器内部会用它请求服务端,空版本号会被判为参数错误
|
|
args << "--app-key" << kUpdaterAppKey << "--version" << VERSION
|
|
<< "--dir" << appDir << "--full";
|
|
} else {
|
|
// 常规补丁包更新
|
|
args << "--app-key" << kUpdaterAppKey << "--version" << VERSION
|
|
<< "--dir" << appDir;
|
|
}
|
|
args << "--launch" << exeName;
|
|
|
|
QProcess::startDetached(updater, args, appDir);
|
|
return false;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
|
|
// 禁用GPU加速(如果黑屏)
|
|
qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--disable-gpu");
|
|
// 启用软件渲染
|
|
qputenv("QT_QUICK_BACKEND", "software");
|
|
qputenv("QT_XCB_FORCE_SOFTWARE_OPENGL", "1");
|
|
// 设置DPI兼容
|
|
if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
|
|
{
|
|
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
|
}
|
|
|
|
// 检测SSL兼容
|
|
if (!QSslSocket::supportsSsl())
|
|
{
|
|
QMessageBox::warning(nullptr, "警告", "OpenSSL组件异常");
|
|
return 0;
|
|
}
|
|
|
|
// 防止多开
|
|
if (AppInstanceManager::isAlreadyRunning()) {
|
|
return 0;
|
|
}
|
|
|
|
// 关闭浏览器安全警告
|
|
char ARG_DISABLE_WEB_SECURITY[] = "--disable-web-security";
|
|
int newArgc = argc + 1 + 1;
|
|
char** newArgv = new char*[newArgc];
|
|
for (int i = 0; i < argc; i++) {
|
|
newArgv[i] = argv[i];
|
|
}
|
|
newArgv[argc] = ARG_DISABLE_WEB_SECURITY;
|
|
newArgv[argc + 1] = nullptr;
|
|
|
|
|
|
|
|
QApplication app(newArgc, newArgv);
|
|
|
|
|
|
qInstallMessageHandler(message_handle);
|
|
|
|
|
|
// 加载QSS样式
|
|
QString style = StyleLoader::loadStyleFromResource();
|
|
if (!style.isEmpty()) {
|
|
app.setStyleSheet(style);
|
|
}
|
|
|
|
// 设置调试端口临时环境变量
|
|
qputenv("QTWEBENGINE_REMOTE_DEBUGGING", "7777");
|
|
|
|
// 设置字体
|
|
QFont font("黑体", 11);
|
|
app.setFont(font);
|
|
|
|
// 初始化配置类
|
|
g_config = new Config();
|
|
|
|
// 初始化验证类(AppKey 和 EncryptKey 都取自 verify 后台的应用配置)
|
|
g_verify = new Verify("https://gendan.xyz", "abab3280114bfe824acfdbc6255538fb",
|
|
"07dab7c3c772a8a8f2dad3f45e2e397806d92f560ac954532ee7562a03c1df14", VERSION);
|
|
|
|
|
|
// 检测更新(由 Update.exe 走 verify 新版接口静默检查)
|
|
if (CheckAndRunUpdater())
|
|
{
|
|
Login w;
|
|
w.show();
|
|
|
|
return app.exec();
|
|
}
|
|
|
|
return 0;
|
|
}
|