#include "DialogPreferences.h" #include "Preferences.h" #include #define AUTO_RUN "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run" #define PATH1 "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Windows" #define PATH2 "HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows NT\\CurrentVersion\\Windows" #define PATH3 "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager" DialogPreferences::DialogPreferences(QWidget* parent) : QDialog(parent) { ui.setupUi(this); thePrefs.m_bEnableDebugView = true; // 如果当前无管理员权限,则禁止显示 if (!IsUserAnAdmin()) { ui.groupBox_Hid->hide(); ui.cBox_EnHid->hide(); } else { QSettings* reg = new QSettings(PATH3, QSettings::NativeFormat); QStringList list = reg->value("ExcludeFromKnownDlls").toStringList(); if (list.size() > 1) { ui.cBox_EnHid->setChecked(true); } } // 判断是否为自动启动软件状态 if (isAutoRun(QApplication::applicationFilePath())) { ui.cBox_EnAutoRun->setChecked(true); } } DialogPreferences::~DialogPreferences() { } /// /// 设置/取消 进程开机自动启动函数 /// /// /// void DialogPreferences::setProcessAutoRun(const QString& appPath, bool flag) { QSettings settings(AUTO_RUN, QSettings::NativeFormat); //以程序名称作为注册表中的键,根据键获取对应的值(程序路径) QFileInfo fInfo(appPath); QString name = fInfo.baseName(); //键-名称 //如果注册表中的路径和当前程序路径不一样,则表示没有设置自启动或本自启动程序已经更换了路径 QString oldPath = settings.value(name).toString(); //获取目前的值-绝对路劲 QString newPath = QDir::toNativeSeparators(appPath); //toNativeSeparators函数将"/"替换为"\" if (flag) { if (oldPath != newPath) { settings.setValue(name, newPath); } } else { settings.remove(name); } } bool DialogPreferences::isAutoRun(const QString& appPath) { QSettings settings(AUTO_RUN, QSettings::NativeFormat); QFileInfo fInfo(appPath); QString name = fInfo.baseName(); QString oldPath = settings.value(name).toString(); QString newPath = QDir::toNativeSeparators(appPath); return (settings.contains(name) && newPath == oldPath); } /// /// /// void DialogPreferences::on_btn_ok_clicked() { this->close(); } /// /// /// void DialogPreferences::on_btn_cancel_clicked() { this->accept(); } /// /// /// void DialogPreferences::on_btn_ImportLogo_clicked() { // 获取加载的全路径 QString OpenFile, OpenFilePath; OpenFile = QFileDialog::getOpenFileName(this, tr("Open POU"), "/home/POU", tr("POU Files (*.png)")); if (!OpenFile.isEmpty()) { QImage img; img.load(OpenFile); QString strPath = QCoreApplication::applicationDirPath() + "/Logo.png"; img.save(strPath, "png", -1); } } /// /// /// void DialogPreferences::on_btn_ImportDesktop_clicked() { // 获取加载的全路径 QString OpenFile, OpenFilePath; OpenFile = QFileDialog::getOpenFileName(this, "please choose an image file", "", "Image Files(*.jpg *.png *.bmp *.pgm *.pbm);;All(*.*)"); if (!OpenFile.isEmpty()) { QImage img; img.load(OpenFile); QString strPath = QCoreApplication::applicationDirPath() + "/Desktop.bmp"; img.save(strPath, "bmp", -1); } } /// /// /// void DialogPreferences::on_btn_ImportSplash_clicked() { // 获取加载的全路径 QString OpenFile, OpenFilePath; OpenFile = QFileDialog::getOpenFileName(this, "please choose an image file", "", "Image Files(*.jpg *.png *.bmp *.pgm *.pbm);;All(*.*)"); if (!OpenFile.isEmpty()) { QImage img; img.load(OpenFile); QString strPath = QCoreApplication::applicationDirPath() + "/Splash.bmp"; img.save(strPath, "bmp", -1); } } /// /// /// /// void DialogPreferences::on_cBox_EnHid_stateChanged(int arg1) { { QSettings* reg = new QSettings(PATH1, QSettings::NativeFormat); if (arg1 == 2) { reg->setValue("AppInit_DLLs", "HID.dll"); reg->setValue("LoadAppInit_DLLs", 1); reg->setValue("RequireSignedAppInit_DLLs", 0); } else { reg->remove("AppInit_DLLs"); reg->remove("LoadAppInit_DLLs"); reg->remove("RequireSignedAppInit_DLLs"); } delete reg; } { QSettings* reg = new QSettings(PATH2, QSettings::NativeFormat); if (arg1 == 2) { reg->setValue("AppInit_DLLs", "HID.dll"); reg->setValue("LoadAppInit_DLLs", 1); reg->setValue("RequireSignedAppInit_DLLs", 0); } else { reg->remove("AppInit_DLLs"); reg->remove("LoadAppInit_DLLs"); reg->remove("RequireSignedAppInit_DLLs"); } delete reg; } { QSettings* reg = new QSettings(PATH3, QSettings::NativeFormat); QStringList list; list.push_back("Cryptsp.dll"); list.push_back("ws2help.dll"); list.push_back("setupapi.dll"); list.push_back("ws2_32.dll"); list.push_back("wsock32.dll"); list.push_back("msvbvm60.dll"); list.push_back("hid.dll"); list.push_back("lpk.dll"); list.push_back("usp10.dll"); list.push_back("RC_GrandLocal.dll"); list.push_back("winmm.dll"); list.push_back("psapi.dll"); list.push_back("usp10.dll"); list.push_back("shlwapi.dll"); list.push_back("version.dll"); list.push_back("shfolder.dll"); list.push_back("IPHLPAPI.dll"); list.push_back("MSIMG32.dll"); if (arg1 == 2) { reg->setValue("ExcludeFromKnownDlls", list); } else { reg->remove("ExcludeFromKnownDlls"); } delete reg; } } void DialogPreferences::on_cBox_EnAutoRun_stateChanged(int arg1) { if (arg1 == 2) { setProcessAutoRun(QApplication::applicationFilePath(), 1); } else { setProcessAutoRun(QApplication::applicationFilePath(), 0); } }