123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- #include "DialogPreferences.h"
- #include "Preferences.h"
- #include <ShlObj_core.h>
- #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()
- {
- }
- /// <summary>
- /// 设置/取消 进程开机自动启动函数
- /// </summary>
- /// <param name="appPath"></param>
- /// <param name="flag"></param>
- 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);
- }
- /// <summary>
- ///
- /// </summary>
- void DialogPreferences::on_btn_ok_clicked()
- {
- this->close();
- }
- /// <summary>
- ///
- /// </summary>
- void DialogPreferences::on_btn_cancel_clicked()
- {
- this->accept();
- }
- /// <summary>
- ///
- /// </summary>
- 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);
- }
- }
- /// <summary>
- ///
- /// </summary>
- 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);
- }
- }
- /// <summary>
- ///
- /// </summary>
- 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);
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="arg1"></param>
- 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);
- }
- }
|