MainForm.cs 77 KB

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