MainForm.cs 76 KB

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