MainForm.cs 63 KB

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