MainForm.cs 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using Microsoft.Win32;
  11. using System.IO;
  12. using System.Threading;
  13. using System.Reflection;
  14. using System.Diagnostics;
  15. using System.Collections.Specialized;
  16. using System.Text.RegularExpressions;
  17. using System.Net;
  18. using Newtonsoft.Json;
  19. namespace Optimizer
  20. {
  21. public partial class MainForm : Form
  22. {
  23. ListViewColumnSorter _columnSorter;
  24. List<StartupItem> _startUpItems = new List<StartupItem>();
  25. List<string> _hostsEntries = new List<string>();
  26. List<string> _customCommands = new List<string>();
  27. List<string> _desktopItems = new List<string>();
  28. List<string> _modernApps = new List<string>();
  29. DesktopItemType _desktopItemType = DesktopItemType.Program;
  30. DesktopTypePosition _desktopItemPosition = DesktopTypePosition.Top;
  31. readonly string _latestVersionLink = "https://raw.githubusercontent.com/hellzerg/optimizer/master/version.txt";
  32. readonly string _changelogLink = "https://github.com/hellzerg/optimizer/blob/master/CHANGELOG.md";
  33. readonly string _noNewVersionMessage = "You already have the latest version!";
  34. readonly string _betaVersionMessage = "You are using an experimental version!";
  35. readonly string _blockedIP = "0.0.0.0";
  36. readonly string _restartMessage = "Restart to apply changes?";
  37. readonly string _removeStartupItemsMessage = "Are you sure you want to delete all startup items?";
  38. readonly string _removeHostsEntriesMessage = "Are you sure you want to delete all hosts entries?";
  39. readonly string _removeDesktopItemsMessage = "Are you sure you want to delete all desktop items?";
  40. readonly string _removeModernAppsMessage = "Are you sure you want to uninstall the following app(s)?";
  41. readonly string _errorModernAppsMessage = "The following app(s) couldn't be uninstalled:\n";
  42. readonly string _resetMessage = "Are you sure you want to reset configuration?\n\nThis will reset all your preferences, including any icons you extracted or downloaded using Integrator, but will not touch anything on your computer!";
  43. private string NewVersionMessage(string latestVersion)
  44. {
  45. return string.Format("There is a new version available!\n\nLatest version: {0}\nCurrent version: {1}\n\nDo you want to download it now?", latestVersion, Program.GetCurrentVersionTostring());
  46. }
  47. private string NewDownloadLink(string latestVersion)
  48. {
  49. return string.Format("https://github.com/hellzerg/optimizer/releases/download/{0}/Optimizer-{0}.exe", latestVersion);
  50. }
  51. private void CheckForUpdate()
  52. {
  53. WebClient client = new WebClient
  54. {
  55. Encoding = Encoding.UTF8
  56. };
  57. string latestVersion = string.Empty;
  58. try
  59. {
  60. latestVersion = client.DownloadString(_latestVersionLink);
  61. }
  62. catch (Exception ex)
  63. {
  64. MessageBox.Show(ex.Message, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
  65. }
  66. if (!string.IsNullOrEmpty(latestVersion))
  67. {
  68. if (float.Parse(latestVersion) > Program.GetCurrentVersion())
  69. {
  70. if (MessageBox.Show(NewVersionMessage(latestVersion), "Update available", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  71. {
  72. // PATCHING PROCESS
  73. try
  74. {
  75. Assembly currentAssembly = Assembly.GetEntryAssembly();
  76. if (currentAssembly == null)
  77. {
  78. currentAssembly = Assembly.GetCallingAssembly();
  79. }
  80. string appFolder = Path.GetDirectoryName(currentAssembly.Location);
  81. string appName = Path.GetFileNameWithoutExtension(currentAssembly.Location);
  82. string appExtension = Path.GetExtension(currentAssembly.Location);
  83. string archiveFile = Path.Combine(appFolder, appName + "_old" + appExtension);
  84. string appFile = Path.Combine(appFolder, appName + appExtension);
  85. string tempFile = Path.Combine(appFolder, appName + "_tmp" + appExtension);
  86. // DOWNLOAD NEW VERSION
  87. client.DownloadFile(NewDownloadLink(latestVersion), tempFile);
  88. // DELETE PREVIOUS BACK-UP
  89. if (File.Exists(archiveFile))
  90. {
  91. File.Delete(archiveFile);
  92. }
  93. // MAKE BACK-UP
  94. File.Move(appFile, archiveFile);
  95. // PATCH
  96. File.Move(tempFile, appFile);
  97. Application.Restart();
  98. }
  99. catch (Exception ex)
  100. {
  101. MessageBox.Show(ex.Message);
  102. }
  103. }
  104. }
  105. else if (float.Parse(latestVersion) == Program.GetCurrentVersion())
  106. {
  107. MessageBox.Show(_noNewVersionMessage, "No update available", MessageBoxButtons.OK, MessageBoxIcon.Information);
  108. }
  109. else
  110. {
  111. MessageBox.Show(_betaVersionMessage, "No update available", MessageBoxButtons.OK, MessageBoxIcon.Information);
  112. }
  113. }
  114. }
  115. private void EnableToggleEvents()
  116. {
  117. toggleSwitch12.Click += new EventHandler(toggleSwitch12_Click);
  118. toggleSwitch11.Click += new EventHandler(toggleSwitch11_Click);
  119. toggleSwitch10.Click += new EventHandler(toggleSwitch10_Click);
  120. toggleSwitch9.Click += new EventHandler(toggleSwitch9_Click);
  121. toggleSwitch8.Click += new EventHandler(toggleSwitch8_Click);
  122. toggleSwitch7.Click += new EventHandler(toggleSwitch7_Click);
  123. toggleSwitch6.Click += new EventHandler(toggleSwitch6_Click);
  124. toggleSwitch5.Click += new EventHandler(toggleSwitch5_Click);
  125. toggleSwitch4.Click += new EventHandler(toggleSwitch4_Click);
  126. toggleSwitch1.Click += new EventHandler(toggleSwitch1_Click);
  127. toggleSwitch3.Click += new EventHandler(toggleSwitch3_Click);
  128. toggleSwitch2.Click += new EventHandler(toggleSwitch2_Click);
  129. toggleSwitch27.Click += new EventHandler(toggleSwitch27_Click);
  130. toggleSwitch28.Click += new EventHandler(toggleSwitch28_Click);
  131. toggleSwitch29.Click += new EventHandler(toggleSwitch29_Click);
  132. toggleSwitch30.Click += new EventHandler(toggleSwitch30_Click);
  133. toggleSwitch22.Click += new EventHandler(toggleSwitch22_Click);
  134. toggleSwitch20.Click += new EventHandler(toggleSwitch20_Click);
  135. toggleSwitch21.Click += new EventHandler(toggleSwitch21_Click);
  136. toggleSwitch23.Click += new EventHandler(toggleSwitch23_Click);
  137. toggleSwitch24.Click += new EventHandler(toggleSwitch24_Click);
  138. toggleSwitch25.Click += new EventHandler(toggleSwitch25_Click);
  139. toggleSwitch26.Click += new EventHandler(toggleSwitch26_Click);
  140. toggleSwitch17.Click += new EventHandler(toggleSwitch17_Click);
  141. toggleSwitch16.Click += new EventHandler(toggleSwitch16_Click);
  142. toggleSwitch15.Click += new EventHandler(toggleSwitch15_Click);
  143. toggleSwitch14.Click += new EventHandler(toggleSwitch14_Click);
  144. toggleSwitch13.Click += new EventHandler(toggleSwitch13_Click);
  145. toggleSwitch31.Click += new EventHandler(toggleSwitch31_Click);
  146. toggleSwitch18.Click += new EventHandler(toggleSwitch18_Click);
  147. toggleSwitch19.Click += new EventHandler(toggleSwitch19_Click);
  148. toggleSwitch32.Click += new EventHandler(toggleSwitch32_Click);
  149. toggleSwitch33.Click += new EventHandler(ToggleSwitch33_Click);
  150. toggleSwitch34.Click += new EventHandler(ToggleSwitch34_Click);
  151. toggleSwitch35.Click += new EventHandler(ToggleSwitch35_Click);
  152. toggleSwitch36.Click += new EventHandler(ToggleSwitch36_Click);
  153. toggleSwitch37.Click += new EventHandler(ToggleSwitch37_Click);
  154. }
  155. private void ToggleSwitch37_Click(object sender, EventArgs e)
  156. {
  157. if (!toggleSwitch37.Checked)
  158. {
  159. Optimize.DisableCloudClipboard();
  160. }
  161. else
  162. {
  163. Optimize.EnableCloudClipboard();
  164. }
  165. Options.CurrentOptions.DisableCloudClipboard = !toggleSwitch37.Checked;
  166. }
  167. private void ToggleSwitch36_Click(object sender, EventArgs e)
  168. {
  169. if (!toggleSwitch36.Checked)
  170. {
  171. Optimize.DisableSmartScreen();
  172. }
  173. else
  174. {
  175. Optimize.EnableSmartScreen();
  176. }
  177. Options.CurrentOptions.DisableSmartScreen = !toggleSwitch36.Checked;
  178. }
  179. private void ToggleSwitch35_Click(object sender, EventArgs e)
  180. {
  181. if (!toggleSwitch35.Checked)
  182. {
  183. Optimize.DisableForcedFeatureUpdates();
  184. }
  185. else
  186. {
  187. Optimize.EnableForcedFeatureUpdates();
  188. }
  189. Options.CurrentOptions.DisableFeatureUpdates = !toggleSwitch35.Checked;
  190. }
  191. private void ToggleSwitch34_Click(object sender, EventArgs e)
  192. {
  193. if (!toggleSwitch34.Checked)
  194. {
  195. Optimize.DisableInsiderService();
  196. }
  197. else
  198. {
  199. Optimize.EnableInsiderService();
  200. }
  201. Options.CurrentOptions.DisableInsiderService = !toggleSwitch34.Checked;
  202. }
  203. private void ToggleSwitch33_Click(object sender, EventArgs e)
  204. {
  205. if (!toggleSwitch33.Checked)
  206. {
  207. Optimize.DisableFaxService();
  208. }
  209. else
  210. {
  211. Optimize.EnableFaxService();
  212. }
  213. Options.CurrentOptions.DisableFaxService = !toggleSwitch33.Checked;
  214. }
  215. private void LoadSettings()
  216. {
  217. switch (Options.CurrentOptions.Color)
  218. {
  219. case Theme.Caramel:
  220. radioCaramel.Checked = true;
  221. break;
  222. case Theme.Lime:
  223. radioLime.Checked = true;
  224. break;
  225. case Theme.Magma:
  226. radioMagma.Checked = true;
  227. break;
  228. case Theme.Minimal:
  229. radioMinimal.Checked = true;
  230. break;
  231. case Theme.Ocean:
  232. radioOcean.Checked = true;
  233. break;
  234. case Theme.Zerg:
  235. radioZerg.Checked = true;
  236. break;
  237. }
  238. }
  239. public MainForm()
  240. {
  241. InitializeComponent();
  242. EnableToggleEvents();
  243. CheckForIllegalCrossThreadCalls = false;
  244. Options.ApplyTheme(this);
  245. ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
  246. if (Utilities.CurrentWindowsVersion == WindowsVersion.Unsupported)
  247. {
  248. tabCollection.TabPages.Remove(universalTab);
  249. tabCollection.TabPages.Remove(windowsVIIITab);
  250. tabCollection.TabPages.Remove(windowsXTab);
  251. tabCollection.TabPages.Remove(modernAppsTab);
  252. }
  253. if (Utilities.CurrentWindowsVersion == WindowsVersion.Windows7)
  254. {
  255. LoadUniversalToggleStates();
  256. tabCollection.TabPages.Remove(windowsVIIITab);
  257. tabCollection.TabPages.Remove(windowsXTab);
  258. tabCollection.TabPages.Remove(modernAppsTab);
  259. }
  260. if (Utilities.CurrentWindowsVersion == WindowsVersion.Windows8)
  261. {
  262. LoadUniversalToggleStates();
  263. LoadWindowsVIIIToggleStates();
  264. tabCollection.TabPages.Remove(windowsXTab);
  265. GetModernApps();
  266. }
  267. if (Utilities.CurrentWindowsVersion == WindowsVersion.Windows10)
  268. {
  269. LoadUniversalToggleStates();
  270. LoadWindowsXToggleStates();
  271. tabCollection.TabPages.Remove(windowsVIIITab);
  272. GetModernApps();
  273. }
  274. _columnSorter = new ListViewColumnSorter();
  275. listStartupItems.ListViewItemSorter = _columnSorter;
  276. integratorTimer.Start();
  277. runDialogTime.Start();
  278. GetStartupItems();
  279. GetHostsEntries();
  280. GetDesktopItems();
  281. GetCustomCommands();
  282. LoadSettings();
  283. radioProgram.Checked = true;
  284. radioTop.Checked = true;
  285. txtVersion.Text = "Version: " + Program.GetCurrentVersionTostring();
  286. Program.MainForm = this;
  287. txtOS.Text = "Microsoft " + Utilities.GetOS();
  288. txtBitness.Text = Utilities.GetBitness();
  289. }
  290. private void CleanPC()
  291. {
  292. try
  293. {
  294. if (checkTemp.Checked)
  295. {
  296. CleanHelper.CleanTemporaries();
  297. }
  298. if (checkUTorrent.Checked)
  299. {
  300. CleanHelper.CleanUTorrent();
  301. }
  302. if (checkFileZilla.Checked)
  303. {
  304. CleanHelper.CleanFileZilla();
  305. }
  306. if (checkMiniDumps.Checked)
  307. {
  308. CleanHelper.CleanMiniDumps();
  309. }
  310. if (checkPrefetch.Checked)
  311. {
  312. CleanHelper.CleanPrefetch();
  313. }
  314. if (checkMediaCache.Checked)
  315. {
  316. CleanHelper.CleanMediaPlayersCache();
  317. }
  318. if (checkLogs.Checked)
  319. {
  320. CleanHelper.CleanLogs();
  321. }
  322. if (checkErrorReports.Checked)
  323. {
  324. CleanHelper.CleanErrorReports();
  325. }
  326. if (checkBin.Checked)
  327. {
  328. CleanHelper.EmptyRecycleBin();
  329. }
  330. }
  331. catch { }
  332. finally
  333. {
  334. CleaningAnimation(false);
  335. }
  336. }
  337. private void CleaningAnimation(bool start)
  338. {
  339. if (start)
  340. {
  341. Utilities.SetControlPropertyThreadSafe(cleaningpanel, "Visible", true);
  342. Utilities.SetControlPropertyThreadSafe(progress2, "Visible", true);
  343. Utilities.SetControlPropertyThreadSafe(progress2, "Style", ProgressBarStyle.Marquee);
  344. Utilities.SetControlPropertyThreadSafe(progress2, "MarqueeAnimationSpeed", 1);
  345. Utilities.SetControlPropertyThreadSafe(label4, "Visible", true);
  346. Utilities.SetControlPropertyThreadSafe(button20, "Enabled", false);
  347. Utilities.SetControlPropertyThreadSafe(panel1, "Enabled", false);
  348. }
  349. else
  350. {
  351. Utilities.SetControlPropertyThreadSafe(cleaningpanel, "Visible", false);
  352. Utilities.SetControlPropertyThreadSafe(progress2, "Visible", false);
  353. Utilities.SetControlPropertyThreadSafe(progress2, "Value", 0);
  354. Utilities.SetControlPropertyThreadSafe(progress2, "Style", ProgressBarStyle.Blocks);
  355. Utilities.SetControlPropertyThreadSafe(progress2, "MarqueeAnimationSpeed", 1);
  356. Utilities.SetControlPropertyThreadSafe(label4, "Visible", false);
  357. Utilities.SetControlPropertyThreadSafe(button20, "Enabled", true);
  358. Utilities.SetControlPropertyThreadSafe(panel1, "Enabled", true);
  359. }
  360. }
  361. private bool FixRegistry()
  362. {
  363. bool changeDetected = false;
  364. try
  365. {
  366. if (checkFirewall.Checked)
  367. {
  368. Utilities.EnableFirewall();
  369. changeDetected = true;
  370. }
  371. if (checkCommandPrompt.Checked)
  372. {
  373. Utilities.EnableCommandPrompt();
  374. changeDetected = true;
  375. }
  376. if (checkControlPanel.Checked)
  377. {
  378. Utilities.EnableControlPanel();
  379. changeDetected = true;
  380. }
  381. if (checkFolderOptions.Checked)
  382. {
  383. Utilities.EnableFolderOptions();
  384. changeDetected = true;
  385. }
  386. if (checkRunDialog.Checked)
  387. {
  388. Utilities.EnableRunDialog();
  389. changeDetected = true;
  390. }
  391. if (checkContextMenu.Checked)
  392. {
  393. Utilities.EnableContextMenu();
  394. changeDetected = true;
  395. }
  396. if (checkTaskManager.Checked)
  397. {
  398. Utilities.EnableTaskManager();
  399. changeDetected = true;
  400. }
  401. if (checkRegistryEditor.Checked)
  402. {
  403. Utilities.EnableRegistryEditor();
  404. changeDetected = true;
  405. }
  406. }
  407. catch { }
  408. return changeDetected;
  409. }
  410. private void LoadUniversalToggleStates()
  411. {
  412. toggleSwitch1.Checked = Options.CurrentOptions.EnablePerformanceTweaks;
  413. toggleSwitch2.Checked = Options.CurrentOptions.DisableNetworkThrottling;
  414. toggleSwitch3.Checked = Options.CurrentOptions.DisableWindowsDefender;
  415. toggleSwitch4.Checked = Options.CurrentOptions.DisableSystemRestore;
  416. toggleSwitch5.Checked = Options.CurrentOptions.DisablePrintService;
  417. toggleSwitch6.Checked = Options.CurrentOptions.DisableMediaPlayerSharing;
  418. toggleSwitch7.Checked = Options.CurrentOptions.BlockSkypeAds;
  419. toggleSwitch8.Checked = Options.CurrentOptions.DisableErrorReporting;
  420. toggleSwitch9.Checked = Options.CurrentOptions.DisableHomeGroup;
  421. toggleSwitch10.Checked = Options.CurrentOptions.DisableSuperfetch;
  422. toggleSwitch11.Checked = Options.CurrentOptions.DisableTelemetryTasks;
  423. toggleSwitch12.Checked = Options.CurrentOptions.DisableOffice2016Telemetry;
  424. toggleSwitch32.Checked = Options.CurrentOptions.DisableCompatibilityAssistant;
  425. toggleSwitch33.Checked = Options.CurrentOptions.DisableFaxService;
  426. toggleSwitch36.Checked = Options.CurrentOptions.DisableSmartScreen;
  427. }
  428. private void LoadWindowsVIIIToggleStates()
  429. {
  430. toggleSwitch31.Checked = Options.CurrentOptions.DisableOneDrive;
  431. }
  432. private void LoadWindowsXToggleStates()
  433. {
  434. toggleSwitch13.Checked = Options.CurrentOptions.EnableLegacyVolumeSlider;
  435. toggleSwitch14.Checked = Options.CurrentOptions.UninstallOneDrive;
  436. toggleSwitch15.Checked = Options.CurrentOptions.DisableGameBar;
  437. toggleSwitch16.Checked = Options.CurrentOptions.DisableCortana;
  438. toggleSwitch17.Checked = Options.CurrentOptions.DisableXboxLive;
  439. toggleSwitch18.Checked = Options.CurrentOptions.DisableQuickAccessHistory;
  440. toggleSwitch19.Checked = Options.CurrentOptions.EnableTaskbarColor;
  441. toggleSwitch20.Checked = Options.CurrentOptions.DisableSensorServices;
  442. toggleSwitch21.Checked = Options.CurrentOptions.DisablePrivacyOptions;
  443. toggleSwitch22.Checked = Options.CurrentOptions.DisableSilentAppInstall;
  444. toggleSwitch23.Checked = Options.CurrentOptions.DisableTelemetryServices;
  445. toggleSwitch24.Checked = Options.CurrentOptions.DisableAutomaticUpdates;
  446. toggleSwitch25.Checked = Options.CurrentOptions.DisableMyPeople;
  447. toggleSwitch26.Checked = Options.CurrentOptions.DisableStartMenuAds;
  448. toggleSwitch27.Checked = Options.CurrentOptions.EnableDarkTheme;
  449. toggleSwitch28.Checked = Options.CurrentOptions.DisableSpellingTyping;
  450. toggleSwitch29.Checked = Options.CurrentOptions.DisableWindowsInk;
  451. toggleSwitch30.Checked = Options.CurrentOptions.ExcludeDrivers;
  452. toggleSwitch34.Checked = Options.CurrentOptions.DisableInsiderService;
  453. toggleSwitch35.Checked = Options.CurrentOptions.DisableFeatureUpdates;
  454. toggleSwitch37.Checked = Options.CurrentOptions.DisableCloudClipboard;
  455. }
  456. private void Main_Load(object sender, EventArgs e)
  457. {
  458. }
  459. private void GetDesktopItems()
  460. {
  461. _desktopItems = Integrator.GetDesktopItems();
  462. listDesktopItems.Items.Clear();
  463. for (int i = 0; i < _desktopItems.Count; i++)
  464. {
  465. if (!string.IsNullOrEmpty(_desktopItems[i]))
  466. {
  467. listDesktopItems.Items.Add(_desktopItems[i]);
  468. }
  469. }
  470. }
  471. private void GetHostsEntries()
  472. {
  473. _hostsEntries = HostsHelper.GetHostsEntries();
  474. listHostEntries.Items.Clear();
  475. for (int i = 0; i < _hostsEntries.Count; i++)
  476. {
  477. if (!string.IsNullOrEmpty(_hostsEntries[i]))
  478. {
  479. listHostEntries.Items.Add(_hostsEntries[i]);
  480. }
  481. }
  482. chkReadOnly.Checked = HostsHelper.GetReadOnly();
  483. button47.Enabled = !chkReadOnly.Checked;
  484. button46.Enabled = !chkReadOnly.Checked;
  485. button42.Enabled = !chkReadOnly.Checked;
  486. button41.Enabled = !chkReadOnly.Checked;
  487. linkLabel4.Enabled = !chkReadOnly.Checked;
  488. chkBlock.Enabled = !chkReadOnly.Checked;
  489. txtDomain.Enabled = !chkReadOnly.Checked;
  490. txtIP.Enabled = !chkReadOnly.Checked;
  491. }
  492. private void GetStartupItems()
  493. {
  494. _startUpItems = Utilities.GetStartupItems();
  495. listStartupItems.Items.Clear();
  496. for (int i = 0; i < _startUpItems.Count; i++)
  497. {
  498. ListViewItem list = new ListViewItem(_startUpItems[i].Name);
  499. list.SubItems.Add(_startUpItems[i].FileLocation);
  500. list.SubItems.Add(_startUpItems[i].ToString());
  501. listStartupItems.Items.Add(list);
  502. }
  503. }
  504. private void GetModernApps()
  505. {
  506. button74.Enabled = false;
  507. button75.Enabled = false;
  508. listModernApps.Enabled = false;
  509. listModernApps.Items.Clear();
  510. _modernApps = Utilities.GetModernApps();
  511. foreach (string x in _modernApps)
  512. {
  513. listModernApps.Items.Add(x);
  514. }
  515. button74.Enabled = true;
  516. button75.Enabled = true;
  517. listModernApps.Enabled = true;
  518. }
  519. private async void UninstallModernApps()
  520. {
  521. string selectedApps = string.Empty;
  522. if (listModernApps.CheckedItems.Count > 0)
  523. {
  524. foreach (string x in listModernApps.CheckedItems)
  525. {
  526. if (string.IsNullOrEmpty(selectedApps))
  527. {
  528. selectedApps = x;
  529. }
  530. else
  531. {
  532. selectedApps += Environment.NewLine + x;
  533. }
  534. }
  535. if (MessageBox.Show(_removeModernAppsMessage + "\n\n" + selectedApps, "Optimizer", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  536. {
  537. button74.Enabled = false;
  538. button75.Enabled = false;
  539. listModernApps.Enabled = false;
  540. bool errorOccured = false;
  541. string failedApps = string.Empty;
  542. foreach (string app in listModernApps.CheckedItems)
  543. {
  544. await Task.Run(() => errorOccured = Utilities.UninstallModernApp(app));
  545. if (errorOccured)
  546. {
  547. failedApps += Environment.NewLine + app;
  548. }
  549. }
  550. if (!string.IsNullOrEmpty(failedApps))
  551. {
  552. MessageBox.Show(_errorModernAppsMessage + failedApps, "Optimizer", MessageBoxButtons.OK, MessageBoxIcon.Information);
  553. }
  554. GetModernApps();
  555. }
  556. }
  557. }
  558. private void GetCustomCommands()
  559. {
  560. _customCommands = Integrator.GetCustomCommands();
  561. listCustomCommands.Items.Clear();
  562. foreach (string s in _customCommands)
  563. {
  564. listCustomCommands.Items.Add(s);
  565. }
  566. }
  567. private void Main_FormClosing(object sender, EventArgs e)
  568. {
  569. Options.SaveSettings();
  570. }
  571. private void button39_Click(object sender, EventArgs e)
  572. {
  573. HelperForm f = new HelperForm(this, MessageType.Restart, _restartMessage);
  574. f.ShowDialog();
  575. }
  576. private void button43_Click(object sender, EventArgs e)
  577. {
  578. HelperForm f = new HelperForm(this, MessageType.Restart, _restartMessage);
  579. f.ShowDialog();
  580. }
  581. private void button44_Click(object sender, EventArgs e)
  582. {
  583. HelperForm f = new HelperForm(this, MessageType.Restart, _restartMessage);
  584. f.ShowDialog();
  585. }
  586. private void button45_Click(object sender, EventArgs e)
  587. {
  588. HelperForm f = new HelperForm(this, MessageType.Restart, _restartMessage);
  589. f.ShowDialog();
  590. }
  591. private void button18_Click(object sender, EventArgs e)
  592. {
  593. EdgeForm f = new EdgeForm();
  594. f.ShowDialog();
  595. }
  596. private void checkSelectAll_CheckedChanged(object sender, EventArgs e)
  597. {
  598. checkTemp.Checked = checkSelectAll.Checked;
  599. checkUTorrent.Checked = checkSelectAll.Checked;
  600. checkFileZilla.Checked = checkSelectAll.Checked;
  601. checkMiniDumps.Checked = checkSelectAll.Checked;
  602. checkPrefetch.Checked = checkSelectAll.Checked;
  603. checkMediaCache.Checked = checkSelectAll.Checked;
  604. checkLogs.Checked = checkSelectAll.Checked;
  605. checkBin.Checked = checkSelectAll.Checked;
  606. checkErrorReports.Checked = checkSelectAll.Checked;
  607. }
  608. private void button20_Click(object sender, EventArgs e)
  609. {
  610. CleaningAnimation(true);
  611. Task t = new Task(() => CleanPC());
  612. t.Start();
  613. }
  614. private void button32_Click(object sender, EventArgs e)
  615. {
  616. if (listStartupItems.SelectedItems.Count == 1)
  617. {
  618. _startUpItems[listStartupItems.SelectedIndices[0]].Remove();
  619. GetStartupItems();
  620. }
  621. }
  622. internal void RemoveAllStartupItems()
  623. {
  624. foreach (ListViewItem i in listStartupItems.Items)
  625. {
  626. _startUpItems[i.Index].Remove();
  627. }
  628. GetStartupItems();
  629. }
  630. private void button22_Click(object sender, EventArgs e)
  631. {
  632. if (listStartupItems.Items.Count > 0)
  633. {
  634. HelperForm r = new HelperForm(this, MessageType.Startup, _removeStartupItemsMessage);
  635. r.ShowDialog(this);
  636. }
  637. }
  638. private void button31_Click(object sender, EventArgs e)
  639. {
  640. if (listStartupItems.SelectedItems.Count == 1)
  641. {
  642. _startUpItems[listStartupItems.SelectedIndices[0]].LocateFile();
  643. }
  644. }
  645. private void checkEnableAll_CheckedChanged(object sender, EventArgs e)
  646. {
  647. checkTaskManager.Checked = checkEnableAll.Checked;
  648. checkCommandPrompt.Checked = checkEnableAll.Checked;
  649. checkControlPanel.Checked = checkEnableAll.Checked;
  650. checkFolderOptions.Checked = checkEnableAll.Checked;
  651. checkRunDialog.Checked = checkEnableAll.Checked;
  652. checkContextMenu.Checked = checkEnableAll.Checked;
  653. checkFirewall.Checked = checkEnableAll.Checked;
  654. checkRegistryEditor.Checked = checkEnableAll.Checked;
  655. }
  656. private void button33_Click(object sender, EventArgs e)
  657. {
  658. bool flag = FixRegistry();
  659. if (flag)
  660. {
  661. panel2.Enabled = false;
  662. button33.Enabled = false;
  663. if (checkRestartExplorer.Checked)
  664. {
  665. Utilities.RestartExplorer();
  666. }
  667. panel2.Enabled = true;
  668. button33.Enabled = true;
  669. }
  670. }
  671. private void pictureBox1_Click(object sender, EventArgs e)
  672. {
  673. AboutForm f = new AboutForm();
  674. f.ShowDialog(this);
  675. }
  676. private void button37_Click(object sender, EventArgs e)
  677. {
  678. GetStartupItems();
  679. }
  680. private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  681. {
  682. HostsHelper.LocateHosts();
  683. }
  684. private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  685. {
  686. HostsEditorForm f = new HostsEditorForm();
  687. f.ShowDialog(this);
  688. GetHostsEntries();
  689. }
  690. private void linkLabel4_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  691. {
  692. HostsHelper.RestoreDefaultHosts();
  693. GetHostsEntries();
  694. }
  695. private void button47_Click(object sender, EventArgs e)
  696. {
  697. if ((txtIP.Text != string.Empty) && (txtDomain.Text != string.Empty))
  698. {
  699. string ip = txtIP.Text.Trim();
  700. string domain = txtDomain.Text.Trim();
  701. string recommendedDomain = string.Empty;
  702. if (!domain.StartsWith("www."))
  703. {
  704. recommendedDomain = "www." + domain;
  705. }
  706. else
  707. {
  708. recommendedDomain = domain.Replace("www.", string.Empty);
  709. }
  710. HostsHelper.AddEntry(HostsHelper.SanitizeEntry(ip) + " " + HostsHelper.SanitizeEntry(domain));
  711. if (!string.IsNullOrEmpty(recommendedDomain))
  712. {
  713. HostsHelper.AddEntry(HostsHelper.SanitizeEntry(ip) + " " + HostsHelper.SanitizeEntry(recommendedDomain));
  714. }
  715. GetHostsEntries();
  716. txtIP.Clear();
  717. txtDomain.Clear();
  718. chkBlock.Checked = false;
  719. }
  720. }
  721. private void button41_Click(object sender, EventArgs e)
  722. {
  723. GetHostsEntries();
  724. }
  725. private void button42_Click(object sender, EventArgs e)
  726. {
  727. if (listHostEntries.SelectedItems.Count == 1)
  728. {
  729. HostsHelper.RemoveEntry(listHostEntries.SelectedItem.ToString().Replace(" : ", " "));
  730. GetHostsEntries();
  731. }
  732. }
  733. private void button46_Click(object sender, EventArgs e)
  734. {
  735. if (listHostEntries.Items.Count > 0)
  736. {
  737. HelperForm r = new HelperForm(this, MessageType.Hosts, _removeHostsEntriesMessage);
  738. r.ShowDialog(this);
  739. }
  740. }
  741. internal void RemoveAllHostsEntries()
  742. {
  743. List<string> collection = new List<string>();
  744. foreach (string item in listHostEntries.Items)
  745. {
  746. collection.Add(item.Replace(" : ", " "));
  747. }
  748. HostsHelper.RemoveAllEntries(collection);
  749. GetHostsEntries();
  750. }
  751. private void aio_SelectedIndexChanged(object sender, EventArgs e)
  752. {
  753. if (tabCollection.SelectedTab == hostsEditorTab)
  754. {
  755. txtIP.Focus();
  756. }
  757. }
  758. private void button48_Click(object sender, EventArgs e)
  759. {
  760. defineCommandDialog.ShowDialog();
  761. }
  762. private void button50_Click(object sender, EventArgs e)
  763. {
  764. if ((txtRunFile.Text != string.Empty) && (txtRunKeyword.Text != string.Empty))
  765. {
  766. Integrator.CreateCustomCommand(txtRunFile.Text, txtRunKeyword.Text);
  767. txtRunFile.Clear();
  768. txtRunKeyword.Clear();
  769. GetCustomCommands();
  770. }
  771. }
  772. private void DefineCmd_FileOk(object sender, CancelEventArgs e)
  773. {
  774. txtRunFile.Text = defineCommandDialog.FileName;
  775. txtRunKeyword.Text = Path.GetFileNameWithoutExtension(txtRunFile.Text).ToLower();
  776. }
  777. private void button58_Click(object sender, EventArgs e)
  778. {
  779. InfoForm r = new InfoForm(Integrator.powerinfo);
  780. r.ShowDialog(this);
  781. }
  782. private void button56_Click(object sender, EventArgs e)
  783. {
  784. InfoForm r = new InfoForm(Integrator.systemtoolsinfo);
  785. r.ShowDialog(this);
  786. }
  787. private void button52_Click(object sender, EventArgs e)
  788. {
  789. InfoForm r = new InfoForm(Integrator.windowsappsinfo);
  790. r.ShowDialog(this);
  791. }
  792. private void button49_Click(object sender, EventArgs e)
  793. {
  794. InfoForm r = new InfoForm(Integrator.systemshortcutsinfo);
  795. r.ShowDialog(this);
  796. }
  797. private void button55_Click(object sender, EventArgs e)
  798. {
  799. InfoForm r = new InfoForm(Integrator.desktopshortcutsinfo);
  800. r.ShowDialog(this);
  801. }
  802. private void button59_Click(object sender, EventArgs e)
  803. {
  804. Utilities.ImportRegistryScript(Required.ReadyMadeMenusFolder + "\\PowerMenu.reg");
  805. GetDesktopItems();
  806. }
  807. private void button53_Click(object sender, EventArgs e)
  808. {
  809. Utilities.ImportRegistryScript(Required.ReadyMadeMenusFolder + "\\SystemTools.reg");
  810. GetDesktopItems();
  811. }
  812. private void button54_Click(object sender, EventArgs e)
  813. {
  814. Utilities.ImportRegistryScript(Required.ReadyMadeMenusFolder + "\\WindowsApps.reg");
  815. GetDesktopItems();
  816. }
  817. private void button51_Click(object sender, EventArgs e)
  818. {
  819. Utilities.ImportRegistryScript(Required.ReadyMadeMenusFolder + "\\SystemShortcuts.reg");
  820. GetDesktopItems();
  821. }
  822. private void button57_Click(object sender, EventArgs e)
  823. {
  824. Utilities.ImportRegistryScript(Required.ReadyMadeMenusFolder + "\\DesktopShortcuts.reg");
  825. GetDesktopItems();
  826. }
  827. private void button60_Click(object sender, EventArgs e)
  828. {
  829. GetDesktopItems();
  830. }
  831. private void button61_Click(object sender, EventArgs e)
  832. {
  833. if (listDesktopItems.SelectedItems.Count == 1)
  834. {
  835. Integrator.RemoveItem(listDesktopItems.SelectedItem.ToString());
  836. GetDesktopItems();
  837. }
  838. }
  839. internal void RemoveAllDesktopItems()
  840. {
  841. List<string> collection = new List<string>();
  842. foreach (string item in listDesktopItems.Items)
  843. {
  844. collection.Add(item);
  845. }
  846. Integrator.RemoveAllItems(collection);
  847. GetDesktopItems();
  848. }
  849. private void button62_Click(object sender, EventArgs e)
  850. {
  851. if (listDesktopItems.Items.Count > 0)
  852. {
  853. HelperForm r = new HelperForm(this, MessageType.Integrator, _removeDesktopItemsMessage);
  854. r.ShowDialog(this);
  855. }
  856. }
  857. private void radioProgram_CheckedChanged(object sender, EventArgs e)
  858. {
  859. if (radioProgram.Checked)
  860. {
  861. btnBrowseItem.Enabled = true;
  862. txtItem.Clear();
  863. checkDefaultIcon.Checked = true;
  864. txtIcon.Enabled = false;
  865. btnBrowseIcon.Enabled = false;
  866. itemtoaddgroup.Text = "Program to add:";
  867. checkDefaultIcon.Visible = true;
  868. checkDefaultIcon.Text = "Use program's icon";
  869. txtItemName.Clear();
  870. txtItem.ReadOnly = true;
  871. txtIcon.ReadOnly = true;
  872. _desktopItemType = DesktopItemType.Program;
  873. }
  874. }
  875. private void radioFolder_CheckedChanged(object sender, EventArgs e)
  876. {
  877. if (radioFolder.Checked)
  878. {
  879. checkDefaultIcon.Checked = true;
  880. btnBrowseItem.Enabled = true;
  881. txtItem.Clear();
  882. itemtoaddgroup.Text = "Folder to add:";
  883. checkDefaultIcon.Text = "Use default folder icon";
  884. txtItemName.Clear();
  885. txtItem.ReadOnly = true;
  886. txtIcon.ReadOnly = true;
  887. _desktopItemType = DesktopItemType.Folder;
  888. }
  889. }
  890. private void radioLink_CheckedChanged(object sender, EventArgs e)
  891. {
  892. if (radioLink.Checked)
  893. {
  894. checkDefaultIcon.Checked = true;
  895. checkDefaultIcon.Text = "Download website icon (favicon)";
  896. btnBrowseItem.Enabled = false;
  897. itemtoaddgroup.Text = "Web address to add:";
  898. checkDefaultIcon.Visible = true;
  899. txtItem.Text = "http://";
  900. txtItemName.Clear();
  901. txtItem.ReadOnly = false;
  902. txtIcon.ReadOnly = true;
  903. _desktopItemType = DesktopItemType.Link;
  904. }
  905. }
  906. private void radioFile_CheckedChanged(object sender, EventArgs e)
  907. {
  908. if (radioFile.Checked)
  909. {
  910. checkDefaultIcon.Checked = true;
  911. checkDefaultIcon.Text = "No icon";
  912. btnBrowseItem.Enabled = true;
  913. itemtoaddgroup.Text = "File to add:";
  914. checkDefaultIcon.Visible = true;
  915. txtItem.Clear();
  916. txtItemName.Clear();
  917. txtItem.ReadOnly = true;
  918. txtIcon.ReadOnly = true;
  919. _desktopItemType = DesktopItemType.File;
  920. }
  921. }
  922. private void radioCommand_CheckedChanged(object sender, EventArgs e)
  923. {
  924. if (radioCommand.Checked)
  925. {
  926. btnBrowseItem.Enabled = false;
  927. txtItem.Clear();
  928. checkDefaultIcon.Checked = true;
  929. txtIcon.Enabled = false;
  930. btnBrowseIcon.Enabled = false;
  931. itemtoaddgroup.Text = "Command to add:";
  932. checkDefaultIcon.Visible = true;
  933. checkDefaultIcon.Text = "No icon";
  934. txtItemName.Clear();
  935. txtItem.ReadOnly = false;
  936. txtIcon.ReadOnly = true;
  937. _desktopItemType = DesktopItemType.Command;
  938. }
  939. }
  940. private void checkDefaultIcon_CheckedChanged(object sender, EventArgs e)
  941. {
  942. if (checkDefaultIcon.Checked)
  943. {
  944. txtIcon.Clear();
  945. txtIcon.Enabled = false;
  946. btnBrowseIcon.Enabled = false;
  947. }
  948. else
  949. {
  950. txtIcon.Clear();
  951. txtIcon.Enabled = true;
  952. btnBrowseIcon.Enabled = true;
  953. }
  954. }
  955. private void btnBrowseItem_Click(object sender, EventArgs e)
  956. {
  957. switch (_desktopItemType)
  958. {
  959. case DesktopItemType.Program:
  960. defineProgramDialog.ShowDialog();
  961. break;
  962. case DesktopItemType.Folder:
  963. defineFolderDialog.ShowDialog();
  964. txtItem.Text = defineFolderDialog.SelectedPath;
  965. int i = defineFolderDialog.SelectedPath.LastIndexOf("\\");
  966. txtItemName.Text = defineFolderDialog.SelectedPath.Remove(0, i + 1);
  967. break;
  968. case DesktopItemType.File:
  969. defineFileDialog.ShowDialog();
  970. break;
  971. }
  972. }
  973. private void DefineProgramDialog_FileOk(object sender, CancelEventArgs e)
  974. {
  975. txtItem.Text = defineProgramDialog.FileName;
  976. txtItemName.Text = defineProgramDialog.SafeFileName.Replace(".exe", string.Empty);
  977. }
  978. private void DefineFileDialog_FileOk(object sender, CancelEventArgs e)
  979. {
  980. txtItem.Text = defineFileDialog.FileName;
  981. txtItemName.Text = defineFileDialog.SafeFileName;
  982. }
  983. private void btnBrowseIcon_Click(object sender, EventArgs e)
  984. {
  985. switch (_desktopItemType)
  986. {
  987. case DesktopItemType.Program:
  988. DefineProgramIconDialog.ShowDialog();
  989. break;
  990. case DesktopItemType.Folder:
  991. DefineFolderIconDialog.ShowDialog();
  992. break;
  993. case DesktopItemType.Link:
  994. DefineURLIconDialog.ShowDialog();
  995. break;
  996. case DesktopItemType.File:
  997. DefineFileIconDialog.ShowDialog();
  998. break;
  999. case DesktopItemType.Command:
  1000. DefineCommandIconDialog.ShowDialog();
  1001. break;
  1002. }
  1003. }
  1004. private void DefineProgramIconDialog_FileOk(object sender, CancelEventArgs e)
  1005. {
  1006. txtIcon.Text = DefineProgramIconDialog.FileName;
  1007. if (txtIcon.Text.Contains(".exe"))
  1008. {
  1009. string iconpath = Integrator.ExtractIconFromExecutable(txtItemName.Text, DefineProgramIconDialog.FileName);
  1010. txtIcon.Text = iconpath;
  1011. }
  1012. }
  1013. private void DefineFolderIconDialog_FileOk(object sender, CancelEventArgs e)
  1014. {
  1015. txtIcon.Text = DefineFolderIconDialog.FileName;
  1016. if (txtIcon.Text.Contains(".exe"))
  1017. {
  1018. string iconpath = Integrator.ExtractIconFromExecutable(txtItemName.Text, DefineFolderIconDialog.FileName);
  1019. txtIcon.Text = iconpath;
  1020. }
  1021. }
  1022. private void DefineURLIconDialog_FileOk(object sender, CancelEventArgs e)
  1023. {
  1024. txtIcon.Text = DefineURLIconDialog.FileName;
  1025. if (txtIcon.Text.Contains(".exe"))
  1026. {
  1027. string iconpath = Integrator.ExtractIconFromExecutable(txtItemName.Text, DefineURLIconDialog.FileName);
  1028. txtIcon.Text = iconpath;
  1029. }
  1030. }
  1031. private void DefineFileIconDialog_FileOk(object sender, CancelEventArgs e)
  1032. {
  1033. txtIcon.Text = DefineFileIconDialog.FileName;
  1034. if (txtIcon.Text.Contains(".exe"))
  1035. {
  1036. string iconpath = Integrator.ExtractIconFromExecutable(txtItemName.Text, DefineFileIconDialog.FileName);
  1037. txtIcon.Text = iconpath;
  1038. }
  1039. }
  1040. private void DefineCommandIconDialog_FileOk(object sender, CancelEventArgs e)
  1041. {
  1042. txtIcon.Text = DefineCommandIconDialog.FileName;
  1043. if (txtIcon.Text.Contains(".exe"))
  1044. {
  1045. string iconpath = Integrator.ExtractIconFromExecutable(txtItemName.Text, DefineCommandIconDialog.FileName);
  1046. txtIcon.Text = iconpath;
  1047. }
  1048. }
  1049. private void btnAddItem_Click(object sender, EventArgs e)
  1050. {
  1051. string icon = string.Empty;
  1052. switch (_desktopItemType)
  1053. {
  1054. case DesktopItemType.Program:
  1055. if (checkDefaultIcon.Checked)
  1056. {
  1057. icon = txtItem.Text;
  1058. }
  1059. else
  1060. {
  1061. icon = txtIcon.Text;
  1062. }
  1063. Integrator.AddItem(txtItemName.Text, txtItem.Text, icon, _desktopItemPosition, checkShift.Checked, DesktopItemType.Program);
  1064. break;
  1065. case DesktopItemType.Folder:
  1066. if (checkDefaultIcon.Checked)
  1067. {
  1068. icon = Integrator.FolderDefaultIcon;
  1069. }
  1070. else
  1071. {
  1072. icon = txtIcon.Text;
  1073. }
  1074. Integrator.AddItem(txtItemName.Text, txtItem.Text, icon, _desktopItemPosition, checkShift.Checked, DesktopItemType.Folder);
  1075. break;
  1076. case DesktopItemType.Link:
  1077. if (checkDefaultIcon.Checked)
  1078. {
  1079. icon = Integrator.DownloadFavicon(txtItem.Text, txtItemName.Text);
  1080. }
  1081. else
  1082. {
  1083. icon = txtIcon.Text;
  1084. }
  1085. Integrator.AddItem(txtItemName.Text, txtItem.Text, icon, _desktopItemPosition, checkShift.Checked, DesktopItemType.Link);
  1086. break;
  1087. case DesktopItemType.File:
  1088. if (!checkDefaultIcon.Checked)
  1089. {
  1090. icon = txtIcon.Text;
  1091. }
  1092. Integrator.AddItem(txtItemName.Text, txtItem.Text, icon, _desktopItemPosition, checkShift.Checked, DesktopItemType.File);
  1093. break;
  1094. case DesktopItemType.Command:
  1095. if (!checkDefaultIcon.Checked)
  1096. {
  1097. icon = txtIcon.Text;
  1098. }
  1099. Integrator.AddItem(txtItemName.Text, txtItem.Text, icon, _desktopItemPosition, checkShift.Checked, DesktopItemType.Command);
  1100. break;
  1101. }
  1102. GetDesktopItems();
  1103. ResetIntegratorForm();
  1104. }
  1105. private void integratorTimer_Tick(object sender, EventArgs e)
  1106. {
  1107. if ((txtItem.Text != "") && (txtItemName.Text != "") && (txtIcon.Text != "") && (!checkDefaultIcon.Checked))
  1108. {
  1109. btnAddItem.Enabled = true;
  1110. }
  1111. else if ((txtItem.Text != "") && (txtItemName.Text != "") && (checkDefaultIcon.Checked))
  1112. {
  1113. btnAddItem.Enabled = true;
  1114. }
  1115. else
  1116. {
  1117. btnAddItem.Enabled = false;
  1118. }
  1119. }
  1120. private void runDialogTimer_Tick(object sender, EventArgs e)
  1121. {
  1122. if ((txtRunFile.Text != "") && (txtRunKeyword.Text != ""))
  1123. {
  1124. btnCreateCustomCommand.Enabled = true;
  1125. }
  1126. else
  1127. {
  1128. btnCreateCustomCommand.Enabled = false;
  1129. }
  1130. }
  1131. private void radioTop_CheckedChanged(object sender, EventArgs e)
  1132. {
  1133. if (radioTop.Checked)
  1134. {
  1135. _desktopItemPosition = DesktopTypePosition.Top;
  1136. }
  1137. }
  1138. private void radioMiddle_CheckedChanged(object sender, EventArgs e)
  1139. {
  1140. if (radioMiddle.Checked)
  1141. {
  1142. _desktopItemPosition = DesktopTypePosition.Middle;
  1143. }
  1144. }
  1145. private void radioBottom_CheckedChanged(object sender, EventArgs e)
  1146. {
  1147. if (radioBottom.Checked)
  1148. {
  1149. _desktopItemPosition = DesktopTypePosition.Bottom;
  1150. }
  1151. }
  1152. private void ResetIntegratorForm()
  1153. {
  1154. txtItem.Clear();
  1155. txtIcon.Clear();
  1156. checkDefaultIcon.Checked = true;
  1157. txtItemName.Clear();
  1158. if (radioLink.Checked)
  1159. {
  1160. txtItem.Text = "http://";
  1161. }
  1162. }
  1163. private void radioOcean_CheckedChanged(object sender, EventArgs e)
  1164. {
  1165. Options.CurrentOptions.Color = Theme.Ocean;
  1166. Options.ApplyTheme(this);
  1167. }
  1168. private void radioMagma_CheckedChanged(object sender, EventArgs e)
  1169. {
  1170. Options.CurrentOptions.Color = Theme.Magma;
  1171. Options.ApplyTheme(this);
  1172. }
  1173. private void radioZerg_CheckedChanged(object sender, EventArgs e)
  1174. {
  1175. Options.CurrentOptions.Color = Theme.Zerg;
  1176. Options.ApplyTheme(this);
  1177. }
  1178. private void radioMinimal_CheckedChanged(object sender, EventArgs e)
  1179. {
  1180. Options.CurrentOptions.Color = Theme.Minimal;
  1181. Options.ApplyTheme(this);
  1182. }
  1183. private void radioCaramel_CheckedChanged(object sender, EventArgs e)
  1184. {
  1185. Options.CurrentOptions.Color = Theme.Caramel;
  1186. Options.ApplyTheme(this);
  1187. }
  1188. private void radioLime_CheckedChanged(object sender, EventArgs e)
  1189. {
  1190. Options.CurrentOptions.Color = Theme.Lime;
  1191. Options.ApplyTheme(this);
  1192. }
  1193. private void button64_Click(object sender, EventArgs e)
  1194. {
  1195. if (listStartupItems.SelectedItems.Count == 1)
  1196. {
  1197. _startUpItems[listStartupItems.SelectedIndices[0]].LocateKey();
  1198. }
  1199. }
  1200. private void button66_Click(object sender, EventArgs e)
  1201. {
  1202. Integrator.TakeOwnership(false);
  1203. }
  1204. private void button65_Click(object sender, EventArgs e)
  1205. {
  1206. Integrator.TakeOwnership(true);
  1207. }
  1208. private void listStartupItems_ColumnClick(object sender, ColumnClickEventArgs e)
  1209. {
  1210. if (e.Column == _columnSorter.CurrentColumn)
  1211. {
  1212. if (_columnSorter.SortOrder == SortOrder.Ascending)
  1213. {
  1214. _columnSorter.SortOrder = SortOrder.Descending;
  1215. }
  1216. else
  1217. {
  1218. _columnSorter.SortOrder = SortOrder.Ascending;
  1219. }
  1220. }
  1221. else
  1222. {
  1223. _columnSorter.CurrentColumn = e.Column;
  1224. _columnSorter.SortOrder = SortOrder.Ascending;
  1225. }
  1226. listStartupItems.Sort();
  1227. }
  1228. private void chkBlock_CheckedChanged(object sender, EventArgs e)
  1229. {
  1230. if (chkBlock.Checked)
  1231. {
  1232. txtIP.Text = _blockedIP;
  1233. txtIP.Enabled = false;
  1234. }
  1235. else
  1236. {
  1237. txtIP.Clear();
  1238. txtIP.Enabled = true;
  1239. }
  1240. }
  1241. private void button8_Click(object sender, EventArgs e)
  1242. {
  1243. GetCustomCommands();
  1244. }
  1245. private void button26_Click(object sender, EventArgs e)
  1246. {
  1247. if (listCustomCommands.SelectedItems.Count == 1)
  1248. {
  1249. Integrator.DeleteCustomCommand(listCustomCommands.SelectedItem.ToString());
  1250. GetCustomCommands();
  1251. }
  1252. }
  1253. private void button75_Click(object sender, EventArgs e)
  1254. {
  1255. GetModernApps();
  1256. }
  1257. private void button74_Click(object sender, EventArgs e)
  1258. {
  1259. UninstallModernApps();
  1260. }
  1261. private void chkSelectAllModernApps_CheckedChanged(object sender, EventArgs e)
  1262. {
  1263. for (int i = 0; i < listModernApps.Items.Count; i++)
  1264. {
  1265. listModernApps.SetItemChecked(i, chkSelectAllModernApps.Checked);
  1266. }
  1267. }
  1268. private void btnResetConfig_Click(object sender, EventArgs e)
  1269. {
  1270. if (MessageBox.Show(_resetMessage, "Information", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1271. {
  1272. Utilities.ResetConfiguration();
  1273. }
  1274. }
  1275. private void toggleSwitch1_Click(object sender, EventArgs e)
  1276. {
  1277. if (!toggleSwitch1.Checked)
  1278. {
  1279. Optimize.EnablePerformanceTweaks();
  1280. }
  1281. else
  1282. {
  1283. Optimize.DisablePerformanceTweaks();
  1284. }
  1285. Options.CurrentOptions.EnablePerformanceTweaks = !toggleSwitch1.Checked;
  1286. }
  1287. private void toggleSwitch2_Click(object sender, EventArgs e)
  1288. {
  1289. if (!toggleSwitch2.Checked)
  1290. {
  1291. Optimize.DisableNetworkThrottling();
  1292. }
  1293. else
  1294. {
  1295. Optimize.EnableNetworkThrottling();
  1296. }
  1297. Options.CurrentOptions.DisableNetworkThrottling = !toggleSwitch2.Checked;
  1298. }
  1299. private void toggleSwitch3_Click(object sender, EventArgs e)
  1300. {
  1301. if (!toggleSwitch3.Checked)
  1302. {
  1303. Optimize.DisableDefender();
  1304. }
  1305. else
  1306. {
  1307. Optimize.EnableDefender();
  1308. }
  1309. Options.CurrentOptions.DisableWindowsDefender = !toggleSwitch3.Checked;
  1310. }
  1311. private void toggleSwitch4_Click(object sender, EventArgs e)
  1312. {
  1313. if (!toggleSwitch4.Checked)
  1314. {
  1315. Optimize.DisableSystemRestore();
  1316. }
  1317. else
  1318. {
  1319. Optimize.EnableSystemRestore();
  1320. }
  1321. Options.CurrentOptions.DisableSystemRestore = !toggleSwitch4.Checked;
  1322. }
  1323. private void toggleSwitch5_Click(object sender, EventArgs e)
  1324. {
  1325. if (!toggleSwitch5.Checked)
  1326. {
  1327. Optimize.DisablePrintService();
  1328. }
  1329. else
  1330. {
  1331. Optimize.EnablePrintService();
  1332. }
  1333. Options.CurrentOptions.DisablePrintService = !toggleSwitch5.Checked;
  1334. }
  1335. private void toggleSwitch6_Click(object sender, EventArgs e)
  1336. {
  1337. if (!toggleSwitch6.Checked)
  1338. {
  1339. Optimize.DisableMediaPlayerSharing();
  1340. }
  1341. else
  1342. {
  1343. Optimize.EnableMediaPlayerSharing();
  1344. }
  1345. Options.CurrentOptions.DisableMediaPlayerSharing = !toggleSwitch6.Checked;
  1346. }
  1347. private void toggleSwitch7_Click(object sender, EventArgs e)
  1348. {
  1349. if (!toggleSwitch7.Checked)
  1350. {
  1351. Optimize.DisableSkypeAds();
  1352. }
  1353. else
  1354. {
  1355. Optimize.EnableSkypeAds();
  1356. }
  1357. Options.CurrentOptions.BlockSkypeAds = !toggleSwitch7.Checked;
  1358. }
  1359. private void toggleSwitch8_Click(object sender, EventArgs e)
  1360. {
  1361. if (!toggleSwitch8.Checked)
  1362. {
  1363. Optimize.DisableErrorReporting();
  1364. }
  1365. else
  1366. {
  1367. Optimize.EnableErrorReporting();
  1368. }
  1369. Options.CurrentOptions.DisableErrorReporting = !toggleSwitch8.Checked;
  1370. }
  1371. private void toggleSwitch9_Click(object sender, EventArgs e)
  1372. {
  1373. if (!toggleSwitch9.Checked)
  1374. {
  1375. Optimize.DisableHomeGroup();
  1376. }
  1377. else
  1378. {
  1379. Optimize.EnableHomeGroup();
  1380. }
  1381. Options.CurrentOptions.DisableHomeGroup = !toggleSwitch9.Checked;
  1382. }
  1383. private void toggleSwitch10_Click(object sender, EventArgs e)
  1384. {
  1385. if (!toggleSwitch10.Checked)
  1386. {
  1387. Optimize.DisableSuperfetch();
  1388. }
  1389. else
  1390. {
  1391. Optimize.EnableSuperfetch();
  1392. }
  1393. Options.CurrentOptions.DisableSuperfetch = !toggleSwitch10.Checked;
  1394. }
  1395. private void toggleSwitch11_Click(object sender, EventArgs e)
  1396. {
  1397. if (!toggleSwitch11.Checked)
  1398. {
  1399. Optimize.DisableTelemetryTasks();
  1400. }
  1401. else
  1402. {
  1403. Optimize.EnableTelemetryTasks();
  1404. }
  1405. Options.CurrentOptions.DisableTelemetryTasks = !toggleSwitch11.Checked;
  1406. }
  1407. private void toggleSwitch12_Click(object sender, EventArgs e)
  1408. {
  1409. if (!toggleSwitch12.Checked)
  1410. {
  1411. Optimize.DisableOffice2016Telemetry();
  1412. }
  1413. else
  1414. {
  1415. Optimize.EnableOffice2016Telemetry();
  1416. }
  1417. Options.CurrentOptions.DisableOffice2016Telemetry = !toggleSwitch12.Checked;
  1418. }
  1419. private void toggleSwitch13_Click(object sender, EventArgs e)
  1420. {
  1421. if (!toggleSwitch13.Checked)
  1422. {
  1423. Optimize.EnableLegacyVolumeSlider();
  1424. }
  1425. else
  1426. {
  1427. Optimize.DisableLegacyVolumeSlider();
  1428. }
  1429. Options.CurrentOptions.EnableLegacyVolumeSlider = !toggleSwitch13.Checked;
  1430. }
  1431. private void toggleSwitch19_Click(object sender, EventArgs e)
  1432. {
  1433. if (!toggleSwitch19.Checked)
  1434. {
  1435. Optimize.EnableTaskbarColor();
  1436. }
  1437. else
  1438. {
  1439. Optimize.DisableTaskbarColor();
  1440. }
  1441. Options.CurrentOptions.EnableTaskbarColor = !toggleSwitch19.Checked;
  1442. }
  1443. private void toggleSwitch18_Click(object sender, EventArgs e)
  1444. {
  1445. if (!toggleSwitch18.Checked)
  1446. {
  1447. Optimize.DisableQuickAccessHistory();
  1448. }
  1449. else
  1450. {
  1451. Optimize.EnableQuickAccessHistory();
  1452. }
  1453. Options.CurrentOptions.DisableQuickAccessHistory = !toggleSwitch18.Checked;
  1454. }
  1455. private void toggleSwitch26_Click(object sender, EventArgs e)
  1456. {
  1457. if (!toggleSwitch26.Checked)
  1458. {
  1459. Optimize.DisableStartMenuAds();
  1460. }
  1461. else
  1462. {
  1463. Optimize.EnableStartMenuAds();
  1464. }
  1465. Options.CurrentOptions.DisableStartMenuAds = !toggleSwitch26.Checked;
  1466. }
  1467. private void toggleSwitch27_Click(object sender, EventArgs e)
  1468. {
  1469. if (!toggleSwitch27.Checked)
  1470. {
  1471. Optimize.EnableDarkTheme();
  1472. }
  1473. else
  1474. {
  1475. Optimize.EnableLightTheme();
  1476. }
  1477. Options.CurrentOptions.EnableDarkTheme = !toggleSwitch27.Checked;
  1478. }
  1479. private void toggleSwitch14_Click(object sender, EventArgs e)
  1480. {
  1481. if (!toggleSwitch14.Checked)
  1482. {
  1483. Task t = new Task(() => Optimize.UninstallOneDrive());
  1484. t.Start();
  1485. }
  1486. else
  1487. {
  1488. Task t = new Task(() => Optimize.InstallOneDrive());
  1489. t.Start();
  1490. }
  1491. Options.CurrentOptions.UninstallOneDrive = !toggleSwitch14.Checked;
  1492. }
  1493. private void toggleSwitch25_Click(object sender, EventArgs e)
  1494. {
  1495. if (!toggleSwitch25.Checked)
  1496. {
  1497. Optimize.DisableMyPeople();
  1498. }
  1499. else
  1500. {
  1501. Optimize.EnableMyPeople();
  1502. }
  1503. Options.CurrentOptions.DisableMyPeople = !toggleSwitch25.Checked;
  1504. }
  1505. private void toggleSwitch24_Click(object sender, EventArgs e)
  1506. {
  1507. if (!toggleSwitch24.Checked)
  1508. {
  1509. Optimize.DisableAutomaticUpdates();
  1510. }
  1511. else
  1512. {
  1513. Optimize.EnableAutomaticUpdates();
  1514. }
  1515. Options.CurrentOptions.DisableAutomaticUpdates = !toggleSwitch24.Checked;
  1516. }
  1517. private void toggleSwitch30_Click(object sender, EventArgs e)
  1518. {
  1519. if (!toggleSwitch30.Checked)
  1520. {
  1521. Optimize.ExcludeDrivers();
  1522. }
  1523. else
  1524. {
  1525. Optimize.IncludeDrivers();
  1526. }
  1527. Options.CurrentOptions.ExcludeDrivers = !toggleSwitch30.Checked;
  1528. }
  1529. private void toggleSwitch23_Click(object sender, EventArgs e)
  1530. {
  1531. if (!toggleSwitch23.Checked)
  1532. {
  1533. Optimize.DisableTelemetryServices();
  1534. }
  1535. else
  1536. {
  1537. Optimize.EnableTelemetryServices();
  1538. }
  1539. Options.CurrentOptions.DisableTelemetryServices = !toggleSwitch23.Checked;
  1540. }
  1541. private void toggleSwitch21_Click(object sender, EventArgs e)
  1542. {
  1543. if (!toggleSwitch21.Checked)
  1544. {
  1545. Optimize.DisablePrivacyOptions();
  1546. }
  1547. else
  1548. {
  1549. Optimize.EnablePrivacyOptions();
  1550. }
  1551. Options.CurrentOptions.DisablePrivacyOptions = !toggleSwitch21.Checked;
  1552. }
  1553. private void toggleSwitch22_Click(object sender, EventArgs e)
  1554. {
  1555. if (!toggleSwitch22.Checked)
  1556. {
  1557. Optimize.DisableSilentAppInstall();
  1558. }
  1559. else
  1560. {
  1561. Optimize.EnableSilentAppInstall();
  1562. }
  1563. Options.CurrentOptions.DisableSilentAppInstall = !toggleSwitch22.Checked;
  1564. }
  1565. private void toggleSwitch16_Click(object sender, EventArgs e)
  1566. {
  1567. if (!toggleSwitch16.Checked)
  1568. {
  1569. Optimize.DisableCortana();
  1570. }
  1571. else
  1572. {
  1573. Optimize.EnableCortana();
  1574. }
  1575. Options.CurrentOptions.DisableCortana = !toggleSwitch16.Checked;
  1576. }
  1577. private void toggleSwitch20_Click(object sender, EventArgs e)
  1578. {
  1579. if (!toggleSwitch20.Checked)
  1580. {
  1581. Optimize.DisableSensorServices();
  1582. }
  1583. else
  1584. {
  1585. Optimize.EnableSensorServices();
  1586. }
  1587. Options.CurrentOptions.DisableSensorServices = !toggleSwitch20.Checked;
  1588. }
  1589. private void toggleSwitch29_Click(object sender, EventArgs e)
  1590. {
  1591. if (!toggleSwitch29.Checked)
  1592. {
  1593. Optimize.DisableWindowsInk();
  1594. }
  1595. else
  1596. {
  1597. Optimize.EnableWindowsInk();
  1598. }
  1599. Options.CurrentOptions.DisableWindowsInk = !toggleSwitch29.Checked;
  1600. }
  1601. private void toggleSwitch28_Click(object sender, EventArgs e)
  1602. {
  1603. if (!toggleSwitch28.Checked)
  1604. {
  1605. Optimize.DisableSpellingAndTypingFeatures();
  1606. }
  1607. else
  1608. {
  1609. Optimize.EnableSpellingAndTypingFeatures();
  1610. }
  1611. Options.CurrentOptions.DisableSpellingTyping = !toggleSwitch28.Checked;
  1612. }
  1613. private void toggleSwitch17_Click(object sender, EventArgs e)
  1614. {
  1615. if (!toggleSwitch17.Checked)
  1616. {
  1617. Optimize.DisableXboxLive();
  1618. }
  1619. else
  1620. {
  1621. Optimize.EnableXboxLive();
  1622. }
  1623. Options.CurrentOptions.DisableXboxLive = !toggleSwitch17.Checked;
  1624. }
  1625. private void toggleSwitch15_Click(object sender, EventArgs e)
  1626. {
  1627. if (!toggleSwitch15.Checked)
  1628. {
  1629. Optimize.DisableGameBar();
  1630. }
  1631. else
  1632. {
  1633. Optimize.EnableGameBar();
  1634. }
  1635. Options.CurrentOptions.DisableGameBar = !toggleSwitch15.Checked;
  1636. }
  1637. private void toggleSwitch31_Click(object sender, EventArgs e)
  1638. {
  1639. if (!toggleSwitch31.Checked)
  1640. {
  1641. Optimize.DisableOneDrive();
  1642. }
  1643. else
  1644. {
  1645. Optimize.EnableOneDrive();
  1646. }
  1647. Options.CurrentOptions.DisableOneDrive = !toggleSwitch31.Checked;
  1648. }
  1649. private void toggleSwitch32_Click(object sender, EventArgs e)
  1650. {
  1651. if (!toggleSwitch32.Checked)
  1652. {
  1653. Optimize.DisableCompatibilityAssistant();
  1654. }
  1655. else
  1656. {
  1657. Optimize.EnableCompatibilityAssistant();
  1658. }
  1659. Options.CurrentOptions.DisableCompatibilityAssistant = !toggleSwitch32.Checked;
  1660. }
  1661. private void btnUpdate_Click(object sender, EventArgs e)
  1662. {
  1663. CheckForUpdate();
  1664. }
  1665. private void btnChangelog_Click(object sender, EventArgs e)
  1666. {
  1667. try
  1668. {
  1669. Process.Start(_changelogLink);
  1670. }
  1671. catch (Exception ex)
  1672. {
  1673. MessageBox.Show(ex.Message, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
  1674. }
  1675. }
  1676. private void chkReadOnly_CheckedChanged(object sender, EventArgs e)
  1677. {
  1678. HostsHelper.ReadOnly(chkReadOnly.Checked);
  1679. button47.Enabled = !chkReadOnly.Checked;
  1680. button46.Enabled = !chkReadOnly.Checked;
  1681. button42.Enabled = !chkReadOnly.Checked;
  1682. button41.Enabled = !chkReadOnly.Checked;
  1683. linkLabel4.Enabled = !chkReadOnly.Checked;
  1684. chkBlock.Enabled = !chkReadOnly.Checked;
  1685. txtDomain.Enabled = !chkReadOnly.Checked;
  1686. txtIP.Enabled = !chkReadOnly.Checked;
  1687. txtIP.Focus();
  1688. }
  1689. }
  1690. }