MainForm.cs 76 KB

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