MainForm.cs 76 KB

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