MainForm.cs 81 KB

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