新增了客户端打包成sdk的功能和服务端docker镜像打包的功能,并修复了一些问题
This commit is contained in:
@@ -9,6 +9,10 @@
|
||||
#include "../Common/ConfigHelper.h"
|
||||
#include "../Common/PolicyHelper.h"
|
||||
#include "../Common/LocalStateHelper.h"
|
||||
#include "../Common/TicketHelper.h"
|
||||
#include "../Common/DeviceIdentityHelper.h"
|
||||
#include <QFile>
|
||||
#include <QFileDialog>
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
@@ -26,6 +30,18 @@ int main(int argc, char* argv[])
|
||||
progress.show();
|
||||
QApplication::processEvents();
|
||||
|
||||
ConfigHelper& config = ConfigHelper::instance();
|
||||
DeviceIdentityHelper identity(QApplication::applicationDirPath());
|
||||
if (!identity.ensureIssued(config.getValue("Server", "api_base_url"),
|
||||
config.getValue("Server", "client_token"),
|
||||
config.getValue("App", "app_id"),
|
||||
config.getValue("App", "channel"),
|
||||
config.getValue("License", "license_key"))) {
|
||||
progress.close();
|
||||
QMessageBox::critical(nullptr, "设备身份验证失败", identity.errorString());
|
||||
return -1;
|
||||
}
|
||||
|
||||
UpdateLogic logic;
|
||||
logic.checkUpdate();
|
||||
|
||||
@@ -37,13 +53,49 @@ int main(int argc, char* argv[])
|
||||
const QString appId = logic.getAppId();
|
||||
const QString channel = logic.getChannel();
|
||||
|
||||
ConfigHelper& config = ConfigHelper::instance();
|
||||
if (logic.lastStatusCode() == 401 || logic.lastStatusCode() == 403) {
|
||||
progress.close();
|
||||
const QJsonValue detail = response.value("detail");
|
||||
const QString message = detail.isObject() ? detail.toObject().value("msg").toString() : detail.toString();
|
||||
QMessageBox::critical(nullptr, "授权被拒绝", message.isEmpty() ? "设备或 License 授权无效。" : message);
|
||||
return -1;
|
||||
}
|
||||
|
||||
const QString launchToken = config.getValue("App", "launch_token");
|
||||
const QString currentVersion = config.getValue("App", "current_version");
|
||||
const QString appDir = QApplication::applicationDirPath();
|
||||
const QString mainAppPath = appDir + "/MainApp.exe";
|
||||
const QString updaterPath = appDir + "/Updater.exe";
|
||||
const QStringList mainArgs{QString("--launcher-token=%1").arg(launchToken)};
|
||||
const auto configuredName = [&](const QString& key, const QString& fallback) {
|
||||
const QString value = config.getValue("Runtime", key).trimmed();
|
||||
return value.isEmpty() ? fallback : value;
|
||||
};
|
||||
const QString mainExecutable = configuredName("main_executable", "MainApp.exe");
|
||||
const QString updaterExecutable = configuredName("updater_executable", "Updater.exe");
|
||||
const QString mainAppPath = QDir(appDir).filePath(mainExecutable);
|
||||
const QString updaterPath = QDir(appDir).filePath(updaterExecutable);
|
||||
const auto importOfflinePackage = [&]() {
|
||||
const QString package = QFileDialog::getOpenFileName(nullptr, "选择离线更新包", QString(), "Marsco 离线更新包 (*.upd)");
|
||||
return package.isEmpty() ? false : QProcess::startDetached(updaterPath, QStringList{QString("--offline-package=%1").arg(package)});
|
||||
};
|
||||
const QString deviceId = config.getValue("Update", "device_id");
|
||||
if (QCoreApplication::arguments().contains("--import-offline")) {
|
||||
progress.close();
|
||||
if (!importOfflinePackage()) QMessageBox::information(nullptr, "离线更新", "未选择离线更新包。");
|
||||
return 0;
|
||||
}
|
||||
|
||||
const auto startMainApp = [&]() {
|
||||
QString ticketPath;
|
||||
QString ticketError;
|
||||
if (!TicketHelper::createTicket(logic.getAppId(), deviceId, currentVersion,
|
||||
launchToken, &ticketPath, &ticketError)) {
|
||||
qDebug() << "Cannot create launch ticket:" << ticketError;
|
||||
return false;
|
||||
}
|
||||
const bool started = QProcess::startDetached(mainAppPath,
|
||||
QStringList{QString("--ticket-file=%1").arg(ticketPath)});
|
||||
if (!started) QFile::remove(ticketPath);
|
||||
return started;
|
||||
};
|
||||
|
||||
progress.setLabelText("正在验证本地运行策略...");
|
||||
QApplication::processEvents();
|
||||
@@ -108,7 +160,7 @@ int main(int argc, char* argv[])
|
||||
QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::Yes;
|
||||
}
|
||||
if (!accepted) {
|
||||
if (!QProcess::startDetached(mainAppPath, mainArgs)) {
|
||||
if (!startMainApp()) {
|
||||
QMessageBox::critical(nullptr, "启动失败", QString("无法启动主程序:%1").arg(mainAppPath));
|
||||
return -1;
|
||||
}
|
||||
@@ -123,6 +175,16 @@ int main(int argc, char* argv[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!networkOk) {
|
||||
progress.close();
|
||||
if (QMessageBox::question(nullptr, "服务器不可用", "当前无法连接更新服务器。是否导入离线更新包?",
|
||||
QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::Yes) {
|
||||
if (!importOfflinePackage()) QMessageBox::information(nullptr, "离线更新", "未选择离线更新包或无法启动更新器。");
|
||||
return 0;
|
||||
}
|
||||
progress.show();
|
||||
}
|
||||
|
||||
if (!networkOk && !policy.isOfflineAllowed())
|
||||
{
|
||||
progress.close();
|
||||
@@ -132,7 +194,7 @@ int main(int argc, char* argv[])
|
||||
|
||||
progress.setLabelText(networkOk ? "当前已是最新版本,正在启动..." : "当前处于离线模式,正在启动...");
|
||||
QApplication::processEvents();
|
||||
if (!QProcess::startDetached(mainAppPath, mainArgs))
|
||||
if (!startMainApp())
|
||||
{
|
||||
progress.close();
|
||||
QMessageBox::critical(nullptr, "启动失败", QString("无法启动主程序:%1").arg(mainAppPath));
|
||||
|
||||
Reference in New Issue
Block a user