155 lines
4.0 KiB
C++
155 lines
4.0 KiB
C++
|
#include "frmRegister.h"
|
|||
|
#include <QDesktopWidget>
|
|||
|
#include <QStyle>
|
|||
|
#include "datavar.h"
|
|||
|
|
|||
|
frmRegister::frmRegister(QWidget *parent)
|
|||
|
: QWidget(parent)
|
|||
|
{
|
|||
|
ui.setupUi(this);
|
|||
|
this->setWindowIcon(QIcon(":/Bitmaps/app.ico"));
|
|||
|
//<2F><><EFBFBD>ļ<EFBFBD><C4BC>в<EFBFBD><D0B2><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD>
|
|||
|
QDir dir;
|
|||
|
if (!dir.exists(dataVar::path_P))
|
|||
|
{
|
|||
|
dir.mkdir(dataVar::path_P);
|
|||
|
}
|
|||
|
if (!dir.exists(dataVar::path_PF))
|
|||
|
{
|
|||
|
dir.mkdir(dataVar::path_PF);
|
|||
|
}
|
|||
|
if (!dir.exists(dataVar::path_L))
|
|||
|
{
|
|||
|
dir.mkdir(dataVar::path_L);
|
|||
|
}
|
|||
|
if (!dir.exists(dataVar::path_LA))
|
|||
|
{
|
|||
|
dir.mkdir(dataVar::path_LA);
|
|||
|
}
|
|||
|
if (!dir.exists(dataVar::path_Image))
|
|||
|
{
|
|||
|
dir.mkdir(dataVar::path_Image);
|
|||
|
}
|
|||
|
if (!dir.exists(dataVar::path_DB))
|
|||
|
{
|
|||
|
dir.mkdir(dataVar::path_DB);
|
|||
|
}
|
|||
|
QString key1 = getCpuSerialNumber();
|
|||
|
QString key2 = getDiskSerialNumber();
|
|||
|
str_key = key1.mid(0, 4) + "s" + key2.mid(3, key2.length() - 2) + "7" + key1.mid(key1.length() - 4, key1.length() - 1) + "6";
|
|||
|
ui.txtSerialNumber->setText(str_key);
|
|||
|
QSettings settings("HKEY_CURRENT_USER\\Software\\MyApp", QSettings::NativeFormat);
|
|||
|
//<2F><>ȡע<C8A1><D7A2><EFBFBD><EFBFBD>
|
|||
|
value = settings.value("sn_code", "error").toString();
|
|||
|
if (form_state != 1)
|
|||
|
{
|
|||
|
m_timer = new QTimer(this);
|
|||
|
connect(m_timer, SIGNAL(timeout()), this, SLOT(form_statues()));
|
|||
|
m_timer->start(1);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void frmRegister::form_statues()
|
|||
|
{
|
|||
|
form_state = 1;
|
|||
|
m_timer->stop();
|
|||
|
m_timer->deleteLater();
|
|||
|
QString str_pw = GetKey(str_key);
|
|||
|
if (1/*value == str_pw*/)
|
|||
|
{
|
|||
|
this->close();
|
|||
|
frmVisualLogo *fVisualLogo = new frmVisualLogo();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
this->close();
|
|||
|
frmRegister *fRegister = new frmRegister();
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD>м<EFBFBD>
|
|||
|
fRegister->move(QApplication::desktop()->screen()->rect().center() - fRegister->rect().center());
|
|||
|
fRegister->show();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void frmRegister::on_btnCmdCheckID_clicked()
|
|||
|
{
|
|||
|
str_input = ui.txtAuthorizationCode->text();
|
|||
|
QString str_pw = GetKey(str_key);
|
|||
|
if (str_input == str_pw)
|
|||
|
{
|
|||
|
QSettings settings("HKEY_CURRENT_USER\\Software\\MyApp", QSettings::NativeFormat);
|
|||
|
//д<><D0B4>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>
|
|||
|
settings.setValue("sn_code", str_pw);
|
|||
|
QMessageBox msgBox(QMessageBox::Icon::NoIcon, "<EFBFBD><EFBFBD>ʾ", "Registration is complete!");
|
|||
|
msgBox.setWindowIcon(QIcon(":/res/ico/info.png"));
|
|||
|
msgBox.exec();
|
|||
|
this->close();
|
|||
|
this->deleteLater();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
QMessageBox msgBox(QMessageBox::Icon::NoIcon, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "Wrong registration code!");
|
|||
|
msgBox.setWindowIcon(QIcon(":/res/ico/error.png"));
|
|||
|
msgBox.exec();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void frmRegister::on_btnCmdCheckID_pressed()
|
|||
|
{
|
|||
|
ui.btnCmdCheckID->setStyleSheet("QPushButton{background-color: rgb(146, 217, 108);color: rgb(0, 0, 0);border: 2px groove gray; border-radius: 8px;}");
|
|||
|
}
|
|||
|
|
|||
|
void frmRegister::on_btnCmdCheckID_released()
|
|||
|
{
|
|||
|
ui.btnCmdCheckID->setStyleSheet("QPushButton{background-color: rgb(85, 170, 127);color: rgb(0, 0, 0);border: 2px groove gray; border-radius: 8px;}");
|
|||
|
}
|
|||
|
|
|||
|
QString frmRegister::GetKey(QString str)
|
|||
|
{
|
|||
|
QString md5;
|
|||
|
QByteArray data;
|
|||
|
data = QCryptographicHash::hash(str.toUtf8(), QCryptographicHash::Md5);
|
|||
|
md5.append(data.toHex());
|
|||
|
QString str1 = md5.mid(0, 10);
|
|||
|
QString str2 = md5.mid(10);
|
|||
|
QString str_all = "5" + str1 + "1" + str2 + "2";
|
|||
|
return str_all;
|
|||
|
}
|
|||
|
|
|||
|
QString frmRegister::getWMIC(const QString& cmd)
|
|||
|
{
|
|||
|
//<2F><>ѯcpu<70><75><EFBFBD>кţ<D0BA>wmic cpu get processorid
|
|||
|
//<2F><>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>кţ<D0BA>wmic baseboard get serialnumber
|
|||
|
//<2F><>ѯBIOS<4F><53><EFBFBD>кţ<D0BA>wmic bios get serialnumber
|
|||
|
//<2F>鿴Ӳ<E9BFB4><D3B2><EFBFBD><EFBFBD><EFBFBD>кţ<D0BA>wmic diskdrive get serialnumber
|
|||
|
QProcess p;
|
|||
|
p.start(cmd);
|
|||
|
p.waitForFinished();
|
|||
|
QString result = QString::fromLocal8Bit(p.readAllStandardOutput());
|
|||
|
QStringList list = cmd.split(" ");
|
|||
|
result = result.remove(list.last(), Qt::CaseInsensitive);
|
|||
|
result = result.replace("\r", "");
|
|||
|
result = result.replace("\n", "");
|
|||
|
result = result.simplified();
|
|||
|
return result;
|
|||
|
}
|
|||
|
|
|||
|
QString frmRegister::getCpuSerialNumber()
|
|||
|
{
|
|||
|
return getWMIC("wmic cpu get processorid");
|
|||
|
}
|
|||
|
|
|||
|
QString frmRegister::getMotherboardSerialNumber()
|
|||
|
{
|
|||
|
return getWMIC("wmic baseboard get serialnumber");
|
|||
|
}
|
|||
|
|
|||
|
QString frmRegister::getBIOSSerialNumber()
|
|||
|
{
|
|||
|
return getWMIC("wmic bios get serialnumber");
|
|||
|
}
|
|||
|
|
|||
|
QString frmRegister::getDiskSerialNumber()
|
|||
|
{
|
|||
|
return getWMIC("wmic diskdrive get serialnumber");
|
|||
|
}
|