MainForm.cs 81 KB

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