1.0.0
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
#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);
|
||||
}
|
||||
Reference in New Issue
Block a user