feat(client): 迁移Hub更新客户端实现
This commit is contained in:
+69
-72
@@ -1,72 +1,69 @@
|
||||
#include "MainWindow.h"
|
||||
#include <QApplication>
|
||||
#include <QFont>
|
||||
#include <QFile>
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
#include <QCryptographicHash>
|
||||
#include "../Common/PolicyHelper.h"
|
||||
#include "../Common/ConfigHelper.h"
|
||||
|
||||
static QString readDllVersion(const QString& dllPath)
|
||||
{
|
||||
QFile file(dllPath);
|
||||
if (!file.exists())
|
||||
return "missing";
|
||||
|
||||
if (!file.open(QIODevice::ReadOnly))
|
||||
return "unreadable";
|
||||
|
||||
QByteArray data = file.read(1024);
|
||||
file.close();
|
||||
return QString::fromUtf8(QCryptographicHash::hash(data, QCryptographicHash::Sha256).toHex().left(8));
|
||||
}
|
||||
|
||||
MainWindow::MainWindow(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
this->setWindowTitle("Marsco Demo MainApp");
|
||||
this->resize(600, 400);
|
||||
|
||||
QString appVersion = ConfigHelper::instance().getValue("App", "current_version");
|
||||
if (appVersion.isEmpty())
|
||||
appVersion = "unknown";
|
||||
|
||||
QString dllVersion = readDllVersion(QApplication::applicationDirPath() + "/plugins/demo_plugin.dll");
|
||||
|
||||
PolicyHelper policy(QApplication::applicationDirPath());
|
||||
QString policyResult;
|
||||
if (!policy.loadPolicy("config/version_policy.dat"))
|
||||
{
|
||||
policyResult = "policy missing";
|
||||
}
|
||||
else if (!policy.isValid())
|
||||
{
|
||||
policyResult = "policy invalid";
|
||||
}
|
||||
else if (!policy.isVersionAllowed(appVersion))
|
||||
{
|
||||
policyResult = "version disabled";
|
||||
}
|
||||
else if (policy.isExpired())
|
||||
{
|
||||
policyResult = "policy expired";
|
||||
}
|
||||
else
|
||||
{
|
||||
policyResult = "policy ok";
|
||||
}
|
||||
|
||||
QVBoxLayout* layout = new QVBoxLayout(this);
|
||||
QLabel* label = new QLabel(QString("Software Running Successfully\nVersion: %1\nDLL Version: %2\nPolicy: %3")
|
||||
.arg(appVersion)
|
||||
.arg(dllVersion)
|
||||
.arg(policyResult));
|
||||
QFont font = label->font();
|
||||
font.setPointSize(14);
|
||||
label->setFont(font);
|
||||
label->setAlignment(Qt::AlignCenter);
|
||||
|
||||
layout->addWidget(label);
|
||||
this->setLayout(layout);
|
||||
}
|
||||
#include "MainWindow.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QCryptographicHash>
|
||||
#include <QFile>
|
||||
#include <QFont>
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "../Common/ConfigHelper.h"
|
||||
|
||||
namespace {
|
||||
|
||||
QString configValue(const QString& key, const QString& fallback = QString())
|
||||
{
|
||||
const QString value = ConfigHelper::instance().getValue(QString(), key).trimmed();
|
||||
return value.isEmpty() ? fallback : value;
|
||||
}
|
||||
|
||||
QString readDllVersion(const QString& dllPath)
|
||||
{
|
||||
QFile file(dllPath);
|
||||
if (!file.exists())
|
||||
return QStringLiteral("missing");
|
||||
|
||||
if (!file.open(QIODevice::ReadOnly))
|
||||
return QStringLiteral("unreadable");
|
||||
|
||||
const QByteArray data = file.read(1024);
|
||||
file.close();
|
||||
return QString::fromUtf8(QCryptographicHash::hash(data, QCryptographicHash::Sha256).toHex().left(8));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
MainWindow::MainWindow(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
this->setWindowTitle("SimCAE Demo MainApp");
|
||||
this->resize(600, 400);
|
||||
|
||||
const QString appVersion = configValue(QStringLiteral("current_version"), QStringLiteral("unknown"));
|
||||
const QString product = configValue(QStringLiteral("product_code"),
|
||||
configValue(QStringLiteral("app_id"), QStringLiteral("unknown")));
|
||||
const QString channel = configValue(QStringLiteral("channel"), QStringLiteral("stable"));
|
||||
const QString apiBaseUrl = configValue(QStringLiteral("api_base_url"), QStringLiteral("not configured"));
|
||||
const QString tokenState = configValue(QStringLiteral("client_token")).isEmpty()
|
||||
? QStringLiteral("missing")
|
||||
: QStringLiteral("configured");
|
||||
const QString dllVersion = readDllVersion(QApplication::applicationDirPath() + "/plugins/demo_plugin.dll");
|
||||
|
||||
QVBoxLayout* layout = new QVBoxLayout(this);
|
||||
QLabel* label = new QLabel(QString(
|
||||
"Software Running Successfully\n"
|
||||
"Product: %1\n"
|
||||
"Version: %2\n"
|
||||
"Channel: %3\n"
|
||||
"Server: %4\n"
|
||||
"Update Client Token: %5\n"
|
||||
"DLL Version: %6")
|
||||
.arg(product, appVersion, channel, apiBaseUrl, tokenState, dllVersion));
|
||||
QFont font = label->font();
|
||||
font.setPointSize(13);
|
||||
label->setFont(font);
|
||||
label->setAlignment(Qt::AlignCenter);
|
||||
|
||||
layout->addWidget(label);
|
||||
this->setLayout(layout);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user