MainForm.cs 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203
  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. linkLabel1.Visible = false;
  1758. }
  1759. private void RenderAppDownloaderFree()
  1760. {
  1761. btnDownloadApps.Enabled = true;
  1762. button5.Enabled = true;
  1763. txtDownloadFolder.ReadOnly = false;
  1764. c64.Enabled = true;
  1765. c32.Enabled = true;
  1766. linkLabel1.Visible = !string.IsNullOrEmpty(downloadLog);
  1767. txtDownloadStatus.Text = "Finished";
  1768. }
  1769. string appNameTemp = string.Empty;
  1770. int maxCount = 0;
  1771. int count = 0;
  1772. Process p;
  1773. string downloadLog = string.Empty;
  1774. private async void btnDownloadApps_Click(object sender, EventArgs e)
  1775. {
  1776. if (!Directory.Exists(txtDownloadFolder.Text))
  1777. {
  1778. MessageBox.Show("Download folder specified is not valid!", "Invalid folder", MessageBoxButtons.OK, MessageBoxIcon.Information);
  1779. }
  1780. RenderAppDownloaderBusy();
  1781. maxCount = 0;
  1782. count = 0;
  1783. downloadLog = string.Empty;
  1784. foreach (Control c in Utilities.GetSelfAndChildrenRecursive(appsTab))
  1785. {
  1786. if (c.Name == "cAutoInstall") continue;
  1787. if (c is CheckBox && ((CheckBox)c).Checked) maxCount++;
  1788. }
  1789. CheckBox currentCheck;
  1790. foreach (AppInfo x in apps.Apps)
  1791. {
  1792. if (string.IsNullOrEmpty(x.Tag)) continue;
  1793. currentCheck = (CheckBox)appsTab.Controls.Find(x.Tag, true)[0];
  1794. if (currentCheck == null) continue;
  1795. if (!currentCheck.Checked) continue;
  1796. appNameTemp = x.Title;
  1797. if (c64.Checked)
  1798. {
  1799. count++;
  1800. if (x.Link64 == null)
  1801. {
  1802. downloadLog += "• " + x.Title + ":" + Environment.NewLine + "No 64-bit available, downloading 32-bit" + Environment.NewLine + Environment.NewLine;
  1803. await DownloadApp(x, false);
  1804. }
  1805. else
  1806. {
  1807. await DownloadApp(x, true);
  1808. }
  1809. }
  1810. else
  1811. {
  1812. count++;
  1813. if (x.Link != null)
  1814. {
  1815. await DownloadApp(x, false);
  1816. }
  1817. else
  1818. {
  1819. downloadLog += "• " + x.Title + ":" + Environment.NewLine + "No 32-bit available" + Environment.NewLine + Environment.NewLine;
  1820. }
  1821. }
  1822. }
  1823. if (cAutoInstall.Checked)
  1824. {
  1825. count = 0;
  1826. foreach (string a in Directory.GetFiles(txtDownloadFolder.Text, "*.*", SearchOption.TopDirectoryOnly))
  1827. {
  1828. using (p = new Process())
  1829. {
  1830. count++;
  1831. p.StartInfo.FileName = a;
  1832. p.EnableRaisingEvents = true;
  1833. p.StartInfo.WorkingDirectory = txtDownloadFolder.Text;
  1834. // APP-SPECIFIC HACKS //
  1835. if (a.Contains("Sumatra")) p.StartInfo.Arguments = " -install";
  1836. // *** //
  1837. txtDownloadStatus.Text = string.Format("{0}/{1} - Installing {2} ...", count, maxCount, Path.GetFileNameWithoutExtension(a));
  1838. await p.RunAsync();
  1839. };
  1840. }
  1841. }
  1842. RenderAppDownloaderFree();
  1843. }
  1844. string fileExtension = ".exe";
  1845. private async Task DownloadApp(AppInfo app, bool pref64)
  1846. {
  1847. try
  1848. {
  1849. using (WebClient downloader = new WebClient())
  1850. {
  1851. downloader.Headers.Add("User-Agent: Other");
  1852. downloader.Encoding = Encoding.UTF8;
  1853. downloader.DownloadProgressChanged += Downloader_DownloadProgressChanged;
  1854. downloader.DownloadFileCompleted += Downloader_DownloadFileCompleted;
  1855. if (pref64)
  1856. {
  1857. if (app.Link64.ToString().Contains(".msi"))
  1858. {
  1859. fileExtension = ".msi";
  1860. }
  1861. else
  1862. {
  1863. fileExtension = ".exe";
  1864. }
  1865. await downloader.DownloadFileTaskAsync(app.Link64, Path.Combine(txtDownloadFolder.Text, app.Title + "-x64" + fileExtension));
  1866. }
  1867. else
  1868. {
  1869. if (app.Link.ToString().Contains(".msi"))
  1870. {
  1871. fileExtension = ".msi";
  1872. }
  1873. else
  1874. {
  1875. fileExtension = ".exe";
  1876. }
  1877. await downloader.DownloadFileTaskAsync(app.Link, Path.Combine(txtDownloadFolder.Text, app.Title + "-x86" + fileExtension));
  1878. }
  1879. }
  1880. }
  1881. catch (Exception ex)
  1882. {
  1883. downloadLog += "• " + app.Title + ":" + Environment.NewLine + "Link is no longer valid!" + Environment.NewLine + Environment.NewLine;
  1884. if (pref64) try { File.Delete(Path.Combine(txtDownloadFolder.Text, app.Title + "-x64.exe")); } catch { }
  1885. if (!pref64) try { File.Delete(Path.Combine(txtDownloadFolder.Text, app.Title + "-x86.exe")); } catch { }
  1886. if (pref64) try { File.Delete(Path.Combine(txtDownloadFolder.Text, app.Title + "-x64.msi")); } catch { }
  1887. if (!pref64) try { File.Delete(Path.Combine(txtDownloadFolder.Text, app.Title + "-x86.msi")); } catch { }
  1888. }
  1889. }
  1890. private void Downloader_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
  1891. {
  1892. this.BeginInvoke((MethodInvoker)delegate
  1893. {
  1894. txtDownloadStatus.Text = "Finished";
  1895. });
  1896. }
  1897. private void Downloader_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
  1898. {
  1899. this.BeginInvoke((MethodInvoker)delegate
  1900. {
  1901. double bytesIn = double.Parse(e.BytesReceived.ToString());
  1902. double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
  1903. double percentage = bytesIn / totalBytes * 100;
  1904. txtDownloadStatus.Text = string.Format("({1}/{2}) - {0} - {3} / {4}", appNameTemp, count, maxCount, ByteSize.FromBytes(e.BytesReceived).ToString("MB"), ByteSize.FromBytes(e.TotalBytesToReceive).ToString("MB"));
  1905. progressDownloader.Value = int.Parse(Math.Truncate(percentage).ToString());
  1906. });
  1907. }
  1908. private void button5_Click(object sender, EventArgs e)
  1909. {
  1910. FolderBrowserDialog d = new FolderBrowserDialog();
  1911. if (d.ShowDialog() == DialogResult.OK)
  1912. {
  1913. txtDownloadFolder.Text = d.SelectedPath;
  1914. Options.CurrentOptions.AppsFolder = d.SelectedPath;
  1915. Options.SaveSettings();
  1916. }
  1917. }
  1918. private void button6_Click(object sender, EventArgs e)
  1919. {
  1920. Process.Start(txtDownloadFolder.Text);
  1921. }
  1922. private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1923. {
  1924. InfoForm lf = new InfoForm(downloadLog);
  1925. lf.ShowDialog(this);
  1926. }
  1927. private void txtDownloadFolder_TextChanged(object sender, EventArgs e)
  1928. {
  1929. Options.CurrentOptions.AppsFolder = txtDownloadFolder.Text;
  1930. Options.SaveSettings();
  1931. }
  1932. }
  1933. }