MainForm.cs 65 KB

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