MainForm.cs 81 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355
  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. // fix SSL/TLS error when contacting internet
  298. ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
  299. // initial states
  300. chkOnlyRemovable.Checked = true;
  301. checkDefaultIcon.Checked = true;
  302. radioProgram.Checked = true;
  303. radioTop.Checked = true;
  304. c64.Checked = Environment.Is64BitOperatingSystem;
  305. c32.Checked = !Environment.Is64BitOperatingSystem;
  306. if (Utilities.CurrentWindowsVersion == WindowsVersion.Unsupported)
  307. {
  308. tabCollection.TabPages.Remove(universalTab);
  309. tabCollection.TabPages.Remove(windowsVIIITab);
  310. tabCollection.TabPages.Remove(windowsXTab);
  311. tabCollection.TabPages.Remove(modernAppsTab);
  312. }
  313. if (Utilities.CurrentWindowsVersion == WindowsVersion.Windows7)
  314. {
  315. LoadUniversalToggleStates();
  316. tabCollection.TabPages.Remove(windowsVIIITab);
  317. tabCollection.TabPages.Remove(windowsXTab);
  318. tabCollection.TabPages.Remove(modernAppsTab);
  319. }
  320. if (Utilities.CurrentWindowsVersion == WindowsVersion.Windows8)
  321. {
  322. LoadUniversalToggleStates();
  323. LoadWindowsVIIIToggleStates();
  324. tabCollection.TabPages.Remove(windowsXTab);
  325. GetModernApps(false);
  326. }
  327. if (Utilities.CurrentWindowsVersion == WindowsVersion.Windows10)
  328. {
  329. LoadUniversalToggleStates();
  330. LoadWindowsXToggleStates();
  331. tabCollection.TabPages.Remove(windowsVIIITab);
  332. GetModernApps(false);
  333. }
  334. _columnSorter = new ListViewColumnSorter();
  335. listStartupItems.ListViewItemSorter = _columnSorter;
  336. GetStartupItems();
  337. GetHostsEntries();
  338. integratorTimer.Start();
  339. runDialogTime.Start();
  340. GetDesktopItems();
  341. GetCustomCommands();
  342. LoadSettings();
  343. txtVersion.Text = "Version: " + Program.GetCurrentVersionTostring();
  344. Program.MainForm = this;
  345. txtOS.Text = "Microsoft " + Utilities.GetOS();
  346. txtBitness.Text = Utilities.GetBitness();
  347. if (string.IsNullOrEmpty(Options.CurrentOptions.AppsFolder))
  348. {
  349. txtDownloadFolder.Text = Path.Combine(Application.StartupPath, "Optimizer Downloads");
  350. Options.CurrentOptions.AppsFolder = Path.Combine(Application.StartupPath, "Optimizer Downloads");
  351. Directory.CreateDirectory(Options.CurrentOptions.AppsFolder);
  352. Options.SaveSettings();
  353. }
  354. else
  355. {
  356. if (!Directory.Exists(Options.CurrentOptions.AppsFolder))
  357. {
  358. Directory.CreateDirectory(Options.CurrentOptions.AppsFolder);
  359. }
  360. txtDownloadFolder.Text = Options.CurrentOptions.AppsFolder;
  361. }
  362. GetFeed();
  363. GetFootprint();
  364. }
  365. private void GetFootprint()
  366. {
  367. ByteSize footprint = CleanHelper.CheckFootprint();
  368. lblFootprint.Text = footprint.ToString();
  369. }
  370. private void GetFeed()
  371. {
  372. WebClient client = new WebClient
  373. {
  374. Encoding = Encoding.UTF8
  375. };
  376. try
  377. {
  378. string feed = client.DownloadString(_feedLink);
  379. AppsFromFeed = JsonConvert.DeserializeObject<List<FeedApp>>(feed);
  380. // UI handling
  381. panel1.Visible = true;
  382. panel2.Visible = true;
  383. panel3.Visible = true;
  384. panel4.Visible = true;
  385. panel5.Visible = true;
  386. panel6.Visible = true;
  387. label42.Visible = true;
  388. label44.Visible = true;
  389. txtDownloadFolder.Visible = true;
  390. button5.Visible = true;
  391. button6.Visible = true;
  392. btnDownloadApps.Visible = true;
  393. c32.Visible = true;
  394. c64.Visible = true;
  395. cAutoInstall.Visible = true;
  396. linkLabel1.Visible = false;
  397. progressDownloader.Visible = true;
  398. txtDownloadStatus.Visible = true;
  399. //btnGetFeed.Visible = true;
  400. txtFeedError.Visible = false;
  401. }
  402. catch (Exception ex)
  403. {
  404. panel1.Visible = false;
  405. panel2.Visible = false;
  406. panel3.Visible = false;
  407. panel4.Visible = false;
  408. panel5.Visible = false;
  409. panel6.Visible = false;
  410. label42.Visible = false;
  411. label44.Visible = false;
  412. txtDownloadFolder.Visible = false;
  413. button5.Visible = true;
  414. button6.Visible = false;
  415. btnDownloadApps.Visible = false;
  416. c32.Visible = false;
  417. c64.Visible = false;
  418. cAutoInstall.Visible = false;
  419. linkLabel1.Visible = false;
  420. progressDownloader.Visible = false;
  421. txtDownloadStatus.Visible = false;
  422. //btnGetFeed.Visible = true;
  423. txtFeedError.Visible = true;
  424. ErrorLogger.LogError("MainForm.GetFeed", ex.Message, ex.StackTrace);
  425. }
  426. }
  427. private void CleanPC()
  428. {
  429. try
  430. {
  431. if (checkTemp.Checked)
  432. {
  433. CleanHelper.CleanTemporaries();
  434. }
  435. if (checkFileZilla.Checked)
  436. {
  437. CleanHelper.CleanFileZilla();
  438. }
  439. if (checkMiniDumps.Checked)
  440. {
  441. CleanHelper.CleanMiniDumps();
  442. }
  443. if (checkMediaCache.Checked)
  444. {
  445. CleanHelper.CleanMediaPlayersCache();
  446. }
  447. if (checkLogs.Checked)
  448. {
  449. CleanHelper.CleanLogs();
  450. }
  451. if (checkErrorReports.Checked)
  452. {
  453. CleanHelper.CleanErrorReports();
  454. }
  455. if (checkBin.Checked)
  456. {
  457. CleanHelper.EmptyRecycleBin();
  458. }
  459. }
  460. catch (Exception ex)
  461. {
  462. ErrorLogger.LogError("MainForm.CleanPC", ex.Message, ex.StackTrace);
  463. }
  464. finally
  465. {
  466. CleaningAnimation(false);
  467. GetFootprint();
  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. checkFileZilla.Checked = checkSelectAll.Checked;
  739. checkMiniDumps.Checked = checkSelectAll.Checked;
  740. checkMediaCache.Checked = checkSelectAll.Checked;
  741. checkLogs.Checked = checkSelectAll.Checked;
  742. checkBin.Checked = checkSelectAll.Checked;
  743. checkErrorReports.Checked = checkSelectAll.Checked;
  744. }
  745. private void button20_Click(object sender, EventArgs e)
  746. {
  747. CleaningAnimation(true);
  748. Task t = new Task(() => CleanPC());
  749. t.Start();
  750. }
  751. private void button32_Click(object sender, EventArgs e)
  752. {
  753. if (listStartupItems.SelectedItems.Count == 1)
  754. {
  755. _startUpItems[listStartupItems.SelectedIndices[0]].Remove();
  756. GetStartupItems();
  757. }
  758. }
  759. internal void RemoveAllStartupItems()
  760. {
  761. foreach (ListViewItem i in listStartupItems.Items)
  762. {
  763. _startUpItems[i.Index].Remove();
  764. }
  765. GetStartupItems();
  766. }
  767. private void button22_Click(object sender, EventArgs e)
  768. {
  769. if (listStartupItems.Items.Count > 0)
  770. {
  771. HelperForm r = new HelperForm(this, MessageType.Startup, _removeStartupItemsMessage);
  772. r.ShowDialog(this);
  773. }
  774. }
  775. private void button31_Click(object sender, EventArgs e)
  776. {
  777. if (listStartupItems.SelectedItems.Count == 1)
  778. {
  779. _startUpItems[listStartupItems.SelectedIndices[0]].LocateFile();
  780. }
  781. }
  782. private void checkEnableAll_CheckedChanged(object sender, EventArgs e)
  783. {
  784. checkTaskManager.Checked = checkEnableAll.Checked;
  785. checkCommandPrompt.Checked = checkEnableAll.Checked;
  786. checkControlPanel.Checked = checkEnableAll.Checked;
  787. checkFolderOptions.Checked = checkEnableAll.Checked;
  788. checkRunDialog.Checked = checkEnableAll.Checked;
  789. checkContextMenu.Checked = checkEnableAll.Checked;
  790. checkFirewall.Checked = checkEnableAll.Checked;
  791. checkRegistryEditor.Checked = checkEnableAll.Checked;
  792. }
  793. private void button33_Click(object sender, EventArgs e)
  794. {
  795. bool flag = FixRegistry();
  796. if (flag)
  797. {
  798. panel2.Enabled = false;
  799. button33.Enabled = false;
  800. if (checkRestartExplorer.Checked)
  801. {
  802. Utilities.RestartExplorer();
  803. }
  804. panel2.Enabled = true;
  805. button33.Enabled = true;
  806. }
  807. }
  808. private void pictureBox1_Click(object sender, EventArgs e)
  809. {
  810. AboutForm f = new AboutForm();
  811. f.ShowDialog(this);
  812. }
  813. private void button37_Click(object sender, EventArgs e)
  814. {
  815. GetStartupItems();
  816. }
  817. private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  818. {
  819. HostsHelper.LocateHosts();
  820. }
  821. private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  822. {
  823. HostsEditorForm f = new HostsEditorForm();
  824. f.ShowDialog(this);
  825. GetHostsEntries();
  826. }
  827. private void linkLabel4_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  828. {
  829. HostsHelper.RestoreDefaultHosts();
  830. GetHostsEntries();
  831. }
  832. private void button47_Click(object sender, EventArgs e)
  833. {
  834. if ((txtIP.Text != string.Empty) && (txtDomain.Text != string.Empty))
  835. {
  836. string ip = txtIP.Text.Trim();
  837. string domain = txtDomain.Text.Trim();
  838. string recommendedDomain = string.Empty;
  839. if (!domain.StartsWith("www."))
  840. {
  841. recommendedDomain = "www." + domain;
  842. }
  843. else
  844. {
  845. recommendedDomain = domain.Replace("www.", string.Empty);
  846. }
  847. HostsHelper.AddEntry(HostsHelper.SanitizeEntry(ip) + " " + HostsHelper.SanitizeEntry(domain));
  848. if (!string.IsNullOrEmpty(recommendedDomain))
  849. {
  850. HostsHelper.AddEntry(HostsHelper.SanitizeEntry(ip) + " " + HostsHelper.SanitizeEntry(recommendedDomain));
  851. }
  852. GetHostsEntries();
  853. txtIP.Clear();
  854. txtDomain.Clear();
  855. chkBlock.Checked = false;
  856. }
  857. }
  858. private void button41_Click(object sender, EventArgs e)
  859. {
  860. GetHostsEntries();
  861. }
  862. private void button42_Click(object sender, EventArgs e)
  863. {
  864. if (listHostEntries.SelectedItems.Count == 1)
  865. {
  866. HostsHelper.RemoveEntry(listHostEntries.SelectedItem.ToString().Replace(" : ", " "));
  867. GetHostsEntries();
  868. }
  869. }
  870. private void button46_Click(object sender, EventArgs e)
  871. {
  872. if (listHostEntries.Items.Count > 0)
  873. {
  874. HelperForm r = new HelperForm(this, MessageType.Hosts, _removeHostsEntriesMessage);
  875. r.ShowDialog(this);
  876. }
  877. }
  878. internal void RemoveAllHostsEntries()
  879. {
  880. List<string> collection = new List<string>();
  881. foreach (string item in listHostEntries.Items)
  882. {
  883. collection.Add(item.Replace(" : ", " "));
  884. }
  885. HostsHelper.RemoveAllEntries(collection);
  886. GetHostsEntries();
  887. }
  888. private void aio_SelectedIndexChanged(object sender, EventArgs e)
  889. {
  890. if (tabCollection.SelectedTab == hostsEditorTab)
  891. {
  892. txtIP.Focus();
  893. }
  894. }
  895. private void button48_Click(object sender, EventArgs e)
  896. {
  897. defineCommandDialog.ShowDialog();
  898. }
  899. private void button50_Click(object sender, EventArgs e)
  900. {
  901. if ((txtRunFile.Text != string.Empty) && (txtRunKeyword.Text != string.Empty))
  902. {
  903. Integrator.CreateCustomCommand(txtRunFile.Text, txtRunKeyword.Text);
  904. txtRunFile.Clear();
  905. txtRunKeyword.Clear();
  906. GetCustomCommands();
  907. }
  908. }
  909. private void DefineCmd_FileOk(object sender, CancelEventArgs e)
  910. {
  911. txtRunFile.Text = defineCommandDialog.FileName;
  912. txtRunKeyword.Text = Path.GetFileNameWithoutExtension(txtRunFile.Text).ToLower();
  913. }
  914. private void button58_Click(object sender, EventArgs e)
  915. {
  916. InfoForm r = new InfoForm(Integrator.powerinfo);
  917. r.ShowDialog(this);
  918. }
  919. private void button56_Click(object sender, EventArgs e)
  920. {
  921. InfoForm r = new InfoForm(Integrator.systemtoolsinfo);
  922. r.ShowDialog(this);
  923. }
  924. private void button52_Click(object sender, EventArgs e)
  925. {
  926. InfoForm r = new InfoForm(Integrator.windowsappsinfo);
  927. r.ShowDialog(this);
  928. }
  929. private void button49_Click(object sender, EventArgs e)
  930. {
  931. InfoForm r = new InfoForm(Integrator.systemshortcutsinfo);
  932. r.ShowDialog(this);
  933. }
  934. private void button55_Click(object sender, EventArgs e)
  935. {
  936. InfoForm r = new InfoForm(Integrator.desktopshortcutsinfo);
  937. r.ShowDialog(this);
  938. }
  939. private void button59_Click(object sender, EventArgs e)
  940. {
  941. Utilities.ImportRegistryScript(Required.ReadyMadeMenusFolder + "\\PowerMenu.reg");
  942. GetDesktopItems();
  943. }
  944. private void button53_Click(object sender, EventArgs e)
  945. {
  946. Utilities.ImportRegistryScript(Required.ReadyMadeMenusFolder + "\\SystemTools.reg");
  947. GetDesktopItems();
  948. }
  949. private void button54_Click(object sender, EventArgs e)
  950. {
  951. Utilities.ImportRegistryScript(Required.ReadyMadeMenusFolder + "\\WindowsApps.reg");
  952. GetDesktopItems();
  953. }
  954. private void button51_Click(object sender, EventArgs e)
  955. {
  956. Utilities.ImportRegistryScript(Required.ReadyMadeMenusFolder + "\\SystemShortcuts.reg");
  957. GetDesktopItems();
  958. }
  959. private void button57_Click(object sender, EventArgs e)
  960. {
  961. Utilities.ImportRegistryScript(Required.ReadyMadeMenusFolder + "\\DesktopShortcuts.reg");
  962. GetDesktopItems();
  963. }
  964. private void button60_Click(object sender, EventArgs e)
  965. {
  966. GetDesktopItems();
  967. }
  968. private void button61_Click(object sender, EventArgs e)
  969. {
  970. if (listDesktopItems.SelectedItems.Count == 1)
  971. {
  972. Integrator.RemoveItem(listDesktopItems.SelectedItem.ToString());
  973. GetDesktopItems();
  974. }
  975. }
  976. internal void RemoveAllDesktopItems()
  977. {
  978. List<string> collection = new List<string>();
  979. foreach (string item in listDesktopItems.Items)
  980. {
  981. collection.Add(item);
  982. }
  983. Integrator.RemoveAllItems(collection);
  984. GetDesktopItems();
  985. }
  986. private void button62_Click(object sender, EventArgs e)
  987. {
  988. if (listDesktopItems.Items.Count > 0)
  989. {
  990. HelperForm r = new HelperForm(this, MessageType.Integrator, _removeDesktopItemsMessage);
  991. r.ShowDialog(this);
  992. }
  993. }
  994. private void radioProgram_CheckedChanged(object sender, EventArgs e)
  995. {
  996. if (radioProgram.Checked)
  997. {
  998. btnBrowseItem.Enabled = true;
  999. txtItem.Clear();
  1000. checkDefaultIcon.Checked = true;
  1001. txtIcon.Enabled = false;
  1002. btnBrowseIcon.Enabled = false;
  1003. itemtoaddgroup.Text = "Program to add:";
  1004. checkDefaultIcon.Visible = true;
  1005. checkDefaultIcon.Text = "Use program's icon";
  1006. txtItemName.Clear();
  1007. txtItem.ReadOnly = true;
  1008. txtIcon.ReadOnly = true;
  1009. _desktopItemType = DesktopItemType.Program;
  1010. }
  1011. }
  1012. private void radioFolder_CheckedChanged(object sender, EventArgs e)
  1013. {
  1014. if (radioFolder.Checked)
  1015. {
  1016. checkDefaultIcon.Checked = true;
  1017. btnBrowseItem.Enabled = true;
  1018. txtItem.Clear();
  1019. itemtoaddgroup.Text = "Folder to add:";
  1020. checkDefaultIcon.Text = "Use default folder icon";
  1021. txtItemName.Clear();
  1022. txtItem.ReadOnly = true;
  1023. txtIcon.ReadOnly = true;
  1024. _desktopItemType = DesktopItemType.Folder;
  1025. }
  1026. }
  1027. private void radioLink_CheckedChanged(object sender, EventArgs e)
  1028. {
  1029. if (radioLink.Checked)
  1030. {
  1031. checkDefaultIcon.Checked = true;
  1032. checkDefaultIcon.Text = "Download website icon (favicon)";
  1033. btnBrowseItem.Enabled = false;
  1034. itemtoaddgroup.Text = "Web address to add:";
  1035. checkDefaultIcon.Visible = true;
  1036. txtItem.Text = "http://";
  1037. txtItemName.Clear();
  1038. txtItem.ReadOnly = false;
  1039. txtIcon.ReadOnly = true;
  1040. _desktopItemType = DesktopItemType.Link;
  1041. }
  1042. }
  1043. private void radioFile_CheckedChanged(object sender, EventArgs e)
  1044. {
  1045. if (radioFile.Checked)
  1046. {
  1047. checkDefaultIcon.Checked = true;
  1048. checkDefaultIcon.Text = "No icon";
  1049. btnBrowseItem.Enabled = true;
  1050. itemtoaddgroup.Text = "File to add:";
  1051. checkDefaultIcon.Visible = true;
  1052. txtItem.Clear();
  1053. txtItemName.Clear();
  1054. txtItem.ReadOnly = true;
  1055. txtIcon.ReadOnly = true;
  1056. _desktopItemType = DesktopItemType.File;
  1057. }
  1058. }
  1059. private void radioCommand_CheckedChanged(object sender, EventArgs e)
  1060. {
  1061. if (radioCommand.Checked)
  1062. {
  1063. btnBrowseItem.Enabled = false;
  1064. txtItem.Clear();
  1065. checkDefaultIcon.Checked = true;
  1066. txtIcon.Enabled = false;
  1067. btnBrowseIcon.Enabled = false;
  1068. itemtoaddgroup.Text = "Command to add:";
  1069. checkDefaultIcon.Visible = true;
  1070. checkDefaultIcon.Text = "No icon";
  1071. txtItemName.Clear();
  1072. txtItem.ReadOnly = false;
  1073. txtIcon.ReadOnly = true;
  1074. _desktopItemType = DesktopItemType.Command;
  1075. }
  1076. }
  1077. private void checkDefaultIcon_CheckedChanged(object sender, EventArgs e)
  1078. {
  1079. if (checkDefaultIcon.Checked)
  1080. {
  1081. txtIcon.Clear();
  1082. txtIcon.Enabled = false;
  1083. btnBrowseIcon.Enabled = false;
  1084. }
  1085. else
  1086. {
  1087. txtIcon.Clear();
  1088. txtIcon.Enabled = true;
  1089. btnBrowseIcon.Enabled = true;
  1090. }
  1091. }
  1092. private void btnBrowseItem_Click(object sender, EventArgs e)
  1093. {
  1094. switch (_desktopItemType)
  1095. {
  1096. case DesktopItemType.Program:
  1097. defineProgramDialog.ShowDialog();
  1098. break;
  1099. case DesktopItemType.Folder:
  1100. defineFolderDialog.ShowDialog();
  1101. txtItem.Text = defineFolderDialog.SelectedPath;
  1102. int i = defineFolderDialog.SelectedPath.LastIndexOf("\\");
  1103. txtItemName.Text = defineFolderDialog.SelectedPath.Remove(0, i + 1);
  1104. break;
  1105. case DesktopItemType.File:
  1106. defineFileDialog.ShowDialog();
  1107. break;
  1108. }
  1109. }
  1110. private void DefineProgramDialog_FileOk(object sender, CancelEventArgs e)
  1111. {
  1112. txtItem.Text = defineProgramDialog.FileName;
  1113. txtItemName.Text = defineProgramDialog.SafeFileName.Replace(".exe", string.Empty);
  1114. }
  1115. private void DefineFileDialog_FileOk(object sender, CancelEventArgs e)
  1116. {
  1117. txtItem.Text = defineFileDialog.FileName;
  1118. txtItemName.Text = defineFileDialog.SafeFileName;
  1119. }
  1120. private void btnBrowseIcon_Click(object sender, EventArgs e)
  1121. {
  1122. switch (_desktopItemType)
  1123. {
  1124. case DesktopItemType.Program:
  1125. DefineProgramIconDialog.ShowDialog();
  1126. break;
  1127. case DesktopItemType.Folder:
  1128. DefineFolderIconDialog.ShowDialog();
  1129. break;
  1130. case DesktopItemType.Link:
  1131. DefineURLIconDialog.ShowDialog();
  1132. break;
  1133. case DesktopItemType.File:
  1134. DefineFileIconDialog.ShowDialog();
  1135. break;
  1136. case DesktopItemType.Command:
  1137. DefineCommandIconDialog.ShowDialog();
  1138. break;
  1139. }
  1140. }
  1141. private void DefineProgramIconDialog_FileOk(object sender, CancelEventArgs e)
  1142. {
  1143. txtIcon.Text = DefineProgramIconDialog.FileName;
  1144. if (txtIcon.Text.Contains(".exe"))
  1145. {
  1146. string iconpath = Integrator.ExtractIconFromExecutable(txtItemName.Text, DefineProgramIconDialog.FileName);
  1147. txtIcon.Text = iconpath;
  1148. }
  1149. }
  1150. private void DefineFolderIconDialog_FileOk(object sender, CancelEventArgs e)
  1151. {
  1152. txtIcon.Text = DefineFolderIconDialog.FileName;
  1153. if (txtIcon.Text.Contains(".exe"))
  1154. {
  1155. string iconpath = Integrator.ExtractIconFromExecutable(txtItemName.Text, DefineFolderIconDialog.FileName);
  1156. txtIcon.Text = iconpath;
  1157. }
  1158. }
  1159. private void DefineURLIconDialog_FileOk(object sender, CancelEventArgs e)
  1160. {
  1161. txtIcon.Text = DefineURLIconDialog.FileName;
  1162. if (txtIcon.Text.Contains(".exe"))
  1163. {
  1164. string iconpath = Integrator.ExtractIconFromExecutable(txtItemName.Text, DefineURLIconDialog.FileName);
  1165. txtIcon.Text = iconpath;
  1166. }
  1167. }
  1168. private void DefineFileIconDialog_FileOk(object sender, CancelEventArgs e)
  1169. {
  1170. txtIcon.Text = DefineFileIconDialog.FileName;
  1171. if (txtIcon.Text.Contains(".exe"))
  1172. {
  1173. string iconpath = Integrator.ExtractIconFromExecutable(txtItemName.Text, DefineFileIconDialog.FileName);
  1174. txtIcon.Text = iconpath;
  1175. }
  1176. }
  1177. private void DefineCommandIconDialog_FileOk(object sender, CancelEventArgs e)
  1178. {
  1179. txtIcon.Text = DefineCommandIconDialog.FileName;
  1180. if (txtIcon.Text.Contains(".exe"))
  1181. {
  1182. string iconpath = Integrator.ExtractIconFromExecutable(txtItemName.Text, DefineCommandIconDialog.FileName);
  1183. txtIcon.Text = iconpath;
  1184. }
  1185. }
  1186. private void btnAddItem_Click(object sender, EventArgs e)
  1187. {
  1188. string icon = string.Empty;
  1189. switch (_desktopItemType)
  1190. {
  1191. case DesktopItemType.Program:
  1192. if (checkDefaultIcon.Checked)
  1193. {
  1194. icon = txtItem.Text;
  1195. }
  1196. else
  1197. {
  1198. icon = txtIcon.Text;
  1199. }
  1200. Integrator.AddItem(txtItemName.Text, txtItem.Text, icon, _desktopItemPosition, checkShift.Checked, DesktopItemType.Program);
  1201. break;
  1202. case DesktopItemType.Folder:
  1203. if (checkDefaultIcon.Checked)
  1204. {
  1205. icon = Integrator.FolderDefaultIcon;
  1206. }
  1207. else
  1208. {
  1209. icon = txtIcon.Text;
  1210. }
  1211. Integrator.AddItem(txtItemName.Text, txtItem.Text, icon, _desktopItemPosition, checkShift.Checked, DesktopItemType.Folder);
  1212. break;
  1213. case DesktopItemType.Link:
  1214. if (checkDefaultIcon.Checked)
  1215. {
  1216. icon = Integrator.DownloadFavicon(txtItem.Text, txtItemName.Text);
  1217. }
  1218. else
  1219. {
  1220. icon = txtIcon.Text;
  1221. }
  1222. Integrator.AddItem(txtItemName.Text, txtItem.Text, icon, _desktopItemPosition, checkShift.Checked, DesktopItemType.Link);
  1223. break;
  1224. case DesktopItemType.File:
  1225. if (!checkDefaultIcon.Checked)
  1226. {
  1227. icon = txtIcon.Text;
  1228. }
  1229. Integrator.AddItem(txtItemName.Text, txtItem.Text, icon, _desktopItemPosition, checkShift.Checked, DesktopItemType.File);
  1230. break;
  1231. case DesktopItemType.Command:
  1232. if (!checkDefaultIcon.Checked)
  1233. {
  1234. icon = txtIcon.Text;
  1235. }
  1236. Integrator.AddItem(txtItemName.Text, txtItem.Text, icon, _desktopItemPosition, checkShift.Checked, DesktopItemType.Command);
  1237. break;
  1238. }
  1239. GetDesktopItems();
  1240. ResetIntegratorForm();
  1241. }
  1242. private void integratorTimer_Tick(object sender, EventArgs e)
  1243. {
  1244. if ((txtItem.Text != "") && (txtItemName.Text != "") && (txtIcon.Text != "") && (!checkDefaultIcon.Checked))
  1245. {
  1246. btnAddItem.Enabled = true;
  1247. }
  1248. else if ((txtItem.Text != "") && (txtItemName.Text != "") && (checkDefaultIcon.Checked))
  1249. {
  1250. btnAddItem.Enabled = true;
  1251. }
  1252. else
  1253. {
  1254. btnAddItem.Enabled = false;
  1255. }
  1256. }
  1257. private void runDialogTimer_Tick(object sender, EventArgs e)
  1258. {
  1259. if ((txtRunFile.Text != "") && (txtRunKeyword.Text != ""))
  1260. {
  1261. btnCreateCustomCommand.Enabled = true;
  1262. }
  1263. else
  1264. {
  1265. btnCreateCustomCommand.Enabled = false;
  1266. }
  1267. }
  1268. private void radioTop_CheckedChanged(object sender, EventArgs e)
  1269. {
  1270. if (radioTop.Checked)
  1271. {
  1272. _desktopItemPosition = DesktopTypePosition.Top;
  1273. }
  1274. }
  1275. private void radioMiddle_CheckedChanged(object sender, EventArgs e)
  1276. {
  1277. if (radioMiddle.Checked)
  1278. {
  1279. _desktopItemPosition = DesktopTypePosition.Middle;
  1280. }
  1281. }
  1282. private void radioBottom_CheckedChanged(object sender, EventArgs e)
  1283. {
  1284. if (radioBottom.Checked)
  1285. {
  1286. _desktopItemPosition = DesktopTypePosition.Bottom;
  1287. }
  1288. }
  1289. private void ResetIntegratorForm()
  1290. {
  1291. txtItem.Clear();
  1292. txtIcon.Clear();
  1293. checkDefaultIcon.Checked = true;
  1294. txtItemName.Clear();
  1295. if (radioLink.Checked)
  1296. {
  1297. txtItem.Text = "http://";
  1298. }
  1299. }
  1300. private void radioOcean_CheckedChanged(object sender, EventArgs e)
  1301. {
  1302. Options.CurrentOptions.Color = Theme.Ocean;
  1303. Options.ApplyTheme(this);
  1304. }
  1305. private void radioMagma_CheckedChanged(object sender, EventArgs e)
  1306. {
  1307. Options.CurrentOptions.Color = Theme.Magma;
  1308. Options.ApplyTheme(this);
  1309. }
  1310. private void radioZerg_CheckedChanged(object sender, EventArgs e)
  1311. {
  1312. Options.CurrentOptions.Color = Theme.Zerg;
  1313. Options.ApplyTheme(this);
  1314. }
  1315. private void radioMinimal_CheckedChanged(object sender, EventArgs e)
  1316. {
  1317. Options.CurrentOptions.Color = Theme.Minimal;
  1318. Options.ApplyTheme(this);
  1319. }
  1320. private void radioCaramel_CheckedChanged(object sender, EventArgs e)
  1321. {
  1322. Options.CurrentOptions.Color = Theme.Caramel;
  1323. Options.ApplyTheme(this);
  1324. }
  1325. private void radioLime_CheckedChanged(object sender, EventArgs e)
  1326. {
  1327. Options.CurrentOptions.Color = Theme.Lime;
  1328. Options.ApplyTheme(this);
  1329. }
  1330. private void button64_Click(object sender, EventArgs e)
  1331. {
  1332. if (listStartupItems.SelectedItems.Count == 1)
  1333. {
  1334. _startUpItems[listStartupItems.SelectedIndices[0]].LocateKey();
  1335. }
  1336. }
  1337. private void button66_Click(object sender, EventArgs e)
  1338. {
  1339. Integrator.TakeOwnership(false);
  1340. }
  1341. private void button65_Click(object sender, EventArgs e)
  1342. {
  1343. Integrator.TakeOwnership(true);
  1344. }
  1345. private void listStartupItems_ColumnClick(object sender, ColumnClickEventArgs e)
  1346. {
  1347. if (e.Column == _columnSorter.CurrentColumn)
  1348. {
  1349. if (_columnSorter.SortOrder == SortOrder.Ascending)
  1350. {
  1351. _columnSorter.SortOrder = SortOrder.Descending;
  1352. }
  1353. else
  1354. {
  1355. _columnSorter.SortOrder = SortOrder.Ascending;
  1356. }
  1357. }
  1358. else
  1359. {
  1360. _columnSorter.CurrentColumn = e.Column;
  1361. _columnSorter.SortOrder = SortOrder.Ascending;
  1362. }
  1363. listStartupItems.Sort();
  1364. }
  1365. private void chkBlock_CheckedChanged(object sender, EventArgs e)
  1366. {
  1367. if (chkBlock.Checked)
  1368. {
  1369. txtIP.Text = _blockedIP;
  1370. txtIP.Enabled = false;
  1371. }
  1372. else
  1373. {
  1374. txtIP.Clear();
  1375. txtIP.Enabled = true;
  1376. }
  1377. }
  1378. private void button8_Click(object sender, EventArgs e)
  1379. {
  1380. GetCustomCommands();
  1381. }
  1382. private void button26_Click(object sender, EventArgs e)
  1383. {
  1384. if (listCustomCommands.SelectedItems.Count == 1)
  1385. {
  1386. Integrator.DeleteCustomCommand(listCustomCommands.SelectedItem.ToString());
  1387. GetCustomCommands();
  1388. }
  1389. }
  1390. private void button75_Click(object sender, EventArgs e)
  1391. {
  1392. GetModernApps(!chkOnlyRemovable.Checked);
  1393. }
  1394. private void button74_Click(object sender, EventArgs e)
  1395. {
  1396. UninstallModernApps();
  1397. }
  1398. private void chkSelectAllModernApps_CheckedChanged(object sender, EventArgs e)
  1399. {
  1400. for (int i = 0; i < listModernApps.Items.Count; i++)
  1401. {
  1402. listModernApps.SetItemChecked(i, chkSelectAllModernApps.Checked);
  1403. }
  1404. }
  1405. private void btnResetConfig_Click(object sender, EventArgs e)
  1406. {
  1407. if (MessageBox.Show(_resetMessage, "Information", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1408. {
  1409. Utilities.ResetConfiguration();
  1410. }
  1411. }
  1412. private void toggleSwitch1_Click(object sender, EventArgs e)
  1413. {
  1414. if (!toggleSwitch1.Checked)
  1415. {
  1416. Optimize.EnablePerformanceTweaks();
  1417. }
  1418. else
  1419. {
  1420. Optimize.DisablePerformanceTweaks();
  1421. }
  1422. Options.CurrentOptions.EnablePerformanceTweaks = !toggleSwitch1.Checked;
  1423. }
  1424. private void toggleSwitch2_Click(object sender, EventArgs e)
  1425. {
  1426. if (!toggleSwitch2.Checked)
  1427. {
  1428. Optimize.DisableNetworkThrottling();
  1429. }
  1430. else
  1431. {
  1432. Optimize.EnableNetworkThrottling();
  1433. }
  1434. Options.CurrentOptions.DisableNetworkThrottling = !toggleSwitch2.Checked;
  1435. }
  1436. private void toggleSwitch3_Click(object sender, EventArgs e)
  1437. {
  1438. if (!toggleSwitch3.Checked)
  1439. {
  1440. Optimize.DisableDefender();
  1441. }
  1442. else
  1443. {
  1444. Optimize.EnableDefender();
  1445. }
  1446. Options.CurrentOptions.DisableWindowsDefender = !toggleSwitch3.Checked;
  1447. }
  1448. private void toggleSwitch4_Click(object sender, EventArgs e)
  1449. {
  1450. if (!toggleSwitch4.Checked)
  1451. {
  1452. Optimize.DisableSystemRestore();
  1453. }
  1454. else
  1455. {
  1456. Optimize.EnableSystemRestore();
  1457. }
  1458. Options.CurrentOptions.DisableSystemRestore = !toggleSwitch4.Checked;
  1459. }
  1460. private void toggleSwitch5_Click(object sender, EventArgs e)
  1461. {
  1462. if (!toggleSwitch5.Checked)
  1463. {
  1464. Optimize.DisablePrintService();
  1465. }
  1466. else
  1467. {
  1468. Optimize.EnablePrintService();
  1469. }
  1470. Options.CurrentOptions.DisablePrintService = !toggleSwitch5.Checked;
  1471. }
  1472. private void toggleSwitch6_Click(object sender, EventArgs e)
  1473. {
  1474. if (!toggleSwitch6.Checked)
  1475. {
  1476. Optimize.DisableMediaPlayerSharing();
  1477. }
  1478. else
  1479. {
  1480. Optimize.EnableMediaPlayerSharing();
  1481. }
  1482. Options.CurrentOptions.DisableMediaPlayerSharing = !toggleSwitch6.Checked;
  1483. }
  1484. private void toggleSwitch8_Click(object sender, EventArgs e)
  1485. {
  1486. if (!toggleSwitch8.Checked)
  1487. {
  1488. Optimize.DisableErrorReporting();
  1489. }
  1490. else
  1491. {
  1492. Optimize.EnableErrorReporting();
  1493. }
  1494. Options.CurrentOptions.DisableErrorReporting = !toggleSwitch8.Checked;
  1495. }
  1496. private void toggleSwitch9_Click(object sender, EventArgs e)
  1497. {
  1498. if (!toggleSwitch9.Checked)
  1499. {
  1500. Optimize.DisableHomeGroup();
  1501. }
  1502. else
  1503. {
  1504. Optimize.EnableHomeGroup();
  1505. }
  1506. Options.CurrentOptions.DisableHomeGroup = !toggleSwitch9.Checked;
  1507. }
  1508. private void toggleSwitch10_Click(object sender, EventArgs e)
  1509. {
  1510. if (!toggleSwitch10.Checked)
  1511. {
  1512. Optimize.DisableSuperfetch();
  1513. }
  1514. else
  1515. {
  1516. Optimize.EnableSuperfetch();
  1517. }
  1518. Options.CurrentOptions.DisableSuperfetch = !toggleSwitch10.Checked;
  1519. }
  1520. private void toggleSwitch11_Click(object sender, EventArgs e)
  1521. {
  1522. if (!toggleSwitch11.Checked)
  1523. {
  1524. Optimize.DisableTelemetryTasks();
  1525. }
  1526. else
  1527. {
  1528. Optimize.EnableTelemetryTasks();
  1529. }
  1530. Options.CurrentOptions.DisableTelemetryTasks = !toggleSwitch11.Checked;
  1531. }
  1532. private void toggleSwitch12_Click(object sender, EventArgs e)
  1533. {
  1534. if (!toggleSwitch12.Checked)
  1535. {
  1536. Optimize.DisableOffice2016Telemetry();
  1537. }
  1538. else
  1539. {
  1540. Optimize.EnableOffice2016Telemetry();
  1541. }
  1542. Options.CurrentOptions.DisableOffice2016Telemetry = !toggleSwitch12.Checked;
  1543. }
  1544. private void toggleSwitch13_Click(object sender, EventArgs e)
  1545. {
  1546. if (!toggleSwitch13.Checked)
  1547. {
  1548. Optimize.EnableLegacyVolumeSlider();
  1549. }
  1550. else
  1551. {
  1552. Optimize.DisableLegacyVolumeSlider();
  1553. }
  1554. Options.CurrentOptions.EnableLegacyVolumeSlider = !toggleSwitch13.Checked;
  1555. }
  1556. private void toggleSwitch19_Click(object sender, EventArgs e)
  1557. {
  1558. if (!toggleSwitch19.Checked)
  1559. {
  1560. Optimize.EnableTaskbarColor();
  1561. }
  1562. else
  1563. {
  1564. Optimize.DisableTaskbarColor();
  1565. }
  1566. Options.CurrentOptions.EnableTaskbarColor = !toggleSwitch19.Checked;
  1567. }
  1568. private void toggleSwitch18_Click(object sender, EventArgs e)
  1569. {
  1570. if (!toggleSwitch18.Checked)
  1571. {
  1572. Optimize.DisableQuickAccessHistory();
  1573. }
  1574. else
  1575. {
  1576. Optimize.EnableQuickAccessHistory();
  1577. }
  1578. Options.CurrentOptions.DisableQuickAccessHistory = !toggleSwitch18.Checked;
  1579. }
  1580. private void toggleSwitch26_Click(object sender, EventArgs e)
  1581. {
  1582. if (!toggleSwitch26.Checked)
  1583. {
  1584. Optimize.DisableStartMenuAds();
  1585. }
  1586. else
  1587. {
  1588. Optimize.EnableStartMenuAds();
  1589. }
  1590. Options.CurrentOptions.DisableStartMenuAds = !toggleSwitch26.Checked;
  1591. }
  1592. private void toggleSwitch27_Click(object sender, EventArgs e)
  1593. {
  1594. if (!toggleSwitch27.Checked)
  1595. {
  1596. Optimize.EnableDarkTheme();
  1597. }
  1598. else
  1599. {
  1600. Optimize.EnableLightTheme();
  1601. }
  1602. Options.CurrentOptions.EnableDarkTheme = !toggleSwitch27.Checked;
  1603. }
  1604. private void toggleSwitch14_Click(object sender, EventArgs e)
  1605. {
  1606. if (!toggleSwitch14.Checked)
  1607. {
  1608. Task t = new Task(() => Optimize.UninstallOneDrive());
  1609. t.Start();
  1610. }
  1611. else
  1612. {
  1613. Task t = new Task(() => Optimize.InstallOneDrive());
  1614. t.Start();
  1615. }
  1616. Options.CurrentOptions.UninstallOneDrive = !toggleSwitch14.Checked;
  1617. }
  1618. private void toggleSwitch25_Click(object sender, EventArgs e)
  1619. {
  1620. if (!toggleSwitch25.Checked)
  1621. {
  1622. Optimize.DisableMyPeople();
  1623. }
  1624. else
  1625. {
  1626. Optimize.EnableMyPeople();
  1627. }
  1628. Options.CurrentOptions.DisableMyPeople = !toggleSwitch25.Checked;
  1629. }
  1630. private void toggleSwitch24_Click(object sender, EventArgs e)
  1631. {
  1632. if (!toggleSwitch24.Checked)
  1633. {
  1634. Optimize.DisableAutomaticUpdates();
  1635. }
  1636. else
  1637. {
  1638. Optimize.EnableAutomaticUpdates();
  1639. }
  1640. Options.CurrentOptions.DisableAutomaticUpdates = !toggleSwitch24.Checked;
  1641. }
  1642. private void toggleSwitch30_Click(object sender, EventArgs e)
  1643. {
  1644. if (!toggleSwitch30.Checked)
  1645. {
  1646. Optimize.ExcludeDrivers();
  1647. }
  1648. else
  1649. {
  1650. Optimize.IncludeDrivers();
  1651. }
  1652. Options.CurrentOptions.ExcludeDrivers = !toggleSwitch30.Checked;
  1653. }
  1654. private void toggleSwitch23_Click(object sender, EventArgs e)
  1655. {
  1656. if (!toggleSwitch23.Checked)
  1657. {
  1658. Optimize.DisableTelemetryServices();
  1659. }
  1660. else
  1661. {
  1662. Optimize.EnableTelemetryServices();
  1663. }
  1664. Options.CurrentOptions.DisableTelemetryServices = !toggleSwitch23.Checked;
  1665. }
  1666. private void toggleSwitch21_Click(object sender, EventArgs e)
  1667. {
  1668. if (!toggleSwitch21.Checked)
  1669. {
  1670. Optimize.DisablePrivacyOptions();
  1671. }
  1672. else
  1673. {
  1674. Optimize.EnablePrivacyOptions();
  1675. }
  1676. Options.CurrentOptions.DisablePrivacyOptions = !toggleSwitch21.Checked;
  1677. }
  1678. private void toggleSwitch16_Click(object sender, EventArgs e)
  1679. {
  1680. if (!toggleSwitch16.Checked)
  1681. {
  1682. Optimize.DisableCortana();
  1683. }
  1684. else
  1685. {
  1686. Optimize.EnableCortana();
  1687. }
  1688. Options.CurrentOptions.DisableCortana = !toggleSwitch16.Checked;
  1689. }
  1690. private void toggleSwitch20_Click(object sender, EventArgs e)
  1691. {
  1692. if (!toggleSwitch20.Checked)
  1693. {
  1694. Optimize.DisableSensorServices();
  1695. }
  1696. else
  1697. {
  1698. Optimize.EnableSensorServices();
  1699. }
  1700. Options.CurrentOptions.DisableSensorServices = !toggleSwitch20.Checked;
  1701. }
  1702. private void toggleSwitch29_Click(object sender, EventArgs e)
  1703. {
  1704. if (!toggleSwitch29.Checked)
  1705. {
  1706. Optimize.DisableWindowsInk();
  1707. }
  1708. else
  1709. {
  1710. Optimize.EnableWindowsInk();
  1711. }
  1712. Options.CurrentOptions.DisableWindowsInk = !toggleSwitch29.Checked;
  1713. }
  1714. private void toggleSwitch28_Click(object sender, EventArgs e)
  1715. {
  1716. if (!toggleSwitch28.Checked)
  1717. {
  1718. Optimize.DisableSpellingAndTypingFeatures();
  1719. }
  1720. else
  1721. {
  1722. Optimize.EnableSpellingAndTypingFeatures();
  1723. }
  1724. Options.CurrentOptions.DisableSpellingTyping = !toggleSwitch28.Checked;
  1725. }
  1726. private void toggleSwitch17_Click(object sender, EventArgs e)
  1727. {
  1728. if (!toggleSwitch17.Checked)
  1729. {
  1730. Optimize.DisableXboxLive();
  1731. }
  1732. else
  1733. {
  1734. Optimize.EnableXboxLive();
  1735. }
  1736. Options.CurrentOptions.DisableXboxLive = !toggleSwitch17.Checked;
  1737. }
  1738. private void toggleSwitch15_Click(object sender, EventArgs e)
  1739. {
  1740. if (!toggleSwitch15.Checked)
  1741. {
  1742. Optimize.DisableGameBar();
  1743. }
  1744. else
  1745. {
  1746. Optimize.EnableGameBar();
  1747. }
  1748. Options.CurrentOptions.DisableGameBar = !toggleSwitch15.Checked;
  1749. }
  1750. private void toggleSwitch31_Click(object sender, EventArgs e)
  1751. {
  1752. if (!toggleSwitch31.Checked)
  1753. {
  1754. Optimize.DisableOneDrive();
  1755. }
  1756. else
  1757. {
  1758. Optimize.EnableOneDrive();
  1759. }
  1760. Options.CurrentOptions.DisableOneDrive = !toggleSwitch31.Checked;
  1761. }
  1762. private void toggleSwitch32_Click(object sender, EventArgs e)
  1763. {
  1764. if (!toggleSwitch32.Checked)
  1765. {
  1766. Optimize.DisableCompatibilityAssistant();
  1767. }
  1768. else
  1769. {
  1770. Optimize.EnableCompatibilityAssistant();
  1771. }
  1772. Options.CurrentOptions.DisableCompatibilityAssistant = !toggleSwitch32.Checked;
  1773. }
  1774. private void btnUpdate_Click(object sender, EventArgs e)
  1775. {
  1776. CheckForUpdate();
  1777. }
  1778. private void btnChangelog_Click(object sender, EventArgs e)
  1779. {
  1780. try
  1781. {
  1782. Process.Start(_changelogLink);
  1783. }
  1784. catch (Exception ex)
  1785. {
  1786. ErrorLogger.LogError("MainForm.btnChangelog_Click", ex.Message, ex.StackTrace);
  1787. MessageBox.Show(ex.Message, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
  1788. }
  1789. }
  1790. private void chkReadOnly_CheckedChanged(object sender, EventArgs e)
  1791. {
  1792. HostsHelper.ReadOnly(chkReadOnly.Checked);
  1793. button47.Enabled = !chkReadOnly.Checked;
  1794. button46.Enabled = !chkReadOnly.Checked;
  1795. button42.Enabled = !chkReadOnly.Checked;
  1796. button41.Enabled = !chkReadOnly.Checked;
  1797. linkLabel4.Enabled = !chkReadOnly.Checked;
  1798. chkBlock.Enabled = !chkReadOnly.Checked;
  1799. txtDomain.Enabled = !chkReadOnly.Checked;
  1800. txtIP.Enabled = !chkReadOnly.Checked;
  1801. button1.Enabled = !chkReadOnly.Checked;
  1802. button2.Enabled = !chkReadOnly.Checked;
  1803. button3.Enabled = !chkReadOnly.Checked;
  1804. button4.Enabled = !chkReadOnly.Checked;
  1805. txtIP.Focus();
  1806. }
  1807. private void button1_Click(object sender, EventArgs e)
  1808. {
  1809. HostsHelper.AdblockBasic();
  1810. GetHostsEntries();
  1811. }
  1812. private void button3_Click(object sender, EventArgs e)
  1813. {
  1814. HostsHelper.AdBlockWithPorn();
  1815. GetHostsEntries();
  1816. }
  1817. private void button2_Click(object sender, EventArgs e)
  1818. {
  1819. HostsHelper.AdBlockWithSocial();
  1820. GetHostsEntries();
  1821. }
  1822. private void button4_Click(object sender, EventArgs e)
  1823. {
  1824. HostsHelper.AdBlockWithSocial();
  1825. GetHostsEntries();
  1826. }
  1827. private void RenderAppDownloaderBusy()
  1828. {
  1829. btnDownloadApps.Enabled = false;
  1830. button5.Enabled = false;
  1831. txtDownloadFolder.ReadOnly = true;
  1832. linkLabel1.Visible = false;
  1833. }
  1834. private void RenderAppDownloaderFree()
  1835. {
  1836. btnDownloadApps.Enabled = true;
  1837. button5.Enabled = true;
  1838. txtDownloadFolder.ReadOnly = false;
  1839. linkLabel1.Visible = !string.IsNullOrEmpty(downloadLog);
  1840. txtDownloadStatus.Text = "Finished";
  1841. }
  1842. string appNameTemp = string.Empty;
  1843. int maxCount = 0;
  1844. int count = 0;
  1845. Process p;
  1846. string downloadLog = string.Empty;
  1847. private async void btnDownloadApps_Click(object sender, EventArgs e)
  1848. {
  1849. if (!Directory.Exists(txtDownloadFolder.Text))
  1850. {
  1851. MessageBox.Show("Download folder specified is not valid!", "Invalid folder", MessageBoxButtons.OK, MessageBoxIcon.Information);
  1852. return;
  1853. }
  1854. RenderAppDownloaderBusy();
  1855. maxCount = 0;
  1856. count = 0;
  1857. downloadLog = string.Empty;
  1858. foreach (Control c in Utilities.GetSelfAndChildrenRecursive(appsTab))
  1859. {
  1860. if (c.Name == "cAutoInstall") continue;
  1861. if (c is ColoredCheckBox && ((ColoredCheckBox)c).Checked) maxCount++;
  1862. }
  1863. ColoredCheckBox currentCheck;
  1864. Control[] temp;
  1865. foreach (FeedApp x in AppsFromFeed)
  1866. {
  1867. if (string.IsNullOrEmpty(x.Tag)) continue;
  1868. temp = appsTab.Controls.Find(x.Tag, true);
  1869. if (temp.Count() == 0) continue;
  1870. currentCheck = (ColoredCheckBox)temp[0];
  1871. if (currentCheck == null) continue;
  1872. if (!currentCheck.Checked) continue;
  1873. appNameTemp = x.Title;
  1874. if (c64.Checked)
  1875. {
  1876. count++;
  1877. if (string.IsNullOrEmpty(x.Link64))
  1878. {
  1879. downloadLog += "• " + x.Title + ":" + Environment.NewLine + "No 64-bit available, downloading 32-bit" + Environment.NewLine + Environment.NewLine;
  1880. await DownloadApp(x, false);
  1881. }
  1882. else
  1883. {
  1884. await DownloadApp(x, true);
  1885. }
  1886. }
  1887. else
  1888. {
  1889. count++;
  1890. if (!string.IsNullOrEmpty(x.Link))
  1891. {
  1892. await DownloadApp(x, false);
  1893. }
  1894. else
  1895. {
  1896. downloadLog += "• " + x.Title + ":" + Environment.NewLine + "No 32-bit available, skipping" + Environment.NewLine + Environment.NewLine;
  1897. }
  1898. }
  1899. }
  1900. if (cAutoInstall.Checked)
  1901. {
  1902. count = 0;
  1903. foreach (string a in Directory.GetFiles(txtDownloadFolder.Text, "*.*", SearchOption.TopDirectoryOnly))
  1904. {
  1905. using (p = new Process())
  1906. {
  1907. count++;
  1908. p.StartInfo.FileName = a;
  1909. p.EnableRaisingEvents = true;
  1910. p.StartInfo.WorkingDirectory = txtDownloadFolder.Text;
  1911. // APP-SPECIFIC HACKS //
  1912. if (a.Contains("Sumatra")) p.StartInfo.Arguments = " -install";
  1913. // *** //
  1914. txtDownloadStatus.Text = string.Format("{0}/{1} - Installing {2} ...", count, maxCount, Path.GetFileNameWithoutExtension(a));
  1915. await p.RunAsync();
  1916. };
  1917. }
  1918. }
  1919. // reset all checkboxes
  1920. foreach (Control c in Utilities.GetSelfAndChildrenRecursive(appsTab))
  1921. {
  1922. if (c.Name == "cAutoInstall") continue;
  1923. if (c is ColoredCheckBox && ((ColoredCheckBox)c).Checked) ((ColoredCheckBox)c).Checked = false;
  1924. }
  1925. RenderAppDownloaderFree();
  1926. }
  1927. string fileExtension = ".exe";
  1928. private async Task DownloadApp(FeedApp app, bool pref64)
  1929. {
  1930. try
  1931. {
  1932. using (WebClient downloader = new WebClient())
  1933. {
  1934. downloader.Headers.Add("User-Agent: Other");
  1935. downloader.Encoding = Encoding.UTF8;
  1936. downloader.DownloadProgressChanged += Downloader_DownloadProgressChanged;
  1937. downloader.DownloadFileCompleted += Downloader_DownloadFileCompleted;
  1938. if (pref64)
  1939. {
  1940. if (app.Link64.Contains(".msi"))
  1941. {
  1942. fileExtension = ".msi";
  1943. }
  1944. else
  1945. {
  1946. fileExtension = ".exe";
  1947. }
  1948. await downloader.DownloadFileTaskAsync(new Uri(app.Link64), Path.Combine(txtDownloadFolder.Text, app.Title + "-x64" + fileExtension));
  1949. }
  1950. else
  1951. {
  1952. if (app.Link.Contains(".msi"))
  1953. {
  1954. fileExtension = ".msi";
  1955. }
  1956. else
  1957. {
  1958. fileExtension = ".exe";
  1959. }
  1960. await downloader.DownloadFileTaskAsync(new Uri(app.Link), Path.Combine(txtDownloadFolder.Text, app.Title + "-x86" + fileExtension));
  1961. }
  1962. }
  1963. }
  1964. catch (Exception ex)
  1965. {
  1966. ErrorLogger.LogError("MainForm.DownloadApp", ex.Message, ex.StackTrace);
  1967. downloadLog += "• " + app.Title + ":" + Environment.NewLine + "Link is no longer valid!" + Environment.NewLine + Environment.NewLine;
  1968. if (pref64) try { File.Delete(Path.Combine(txtDownloadFolder.Text, app.Title + "-x64.exe")); } catch { }
  1969. if (!pref64) try { File.Delete(Path.Combine(txtDownloadFolder.Text, app.Title + "-x86.exe")); } catch { }
  1970. if (pref64) try { File.Delete(Path.Combine(txtDownloadFolder.Text, app.Title + "-x64.msi")); } catch { }
  1971. if (!pref64) try { File.Delete(Path.Combine(txtDownloadFolder.Text, app.Title + "-x86.msi")); } catch { }
  1972. }
  1973. }
  1974. private void Downloader_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
  1975. {
  1976. this.BeginInvoke((MethodInvoker)delegate
  1977. {
  1978. //txtDownloadStatus.Text = "Finished";
  1979. });
  1980. }
  1981. int tempProgress;
  1982. private void Downloader_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
  1983. {
  1984. this.BeginInvoke((MethodInvoker)delegate
  1985. {
  1986. double bytesIn = double.Parse(e.BytesReceived.ToString());
  1987. double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
  1988. double percentage = bytesIn / totalBytes * 100;
  1989. tempProgress = int.Parse(Math.Truncate(percentage).ToString());
  1990. // if Content-Length header is missing, just show an animation
  1991. if (Math.Abs(tempProgress) > 100)
  1992. {
  1993. txtDownloadStatus.Text = string.Format("({1}/{2}) - {0} ...", appNameTemp, count, maxCount);
  1994. progressDownloader.Style = ProgressBarStyle.Marquee;
  1995. }
  1996. // if not, show actual progress
  1997. else
  1998. {
  1999. txtDownloadStatus.Text = string.Format("({1}/{2}) - {0} - {3} / {4}", appNameTemp, count, maxCount, ByteSize.FromBytes(e.BytesReceived).ToString("MB"), ByteSize.FromBytes(e.TotalBytesToReceive).ToString("MB"));
  2000. progressDownloader.Style = ProgressBarStyle.Continuous;
  2001. progressDownloader.Value = tempProgress;
  2002. }
  2003. });
  2004. }
  2005. private void button5_Click(object sender, EventArgs e)
  2006. {
  2007. FolderBrowserDialog d = new FolderBrowserDialog();
  2008. if (d.ShowDialog() == DialogResult.OK)
  2009. {
  2010. txtDownloadFolder.Text = d.SelectedPath;
  2011. Options.CurrentOptions.AppsFolder = d.SelectedPath;
  2012. Options.SaveSettings();
  2013. }
  2014. }
  2015. private void button6_Click(object sender, EventArgs e)
  2016. {
  2017. Process.Start(txtDownloadFolder.Text);
  2018. }
  2019. private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  2020. {
  2021. InfoForm lf = new InfoForm(downloadLog);
  2022. lf.ShowDialog(this);
  2023. }
  2024. private void txtDownloadFolder_TextChanged(object sender, EventArgs e)
  2025. {
  2026. Options.CurrentOptions.AppsFolder = txtDownloadFolder.Text;
  2027. Options.SaveSettings();
  2028. }
  2029. private void chkOnlyRemovable_CheckedChanged(object sender, EventArgs e)
  2030. {
  2031. GetModernApps(!chkOnlyRemovable.Checked);
  2032. }
  2033. private void btnGetFeed_Click(object sender, EventArgs e)
  2034. {
  2035. GetFeed();
  2036. }
  2037. private void l2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  2038. {
  2039. Process.Start("https://github.com/hellzerg/optimizer");
  2040. }
  2041. private void btnViewLog_Click(object sender, EventArgs e)
  2042. {
  2043. if (File.Exists(ErrorLogger.ErrorLogFile))
  2044. {
  2045. InfoForm iform = new InfoForm(File.ReadAllText(ErrorLogger.ErrorLogFile, Encoding.UTF8));
  2046. iform.ShowDialog();
  2047. }
  2048. else
  2049. {
  2050. MessageBox.Show("There are no errors to show!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
  2051. }
  2052. }
  2053. private void btnOpenConf_Click(object sender, EventArgs e)
  2054. {
  2055. Process.Start(Required.CoreFolder);
  2056. }
  2057. private void btnPing_Click(object sender, EventArgs e)
  2058. {
  2059. PingReply reply1 = Utilities.PingHost(txtPingInput.Text);
  2060. PingReply reply2 = Utilities.PingHost(txtPingInput.Text);
  2061. PingReply reply3 = Utilities.PingHost(txtPingInput.Text);
  2062. }
  2063. private void btnCheckFootprint_Click(object sender, EventArgs e)
  2064. {
  2065. CleanHelper.CheckFootprint();
  2066. }
  2067. }
  2068. }