MainForm.cs 80 KB

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