MainForm.cs 79 KB

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