MainForm.cs 86 KB

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