96 lines
2.5 KiB
C++
96 lines
2.5 KiB
C++
#include "DogCheck.h"
|
|
#include "ui_DogCheck.h"
|
|
#include "sys_dog_auth_api/DogAuthInterface.h"
|
|
#include <QDesktopServices>
|
|
#include <QStandardPaths>
|
|
#include <QFile>
|
|
#include <QFileDialog>
|
|
#include <QMessageBox>
|
|
|
|
using namespace iot_sys;
|
|
DogCheck::DogCheck(QWidget *parent) :
|
|
QDialog(parent),
|
|
ui(new Ui::DogCheck)
|
|
{
|
|
ui->setupUi(this);
|
|
this->setWindowTitle(tr("加密狗检测"));
|
|
this->setWindowFlags(windowFlags()&~Qt::WindowContextHelpButtonHint);
|
|
slot_recheckBtn();
|
|
ui->recheckBtn->setText(tr("重新检测"));
|
|
connect(ui->recheckBtn, &QPushButton::clicked, this, &DogCheck::slot_recheckBtn);
|
|
connect(ui->pushButton_2,&QPushButton::clicked,this,&DogCheck::slot_openLicenseDir);
|
|
connect(ui->pushButton,&QPushButton::clicked,this,&DogCheck::slot_selectLicense);
|
|
|
|
}
|
|
|
|
DogCheck::~DogCheck()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void DogCheck::slot_recheckBtn()
|
|
{
|
|
CDogAuthInterfacePtr ptrDogAuth = getDogAuthInstance();
|
|
int nRet = ptrDogAuth->checkAuthStatus();
|
|
if (nRet > 0)
|
|
{
|
|
|
|
ui->statusLab->setText(tr("异常,错误码[%1]").arg(nRet));
|
|
}
|
|
else
|
|
{
|
|
ui->statusLab->setText(tr("正常"));
|
|
}
|
|
}
|
|
|
|
void DogCheck::slot_openLicenseDir()
|
|
{
|
|
QString strDir = QCoreApplication::applicationDirPath();
|
|
QString licenseDir = QString("%1/../common/license/").arg(strDir);
|
|
if(!QFileInfo::exists(licenseDir))
|
|
{
|
|
|
|
}
|
|
QDesktopServices::openUrl(QUrl::fromLocalFile(licenseDir));
|
|
}
|
|
|
|
void DogCheck::slot_selectLicense()
|
|
{
|
|
QString strBinDir = QCoreApplication::applicationDirPath();
|
|
QString licenseFile = QString("%1/../common/license/license.txt").arg(strBinDir);
|
|
|
|
QFile destFile(licenseFile);
|
|
if(destFile.exists())
|
|
{
|
|
if(!destFile.remove())
|
|
{
|
|
QMessageBox::warning(this, tr("提示"), QString("删除原文件失败"));
|
|
return ;
|
|
}
|
|
}
|
|
|
|
QFileDialog fileDialog;
|
|
QString strDir = fileDialog.getOpenFileName(this, tr("选择授权文件"),"license.txt",tr("txt (*.txt)"));
|
|
|
|
if (strDir.isEmpty())
|
|
{
|
|
return ;
|
|
}
|
|
|
|
QFile sourceFile(strDir);
|
|
if (!sourceFile.exists()) {
|
|
QMessageBox::warning(this, tr("提示"), QString("文件不存在"));
|
|
return ;
|
|
}
|
|
|
|
bool ret = sourceFile.copy(licenseFile);
|
|
if(!ret)
|
|
{
|
|
QMessageBox::warning(this, tr("提示"), QString("导入失败![%1]").arg(sourceFile.errorString()));
|
|
return;
|
|
}
|
|
|
|
|
|
QMessageBox::warning(this, tr("提示"), QString("导入成功!"));
|
|
}
|