2023-08-26 22:13:39 +08:00
|
|
|
|
#include "mysettingsdialog.h"
|
2023-08-08 15:15:19 +08:00
|
|
|
|
#include <Windows.h>
|
|
|
|
|
#include <QClipBoard>
|
|
|
|
|
#include "netio.h"
|
2023-08-10 15:36:08 +08:00
|
|
|
|
#include "sqlitehelper.h"
|
2023-08-08 15:15:19 +08:00
|
|
|
|
#include "config.h"
|
|
|
|
|
#include "globalvariables.h"
|
|
|
|
|
MySettingsDialog::MySettingsDialog(QWidget *parent)
|
|
|
|
|
: QDialog(parent)
|
|
|
|
|
{
|
|
|
|
|
ui.setupUi(this);
|
|
|
|
|
setWindowFlags(Qt::WindowCloseButtonHint);
|
|
|
|
|
this->setFixedSize(width(), height());
|
|
|
|
|
HKEY hRoot = HKEY_CURRENT_USER;
|
2023-08-26 22:13:39 +08:00
|
|
|
|
wchar_t *szSubKey = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run";
|
2023-08-08 15:15:19 +08:00
|
|
|
|
HKEY hKey;
|
2023-08-26 22:13:39 +08:00
|
|
|
|
DWORD dwDisposition = REG_OPENED_EXISTING_KEY; // 如果不存在不创建
|
2023-08-08 15:15:19 +08:00
|
|
|
|
LONG lRet = RegCreateKeyEx(hRoot, szSubKey, 0, NULL,
|
|
|
|
|
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition);
|
|
|
|
|
if (lRet != ERROR_SUCCESS) {
|
|
|
|
|
ui.autostart->setDisabled(true);
|
|
|
|
|
}
|
|
|
|
|
QString app = QApplication::applicationFilePath();
|
|
|
|
|
app.replace("/", "\\");
|
2023-08-26 22:13:39 +08:00
|
|
|
|
app += " autostart";
|
|
|
|
|
DWORD size=256*sizeof(wchar_t);
|
|
|
|
|
wchar_t reg[256] = { 0 };
|
|
|
|
|
lRet = RegQueryValueEx(hKey, LENG_NAME, NULL, NULL,(LPBYTE)reg, &size);
|
2023-08-08 15:15:19 +08:00
|
|
|
|
if (lRet==0) {
|
|
|
|
|
ui.autostart->setChecked(true);
|
|
|
|
|
}
|
|
|
|
|
copyButton = ui.copy;
|
|
|
|
|
connect(copyButton, &QPushButton::clicked, this, &MySettingsDialog::copyToCLipboard);
|
|
|
|
|
connect(ui.autostart, &QCheckBox::stateChanged, this, &MySettingsDialog::autoStart);
|
|
|
|
|
connect(ui.addshortcut, &QPushButton::clicked, this, &MySettingsDialog::createShortcut);
|
|
|
|
|
connect(ui.law_button, &QPushButton::clicked, this, &MySettingsDialog::law);
|
|
|
|
|
ui.code->setText(QString(QCryptographicHash::hash(getMachineGUID().toUtf8(), QCryptographicHash::Md5).toHex()));
|
|
|
|
|
ui.version->setText(QString(VERSION) + "-" + QString(RELEASE));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MySettingsDialog::~MySettingsDialog()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MySettingsDialog::autoStart(int state)
|
|
|
|
|
{
|
|
|
|
|
if (state == Qt::Checked) {
|
|
|
|
|
HKEY hRoot = HKEY_CURRENT_USER;
|
|
|
|
|
wchar_t *szSubKey = (wchar_t*)L"Software\\Microsoft\\Windows\\CurrentVersion\\Run";
|
|
|
|
|
HKEY hKey;
|
2023-08-26 22:13:39 +08:00
|
|
|
|
DWORD dwDisposition = REG_OPENED_EXISTING_KEY; // 如果不存在不创建
|
2023-08-08 15:15:19 +08:00
|
|
|
|
LONG lRet = RegCreateKeyEx(hRoot, szSubKey, 0, NULL,
|
|
|
|
|
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition);
|
|
|
|
|
if (lRet != ERROR_SUCCESS) {
|
2023-08-26 22:13:39 +08:00
|
|
|
|
QMessageBox::critical(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("创建开机启动项失败"));
|
2023-08-08 15:15:19 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
QString app = QApplication::applicationFilePath();
|
|
|
|
|
app.replace("/", "\\");
|
2023-08-13 12:16:22 +08:00
|
|
|
|
app += " autostart";
|
2023-08-08 15:15:19 +08:00
|
|
|
|
qDebug() << app.toStdWString().c_str();
|
|
|
|
|
lRet = RegSetValueEx(hKey, LENG_NAME, 0, REG_SZ, (BYTE*)app.toStdWString().c_str(), app.length()*sizeof(wchar_t));
|
|
|
|
|
if (lRet == ERROR_SUCCESS)
|
|
|
|
|
{
|
2023-08-26 22:13:39 +08:00
|
|
|
|
QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("创建开机启动项成功"));
|
2023-08-08 15:15:19 +08:00
|
|
|
|
}
|
|
|
|
|
RegCloseKey(hKey);
|
2023-08-13 12:16:22 +08:00
|
|
|
|
if(agree)
|
|
|
|
|
{
|
|
|
|
|
OpRequest op_request("auto_start", "true");
|
|
|
|
|
op_request.sendRequest();
|
|
|
|
|
}
|
2023-08-08 15:15:19 +08:00
|
|
|
|
}
|
|
|
|
|
else if (state == Qt::Unchecked) {
|
|
|
|
|
HKEY hRoot = HKEY_CURRENT_USER;
|
|
|
|
|
wchar_t *szSubKey = (wchar_t*)L"Software\\Microsoft\\Windows\\CurrentVersion\\Run";
|
|
|
|
|
HKEY hKey;
|
|
|
|
|
DWORD dwDisposition = REG_OPENED_EXISTING_KEY;
|
|
|
|
|
LONG lRet = RegCreateKeyEx(hRoot, szSubKey, 0, NULL,
|
|
|
|
|
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition);
|
|
|
|
|
if (lRet != ERROR_SUCCESS) {
|
2023-08-26 22:13:39 +08:00
|
|
|
|
QMessageBox::critical(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("移除开机启动项失败。"));
|
2023-08-08 15:15:19 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
QString app = QApplication::applicationFilePath();
|
|
|
|
|
lRet = RegDeleteValue(hKey, LENG_NAME);
|
|
|
|
|
if (lRet == ERROR_SUCCESS)
|
|
|
|
|
{
|
2023-08-26 22:13:39 +08:00
|
|
|
|
QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("移除开机启动项成功。"));
|
2023-08-08 15:15:19 +08:00
|
|
|
|
}
|
|
|
|
|
RegCloseKey(hKey);
|
2023-08-13 12:16:22 +08:00
|
|
|
|
if(agree)
|
|
|
|
|
{
|
|
|
|
|
OpRequest op_request("auto_start", "false");
|
|
|
|
|
op_request.sendRequest();
|
|
|
|
|
}
|
2023-08-08 15:15:19 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MySettingsDialog::law()
|
|
|
|
|
{
|
|
|
|
|
QString path = QApplication::applicationDirPath();
|
|
|
|
|
QString license = path + "/license.txt";
|
|
|
|
|
license.replace("/", "\\");
|
|
|
|
|
ShellExecute(GetDesktopWindow(), L"open", L"notepad.exe" , license.toStdWString().c_str(), nullptr, SW_SHOW);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MySettingsDialog::copyToCLipboard() {
|
|
|
|
|
QClipboard *clip = QApplication::clipboard();
|
|
|
|
|
clip->setText(QString(QCryptographicHash::hash(getMachineGUID().toUtf8(), QCryptographicHash::Md5).toHex()));
|
|
|
|
|
}
|
|
|
|
|
void MySettingsDialog::createShortcut() {
|
|
|
|
|
QString deskTopPath = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
|
|
|
|
|
deskTopPath = deskTopPath + QString::fromLocal8Bit("/");
|
|
|
|
|
deskTopPath = deskTopPath + QString::fromLocal8Bit(NAME);
|
|
|
|
|
deskTopPath = deskTopPath + QString::fromLocal8Bit(".lnk");
|
|
|
|
|
QString srcFile = QApplication::applicationFilePath();
|
|
|
|
|
bool succeed=QFile::link(srcFile, deskTopPath);
|
|
|
|
|
if (succeed) {
|
2023-08-26 22:13:39 +08:00
|
|
|
|
QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("创建快捷方式成功。"));
|
2023-08-08 15:15:19 +08:00
|
|
|
|
}
|
|
|
|
|
else {
|
2023-08-26 22:13:39 +08:00
|
|
|
|
QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("创建快捷方式失败。"));
|
2023-08-08 15:15:19 +08:00
|
|
|
|
}
|
2023-08-01 15:22:48 +08:00
|
|
|
|
}
|