MainForm.cs 76 KB

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