DialogPreferences.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. #include "DialogPreferences.h"
  2. #include "Preferences.h"
  3. #include <ShlObj_core.h>
  4. #define AUTO_RUN "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run"
  5. #define PATH1 "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Windows"
  6. #define PATH2 "HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows NT\\CurrentVersion\\Windows"
  7. #define PATH3 "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager"
  8. DialogPreferences::DialogPreferences(QWidget* parent)
  9. : QDialog(parent)
  10. {
  11. ui.setupUi(this);
  12. thePrefs.m_bEnableDebugView = true;
  13. // 如果当前无管理员权限,则禁止显示
  14. if (!IsUserAnAdmin())
  15. {
  16. ui.groupBox_Hid->hide();
  17. ui.cBox_EnHid->hide();
  18. }
  19. else
  20. {
  21. QSettings* reg = new QSettings(PATH3, QSettings::NativeFormat);
  22. QStringList list = reg->value("ExcludeFromKnownDlls").toStringList();
  23. if (list.size() > 1)
  24. {
  25. ui.cBox_EnHid->setChecked(true);
  26. }
  27. }
  28. // 判断是否为自动启动软件状态
  29. if (isAutoRun(QApplication::applicationFilePath()))
  30. {
  31. ui.cBox_EnAutoRun->setChecked(true);
  32. }
  33. }
  34. DialogPreferences::~DialogPreferences()
  35. {
  36. }
  37. /// <summary>
  38. /// 设置/取消 进程开机自动启动函数
  39. /// </summary>
  40. /// <param name="appPath"></param>
  41. /// <param name="flag"></param>
  42. void DialogPreferences::setProcessAutoRun(const QString& appPath, bool flag)
  43. {
  44. QSettings settings(AUTO_RUN, QSettings::NativeFormat);
  45. //以程序名称作为注册表中的键,根据键获取对应的值(程序路径)
  46. QFileInfo fInfo(appPath);
  47. QString name = fInfo.baseName(); //键-名称
  48. //如果注册表中的路径和当前程序路径不一样,则表示没有设置自启动或本自启动程序已经更换了路径
  49. QString oldPath = settings.value(name).toString(); //获取目前的值-绝对路劲
  50. QString newPath = QDir::toNativeSeparators(appPath); //toNativeSeparators函数将"/"替换为"\"
  51. if (flag)
  52. {
  53. if (oldPath != newPath)
  54. {
  55. settings.setValue(name, newPath);
  56. }
  57. }
  58. else
  59. {
  60. settings.remove(name);
  61. }
  62. }
  63. bool DialogPreferences::isAutoRun(const QString& appPath)
  64. {
  65. QSettings settings(AUTO_RUN, QSettings::NativeFormat);
  66. QFileInfo fInfo(appPath);
  67. QString name = fInfo.baseName();
  68. QString oldPath = settings.value(name).toString();
  69. QString newPath = QDir::toNativeSeparators(appPath);
  70. return (settings.contains(name) && newPath == oldPath);
  71. }
  72. /// <summary>
  73. ///
  74. /// </summary>
  75. void DialogPreferences::on_btn_ok_clicked()
  76. {
  77. this->close();
  78. }
  79. /// <summary>
  80. ///
  81. /// </summary>
  82. void DialogPreferences::on_btn_cancel_clicked()
  83. {
  84. this->accept();
  85. }
  86. /// <summary>
  87. ///
  88. /// </summary>
  89. void DialogPreferences::on_btn_ImportLogo_clicked()
  90. {
  91. // 获取加载的全路径
  92. QString OpenFile, OpenFilePath;
  93. OpenFile = QFileDialog::getOpenFileName(this,
  94. tr("Open POU"), "/home/POU", tr("POU Files (*.png)"));
  95. if (!OpenFile.isEmpty())
  96. {
  97. QImage img;
  98. img.load(OpenFile);
  99. QString strPath = QCoreApplication::applicationDirPath() + "/Logo.png";
  100. img.save(strPath, "png", -1);
  101. }
  102. }
  103. /// <summary>
  104. ///
  105. /// </summary>
  106. void DialogPreferences::on_btn_ImportDesktop_clicked()
  107. {
  108. // 获取加载的全路径
  109. QString OpenFile, OpenFilePath;
  110. OpenFile = QFileDialog::getOpenFileName(this,
  111. "please choose an image file",
  112. "",
  113. "Image Files(*.jpg *.png *.bmp *.pgm *.pbm);;All(*.*)");
  114. if (!OpenFile.isEmpty())
  115. {
  116. QImage img;
  117. img.load(OpenFile);
  118. QString strPath = QCoreApplication::applicationDirPath() + "/Desktop.bmp";
  119. img.save(strPath, "bmp", -1);
  120. }
  121. }
  122. /// <summary>
  123. ///
  124. /// </summary>
  125. void DialogPreferences::on_btn_ImportSplash_clicked()
  126. {
  127. // 获取加载的全路径
  128. QString OpenFile, OpenFilePath;
  129. OpenFile = QFileDialog::getOpenFileName(this,
  130. "please choose an image file",
  131. "",
  132. "Image Files(*.jpg *.png *.bmp *.pgm *.pbm);;All(*.*)");
  133. if (!OpenFile.isEmpty())
  134. {
  135. QImage img;
  136. img.load(OpenFile);
  137. QString strPath = QCoreApplication::applicationDirPath() + "/Splash.bmp";
  138. img.save(strPath, "bmp", -1);
  139. }
  140. }
  141. /// <summary>
  142. ///
  143. /// </summary>
  144. /// <param name="arg1"></param>
  145. void DialogPreferences::on_cBox_EnHid_stateChanged(int arg1)
  146. {
  147. {
  148. QSettings* reg = new QSettings(PATH1, QSettings::NativeFormat);
  149. if (arg1 == 2)
  150. {
  151. reg->setValue("AppInit_DLLs", "HID.dll");
  152. reg->setValue("LoadAppInit_DLLs", 1);
  153. reg->setValue("RequireSignedAppInit_DLLs", 0);
  154. }
  155. else
  156. {
  157. reg->remove("AppInit_DLLs");
  158. reg->remove("LoadAppInit_DLLs");
  159. reg->remove("RequireSignedAppInit_DLLs");
  160. }
  161. delete reg;
  162. }
  163. {
  164. QSettings* reg = new QSettings(PATH2, QSettings::NativeFormat);
  165. if (arg1 == 2)
  166. {
  167. reg->setValue("AppInit_DLLs", "HID.dll");
  168. reg->setValue("LoadAppInit_DLLs", 1);
  169. reg->setValue("RequireSignedAppInit_DLLs", 0);
  170. }
  171. else
  172. {
  173. reg->remove("AppInit_DLLs");
  174. reg->remove("LoadAppInit_DLLs");
  175. reg->remove("RequireSignedAppInit_DLLs");
  176. }
  177. delete reg;
  178. }
  179. {
  180. QSettings* reg = new QSettings(PATH3, QSettings::NativeFormat);
  181. QStringList list;
  182. list.push_back("Cryptsp.dll");
  183. list.push_back("ws2help.dll");
  184. list.push_back("setupapi.dll");
  185. list.push_back("ws2_32.dll");
  186. list.push_back("wsock32.dll");
  187. list.push_back("msvbvm60.dll");
  188. list.push_back("hid.dll");
  189. list.push_back("lpk.dll");
  190. list.push_back("usp10.dll");
  191. list.push_back("RC_GrandLocal.dll");
  192. list.push_back("winmm.dll");
  193. list.push_back("psapi.dll");
  194. list.push_back("usp10.dll");
  195. list.push_back("shlwapi.dll");
  196. list.push_back("version.dll");
  197. list.push_back("shfolder.dll");
  198. list.push_back("IPHLPAPI.dll");
  199. list.push_back("MSIMG32.dll");
  200. if (arg1 == 2)
  201. {
  202. reg->setValue("ExcludeFromKnownDlls", list);
  203. }
  204. else
  205. {
  206. reg->remove("ExcludeFromKnownDlls");
  207. }
  208. delete reg;
  209. }
  210. }
  211. void DialogPreferences::on_cBox_EnAutoRun_stateChanged(int arg1)
  212. {
  213. if (arg1 == 2)
  214. {
  215. setProcessAutoRun(QApplication::applicationFilePath(), 1);
  216. }
  217. else
  218. {
  219. setProcessAutoRun(QApplication::applicationFilePath(), 0);
  220. }
  221. }