MainForm.cs 107 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Diagnostics;
  6. using System.Drawing;
  7. using System.Globalization;
  8. using System.IO;
  9. using System.IO.Compression;
  10. using System.Linq;
  11. using System.Net;
  12. using System.Net.NetworkInformation;
  13. using System.Reflection;
  14. using System.Text;
  15. using System.Threading;
  16. using System.Threading.Tasks;
  17. using System.Windows.Forms;
  18. namespace Optimizer
  19. {
  20. public partial class MainForm : Form
  21. {
  22. ListViewColumnSorter _columnSorter;
  23. List<StartupItem> _startUpItems = new List<StartupItem>();
  24. List<StartupBackupItem> _backupItems = new List<StartupBackupItem>();
  25. List<string> _hostsEntries = new List<string>();
  26. List<string> _customCommands = new List<string>();
  27. List<string> _desktopItems = new List<string>();
  28. List<string> _modernApps = new List<string>();
  29. bool _trayMenu = false;
  30. List<PingReply> _pingResults;
  31. string _shodanIP = string.Empty;
  32. PingReply tmpReply;
  33. //NetworkMonitor _networkMonitor;
  34. double uploadSpeed = 0;
  35. double downloadSpeed = 0;
  36. DesktopItemType _desktopItemType = DesktopItemType.Program;
  37. DesktopTypePosition _desktopItemPosition = DesktopTypePosition.Top;
  38. public List<FeedApp> AppsFromFeed = new List<FeedApp>();
  39. readonly string _feedLink = "https://raw.githubusercontent.com/hellzerg/optimizer/master/feed.json";
  40. readonly string _feedImages = "https://raw.githubusercontent.com/hellzerg/optimizer/master/images/feed.zip";
  41. readonly string _licenseLink = "https://www.gnu.org/licenses/gpl-3.0.en.html";
  42. readonly string _openSourceLink = "https://opensource.org/";
  43. readonly string _latestVersionLink = "https://raw.githubusercontent.com/hellzerg/optimizer/master/version.txt";
  44. readonly string _changelogLink = "https://github.com/hellzerg/optimizer/blob/master/CHANGELOG.md";
  45. string _noNewVersionMessage = "You already have the latest version!";
  46. string _betaVersionMessage = "You are using an experimental version!";
  47. readonly string _blockedIP = "0.0.0.0";
  48. string _restartMessage = "Restart to apply changes?";
  49. string _removeStartupItemsMessage = "Are you sure you want to delete these startup items?\n\n";
  50. string _removeHostsEntriesMessage = "Are you sure you want to delete all hosts entries?";
  51. string _removeDesktopItemsMessage = "Are you sure you want to delete all desktop items?";
  52. string _removeModernAppsMessage = "Are you sure you want to uninstall the following app(s)?";
  53. string _errorModernAppsMessage = "The following app(s) couldn't be uninstalled:\n";
  54. string _resetMessage = "Are you sure you want to reset configuration?\n\nThis will reset all your preferences, including any icons you extracted or downloaded using Integrator, but will not touch anything on your computer!";
  55. private string NewVersionMessage(string latestVersion)
  56. {
  57. return Options.TranslationList["newVersion"].ToString().Replace("{LATEST}", latestVersion).Replace("{CURRENT}", Program.GetCurrentVersionTostring());
  58. }
  59. private string NewDownloadLink(string latestVersion)
  60. {
  61. return string.Format("https://github.com/hellzerg/optimizer/releases/download/{0}/Optimizer-{0}.exe", latestVersion);
  62. }
  63. private void CheckForUpdate(bool silentCheck = false)
  64. {
  65. WebClient client = new WebClient
  66. {
  67. Encoding = Encoding.UTF8
  68. };
  69. string latestVersion = string.Empty;
  70. try
  71. {
  72. latestVersion = client.DownloadString(_latestVersionLink).Trim();
  73. }
  74. catch (Exception ex)
  75. {
  76. ErrorLogger.LogError("MainForm.CheckForUpdate", ex.Message, ex.StackTrace);
  77. MessageBox.Show(ex.Message, "Optimizer", MessageBoxButtons.OK, MessageBoxIcon.Information);
  78. }
  79. if (!string.IsNullOrEmpty(latestVersion))
  80. {
  81. if (float.Parse(latestVersion) > Program.GetCurrentVersion())
  82. {
  83. // show UPDATE AVAILABLE on app launch
  84. if (silentCheck)
  85. {
  86. linkUpdate.Visible = true;
  87. return;
  88. }
  89. if (MessageBox.Show(NewVersionMessage(latestVersion), "Optimizer", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  90. {
  91. // PATCHING PROCESS
  92. try
  93. {
  94. Assembly currentAssembly = Assembly.GetEntryAssembly();
  95. if (currentAssembly == null)
  96. {
  97. currentAssembly = Assembly.GetCallingAssembly();
  98. }
  99. string appFolder = Path.GetDirectoryName(currentAssembly.Location);
  100. string appName = Path.GetFileNameWithoutExtension(currentAssembly.Location);
  101. string appExtension = Path.GetExtension(currentAssembly.Location);
  102. string archiveFile = Path.Combine(appFolder, "Optimizer_old" + appExtension);
  103. string appFile = Path.Combine(appFolder, appName + appExtension);
  104. string tempFile = Path.Combine(appFolder, "Optimizer_tmp" + appExtension);
  105. // DOWNLOAD NEW VERSION
  106. client.DownloadFile(NewDownloadLink(latestVersion), tempFile);
  107. // DELETE PREVIOUS BACK-UP
  108. if (File.Exists(archiveFile))
  109. {
  110. File.Delete(archiveFile);
  111. }
  112. // MAKE BACK-UP
  113. File.Move(appFile, archiveFile);
  114. // PATCH
  115. File.Move(tempFile, appFile);
  116. _trayMenu = false;
  117. Application.Restart();
  118. }
  119. catch (Exception ex)
  120. {
  121. ErrorLogger.LogError("MainForm.CheckForUpdate", ex.Message, ex.StackTrace);
  122. MessageBox.Show(ex.Message);
  123. }
  124. }
  125. }
  126. else if (float.Parse(latestVersion) == Program.GetCurrentVersion())
  127. {
  128. if (!silentCheck) MessageBox.Show(_noNewVersionMessage, "Optimizer", MessageBoxButtons.OK, MessageBoxIcon.Information);
  129. }
  130. else
  131. {
  132. if (!silentCheck) MessageBox.Show(_betaVersionMessage, "Optimizer", MessageBoxButtons.OK, MessageBoxIcon.Information);
  133. }
  134. }
  135. }
  136. private void EnableToggleEvents()
  137. {
  138. actionSw.Click += new EventHandler(ToggleSwitch7_Click);
  139. officeTelemetrySw.Click += new EventHandler(toggleSwitch12_Click);
  140. telemetryTasksSw.Click += new EventHandler(toggleSwitch11_Click);
  141. superfetchSw.Click += new EventHandler(toggleSwitch10_Click);
  142. homegroupSw.Click += new EventHandler(toggleSwitch9_Click);
  143. reportingSw.Click += new EventHandler(toggleSwitch8_Click);
  144. mediaSharingSw.Click += new EventHandler(toggleSwitch6_Click);
  145. printSw.Click += new EventHandler(toggleSwitch5_Click);
  146. systemRestoreSw.Click += new EventHandler(toggleSwitch4_Click);
  147. performanceSw.Click += new EventHandler(toggleSwitch1_Click);
  148. defenderSw.Click += new EventHandler(toggleSwitch3_Click);
  149. networkSw.Click += new EventHandler(toggleSwitch2_Click);
  150. darkSw.Click += new EventHandler(toggleSwitch27_Click);
  151. spellSw.Click += new EventHandler(toggleSwitch28_Click);
  152. inkSw.Click += new EventHandler(toggleSwitch29_Click);
  153. driversSw.Click += new EventHandler(toggleSwitch30_Click);
  154. sensorSw.Click += new EventHandler(toggleSwitch20_Click);
  155. privacySw.Click += new EventHandler(toggleSwitch21_Click);
  156. telemetryServicesSw.Click += new EventHandler(toggleSwitch23_Click);
  157. autoUpdatesSw.Click += new EventHandler(toggleSwitch24_Click);
  158. peopleSw.Click += new EventHandler(toggleSwitch25_Click);
  159. adsSw.Click += new EventHandler(toggleSwitch26_Click);
  160. xboxSw.Click += new EventHandler(toggleSwitch17_Click);
  161. cortanaSw.Click += new EventHandler(toggleSwitch16_Click);
  162. gameBarSw.Click += new EventHandler(toggleSwitch15_Click);
  163. uODSw.Click += new EventHandler(toggleSwitch14_Click);
  164. oldMixerSw.Click += new EventHandler(toggleSwitch13_Click);
  165. disableOneDriveSw.Click += new EventHandler(toggleSwitch31_Click);
  166. oldExplorerSw.Click += new EventHandler(toggleSwitch18_Click);
  167. colorBarSw.Click += new EventHandler(toggleSwitch19_Click);
  168. compatSw.Click += new EventHandler(toggleSwitch32_Click);
  169. faxSw.Click += new EventHandler(ToggleSwitch33_Click);
  170. insiderSw.Click += new EventHandler(ToggleSwitch34_Click);
  171. featuresSw.Click += new EventHandler(ToggleSwitch35_Click);
  172. smartScreenSw.Click += new EventHandler(ToggleSwitch36_Click);
  173. ccSw.Click += new EventHandler(ToggleSwitch37_Click);
  174. stickySw.Click += new EventHandler(ToggleSwitch38_Click);
  175. longPathsSw.Click += new EventHandler(ToggleSwitch39_Click);
  176. castSw.Click += new EventHandler(ToggleSwitch40_Click);
  177. leftTaskbarSw.Click += LeftTaskbarSw_Click;
  178. snapAssistSw.Click += SnapAssistSw_Click;
  179. widgetsSw.Click += WidgetsSw_Click;
  180. smallerTaskbarSw.Click += SmallerTaskbarSw_Click;
  181. }
  182. private void SmallerTaskbarSw_Click(object sender, EventArgs e)
  183. {
  184. if (!smallerTaskbarSw.Checked)
  185. {
  186. Optimize.SmallerTaskbar();
  187. }
  188. else
  189. {
  190. Optimize.DefaultTaskbarSize();
  191. }
  192. //Options.CurrentOptions.DisableActionCenter = !actionSw.Checked;
  193. }
  194. private void WidgetsSw_Click(object sender, EventArgs e)
  195. {
  196. if (!widgetsSw.Checked)
  197. {
  198. Optimize.DisableWidgets();
  199. }
  200. else
  201. {
  202. Optimize.EnableWidgets();
  203. }
  204. //Options.CurrentOptions.DisableActionCenter = !actionSw.Checked;
  205. }
  206. private void SnapAssistSw_Click(object sender, EventArgs e)
  207. {
  208. if (!snapAssistSw.Checked)
  209. {
  210. Optimize.DisableSnapAssist();
  211. }
  212. else
  213. {
  214. Optimize.EnableSnapAssist();
  215. }
  216. //Options.CurrentOptions.DisableActionCenter = !actionSw.Checked;
  217. }
  218. private void LeftTaskbarSw_Click(object sender, EventArgs e)
  219. {
  220. if (!leftTaskbarSw.Checked)
  221. {
  222. Optimize.AlignTaskbarToLeft();
  223. }
  224. else
  225. {
  226. Optimize.AlignTaskbarToCenter();
  227. }
  228. //Options.CurrentOptions.DisableActionCenter = !actionSw.Checked;
  229. }
  230. private void SetHelpBoxTranslation()
  231. {
  232. helpBox.SetToolTip(performanceSw, Options.TranslationList["performanceTip"].ToString());
  233. helpBox.SetToolTip(networkSw, Options.TranslationList["networkTip"].ToString());
  234. helpBox.SetToolTip(defenderSw, Options.TranslationList["defenderTip"].ToString());
  235. helpBox.SetToolTip(smartScreenSw, Options.TranslationList["smartScreenTip"].ToString());
  236. helpBox.SetToolTip(systemRestoreSw, Options.TranslationList["systemRestoreTip"].ToString());
  237. helpBox.SetToolTip(reportingSw, Options.TranslationList["reportingTip"].ToString());
  238. helpBox.SetToolTip(telemetryTasksSw, Options.TranslationList["telemetryTasksTip"].ToString());
  239. helpBox.SetToolTip(officeTelemetrySw, Options.TranslationList["officeTelemetryTip"].ToString());
  240. helpBox.SetToolTip(printSw, Options.TranslationList["printTip"].ToString());
  241. helpBox.SetToolTip(faxSw, Options.TranslationList["faxTip"].ToString());
  242. helpBox.SetToolTip(mediaSharingSw, Options.TranslationList["mediaSharingTip"].ToString());
  243. helpBox.SetToolTip(stickySw, Options.TranslationList["stickyTip"].ToString());
  244. helpBox.SetToolTip(homegroupSw, Options.TranslationList["homegroupTip"].ToString());
  245. helpBox.SetToolTip(superfetchSw, Options.TranslationList["superfetchTip"].ToString());
  246. helpBox.SetToolTip(compatSw, Options.TranslationList["compatTip"].ToString());
  247. helpBox.SetToolTip(disableOneDriveSw, Options.TranslationList["disableOneDriveTip"].ToString());
  248. helpBox.SetToolTip(oldMixerSw, Options.TranslationList["oldMixerTip"].ToString());
  249. helpBox.SetToolTip(colorBarSw, Options.TranslationList["colorBarTip"].ToString());
  250. helpBox.SetToolTip(oldExplorerSw, Options.TranslationList["oldExplorerTip"].ToString());
  251. helpBox.SetToolTip(adsSw, Options.TranslationList["adsTip"].ToString());
  252. helpBox.SetToolTip(darkSw, Options.TranslationList["darkTip"].ToString());
  253. helpBox.SetToolTip(uODSw, Options.TranslationList["uODTip"].ToString());
  254. helpBox.SetToolTip(peopleSw, Options.TranslationList["peopleTip"].ToString());
  255. helpBox.SetToolTip(longPathsSw, Options.TranslationList["longPathsTip"].ToString());
  256. helpBox.SetToolTip(inkSw, Options.TranslationList["inkTip"].ToString());
  257. helpBox.SetToolTip(spellSw, Options.TranslationList["spellTip"].ToString());
  258. helpBox.SetToolTip(xboxSw, Options.TranslationList["xboxTip"].ToString());
  259. helpBox.SetToolTip(actionSw, Options.TranslationList["actionTip"].ToString());
  260. helpBox.SetToolTip(autoUpdatesSw, Options.TranslationList["autoUpdatesTip"].ToString());
  261. helpBox.SetToolTip(driversSw, Options.TranslationList["driversTip"].ToString());
  262. helpBox.SetToolTip(telemetryServicesSw, Options.TranslationList["telemetryServicesTip"].ToString());
  263. helpBox.SetToolTip(privacySw, Options.TranslationList["privacyTip"].ToString());
  264. helpBox.SetToolTip(ccSw, Options.TranslationList["ccTip"].ToString());
  265. helpBox.SetToolTip(cortanaSw, Options.TranslationList["cortanaTip"].ToString());
  266. helpBox.SetToolTip(sensorSw, Options.TranslationList["sensorTip"].ToString());
  267. helpBox.SetToolTip(castSw, Options.TranslationList["castTip"].ToString());
  268. helpBox.SetToolTip(gameBarSw, Options.TranslationList["gameBarTip"].ToString());
  269. helpBox.SetToolTip(insiderSw, Options.TranslationList["insiderTip"].ToString());
  270. helpBox.SetToolTip(featuresSw, Options.TranslationList["featuresTip"].ToString());
  271. helpBox.ToolTipTitle = Options.TranslationList["tipWhatsThis"].ToString();
  272. }
  273. private void ToggleSwitch7_Click(object sender, EventArgs e)
  274. {
  275. if (!actionSw.Checked)
  276. {
  277. Optimize.DisableActionCenter();
  278. }
  279. else
  280. {
  281. Optimize.EnableActionCenter();
  282. }
  283. Options.CurrentOptions.DisableActionCenter = !actionSw.Checked;
  284. }
  285. private void ToggleSwitch40_Click(object sender, EventArgs e)
  286. {
  287. if (!castSw.Checked)
  288. {
  289. Optimize.RemoveCastToDevice();
  290. }
  291. else
  292. {
  293. Optimize.AddCastToDevice();
  294. }
  295. Options.CurrentOptions.RemoveCastToDevice = !castSw.Checked;
  296. }
  297. private void ToggleSwitch39_Click(object sender, EventArgs e)
  298. {
  299. if (!longPathsSw.Checked)
  300. {
  301. Optimize.EnableLongPaths();
  302. }
  303. else
  304. {
  305. Optimize.DisableLongPaths();
  306. }
  307. Options.CurrentOptions.EnableLongPaths = !longPathsSw.Checked;
  308. }
  309. private void ToggleSwitch38_Click(object sender, EventArgs e)
  310. {
  311. if (!stickySw.Checked)
  312. {
  313. Optimize.DisableStickyKeys();
  314. }
  315. else
  316. {
  317. Optimize.EnableStickyKeys();
  318. }
  319. Options.CurrentOptions.DisableStickyKeys = !stickySw.Checked;
  320. }
  321. private void ToggleSwitch37_Click(object sender, EventArgs e)
  322. {
  323. if (!ccSw.Checked)
  324. {
  325. Optimize.DisableCloudClipboard();
  326. }
  327. else
  328. {
  329. Optimize.EnableCloudClipboard();
  330. }
  331. Options.CurrentOptions.DisableCloudClipboard = !ccSw.Checked;
  332. }
  333. private void ToggleSwitch36_Click(object sender, EventArgs e)
  334. {
  335. if (!smartScreenSw.Checked)
  336. {
  337. Optimize.DisableSmartScreen();
  338. }
  339. else
  340. {
  341. Optimize.EnableSmartScreen();
  342. }
  343. Options.CurrentOptions.DisableSmartScreen = !smartScreenSw.Checked;
  344. }
  345. private void ToggleSwitch35_Click(object sender, EventArgs e)
  346. {
  347. if (!featuresSw.Checked)
  348. {
  349. Optimize.DisableForcedFeatureUpdates();
  350. }
  351. else
  352. {
  353. Optimize.EnableForcedFeatureUpdates();
  354. }
  355. Options.CurrentOptions.DisableFeatureUpdates = !featuresSw.Checked;
  356. }
  357. private void ToggleSwitch34_Click(object sender, EventArgs e)
  358. {
  359. if (!insiderSw.Checked)
  360. {
  361. Optimize.DisableInsiderService();
  362. }
  363. else
  364. {
  365. Optimize.EnableInsiderService();
  366. }
  367. Options.CurrentOptions.DisableInsiderService = !insiderSw.Checked;
  368. }
  369. private void ToggleSwitch33_Click(object sender, EventArgs e)
  370. {
  371. if (!faxSw.Checked)
  372. {
  373. Optimize.DisableFaxService();
  374. }
  375. else
  376. {
  377. Optimize.EnableFaxService();
  378. }
  379. Options.CurrentOptions.DisableFaxService = !faxSw.Checked;
  380. }
  381. private void LoadSettings()
  382. {
  383. switch (Options.CurrentOptions.Color)
  384. {
  385. case Theme.Caramel:
  386. radioCaramel.Checked = true;
  387. break;
  388. case Theme.Lime:
  389. radioLime.Checked = true;
  390. break;
  391. case Theme.Magma:
  392. radioMagma.Checked = true;
  393. break;
  394. case Theme.Minimal:
  395. radioMinimal.Checked = true;
  396. break;
  397. case Theme.Ocean:
  398. radioOcean.Checked = true;
  399. break;
  400. case Theme.Zerg:
  401. radioZerg.Checked = true;
  402. break;
  403. }
  404. }
  405. // INIT
  406. public MainForm()
  407. {
  408. InitializeComponent();
  409. CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
  410. CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("en-US");
  411. CheckForIllegalCrossThreadCalls = false;
  412. EnableToggleEvents();
  413. // theming
  414. Options.ApplyTheme(this);
  415. launcherMenu.Renderer = new ToolStripRendererMaterial();
  416. progressDownloader.BackColor = Options.ForegroundColor;
  417. progressDownloader.ForeColor = Options.ForegroundAccentColor;
  418. // quick access
  419. _trayMenu = Options.CurrentOptions.EnableTray;
  420. quickAccessToggle.Checked = Options.CurrentOptions.EnableTray;
  421. launcherIcon.Visible = Options.CurrentOptions.EnableTray;
  422. // help tips
  423. helpBox.Active = Options.CurrentOptions.ShowHelp;
  424. helpTipsToggle.Checked = Options.CurrentOptions.ShowHelp;
  425. // fix SSL/TLS error when contacting internet
  426. ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
  427. // initial states
  428. chkOnlyRemovable.Checked = true;
  429. checkDefaultIcon.Checked = true;
  430. radioProgram.Checked = true;
  431. radioTop.Checked = true;
  432. c64.Checked = Environment.Is64BitOperatingSystem;
  433. c32.Checked = !Environment.Is64BitOperatingSystem;
  434. // EXPERIMENTAL message
  435. lblLab.Visible = Program.EXPERIMENTAL_BUILD;
  436. // Windows version, architecture, .NET Framework
  437. txtOS.Text = Utilities.GetOS();
  438. txtBitness.Text = Utilities.GetBitness();
  439. txtNetFw.Text = ".NET Framework " + Utilities.GetNETFramework();
  440. if (Utilities.CurrentWindowsVersion == WindowsVersion.Unsupported)
  441. {
  442. tabCollection.TabPages.Remove(universalTab);
  443. tabCollection.TabPages.Remove(windows8Tab);
  444. tabCollection.TabPages.Remove(windows10Tab);
  445. tabCollection.TabPages.Remove(windows11Tab);
  446. tabCollection.TabPages.Remove(modernAppsTab);
  447. }
  448. if (Utilities.CurrentWindowsVersion == WindowsVersion.Windows7)
  449. {
  450. LoadUniversalToggleStates();
  451. tabCollection.TabPages.Remove(windows8Tab);
  452. tabCollection.TabPages.Remove(windows10Tab);
  453. tabCollection.TabPages.Remove(windows11Tab);
  454. tabCollection.TabPages.Remove(modernAppsTab);
  455. }
  456. if (Utilities.CurrentWindowsVersion == WindowsVersion.Windows8)
  457. {
  458. LoadUniversalToggleStates();
  459. LoadWindowsVIIIToggleStates();
  460. tabCollection.TabPages.Remove(windows10Tab);
  461. tabCollection.TabPages.Remove(windows11Tab);
  462. GetModernApps(false);
  463. }
  464. if (Utilities.CurrentWindowsVersion == WindowsVersion.Windows10)
  465. {
  466. LoadUniversalToggleStates();
  467. LoadWindowsXToggleStates();
  468. tabCollection.TabPages.Remove(windows8Tab);
  469. tabCollection.TabPages.Remove(windows11Tab);
  470. GetModernApps(false);
  471. txtOS.Text += string.Format(" ({0})", Utilities.GetWindows10Build());
  472. }
  473. //if (Utilities.CurrentWindowsVersion == WindowsVersion.Windows11)
  474. //{
  475. // // load toggles ...
  476. // tabCollection.TabPages.Remove(windows8Tab);
  477. // //tabCollection.TabPages.Remove(windows10Tab);
  478. // GetModernApps(false);
  479. //}
  480. _columnSorter = new ListViewColumnSorter();
  481. listStartupItems.ListViewItemSorter = _columnSorter;
  482. GetStartupItems();
  483. GetHostsEntries();
  484. GetDesktopItems();
  485. GetCustomCommands();
  486. GetFeed();
  487. GetFootprint();
  488. LoadSettings();
  489. // Translation-related
  490. if (Options.CurrentOptions.LanguageCode == LanguageCode.EN)
  491. {
  492. radioEnglish.Checked = true;
  493. Translate(true);
  494. }
  495. else
  496. {
  497. Translate();
  498. }
  499. if (Options.CurrentOptions.LanguageCode == LanguageCode.RU) radioRussian.Checked = true;
  500. if (Options.CurrentOptions.LanguageCode == LanguageCode.TR) radioTurkish.Checked = true;
  501. if (Options.CurrentOptions.LanguageCode == LanguageCode.EL) radioHellenic.Checked = true;
  502. if (Options.CurrentOptions.LanguageCode == LanguageCode.DE) radioGerman.Checked = true;
  503. if (Options.CurrentOptions.LanguageCode == LanguageCode.PT) radioPortuguese.Checked = true;
  504. Program.MainForm = this;
  505. if (string.IsNullOrEmpty(Options.CurrentOptions.AppsFolder))
  506. {
  507. txtDownloadFolder.Text = Path.Combine(Application.StartupPath, "Optimizer Downloads");
  508. Options.CurrentOptions.AppsFolder = Path.Combine(Application.StartupPath, "Optimizer Downloads");
  509. Directory.CreateDirectory(Options.CurrentOptions.AppsFolder);
  510. Options.SaveSettings();
  511. }
  512. else
  513. {
  514. if (!Directory.Exists(Options.CurrentOptions.AppsFolder))
  515. {
  516. try
  517. {
  518. Directory.CreateDirectory(Options.CurrentOptions.AppsFolder);
  519. }
  520. catch (Exception ex)
  521. {
  522. txtDownloadFolder.Text = string.Empty;
  523. ErrorLogger.LogError("MainForm.INIT", ex.Message, ex.StackTrace);
  524. }
  525. }
  526. txtDownloadFolder.Text = Options.CurrentOptions.AppsFolder;
  527. }
  528. if (!Program.EXPERIMENTAL_BUILD && Utilities.IsInternetAvailable()) CheckForUpdate(true);
  529. if (Program.EXPERIMENTAL_BUILD)
  530. {
  531. btnUpdate.Enabled = false;
  532. lblUpdateDisabled.Visible = true;
  533. }
  534. // network monitoring
  535. //_networkMonitor = new NetworkMonitor();
  536. }
  537. //private void NetworkMonitoring()
  538. //{
  539. // while (true)
  540. // {
  541. // downloadSpeed = 0;
  542. // uploadSpeed = 0;
  543. // foreach (NetworkAdapter adapter in _networkMonitor.Adapters)
  544. // {
  545. // //adapter.Refresh();
  546. // downloadSpeed += Math.Round(adapter.DownloadSpeedMbps, 2);
  547. // uploadSpeed += Math.Round(adapter.UploadSpeedMbps, 2);
  548. // }
  549. // this.Text = string.Format("Optimizer - DOWN: {0} UP: {1}", downloadSpeed, uploadSpeed);
  550. // Thread.Sleep(1000);
  551. // }
  552. //}
  553. private void Translate(bool skipFull = false)
  554. {
  555. Dictionary<string, string> translationList = Options.TranslationList.ToObject<Dictionary<string, string>>();
  556. if (Environment.Is64BitOperatingSystem)
  557. {
  558. translationList["txtBitness"] = translationList["txtBitness"].Replace("{BITS}", translationList["c64"]);
  559. }
  560. else
  561. {
  562. translationList["txtBitness"] = translationList["txtBitness"].Replace("{BITS}", translationList["c32"]);
  563. }
  564. SetHelpBoxTranslation();
  565. if (!skipFull)
  566. {
  567. _noNewVersionMessage = Options.TranslationList["noNewVersion"];
  568. _betaVersionMessage = Options.TranslationList["betaVersion"];
  569. _restartMessage = Options.TranslationList["restartAndApply"];
  570. _removeStartupItemsMessage = Options.TranslationList["removeAllStartup"];
  571. _removeHostsEntriesMessage = Options.TranslationList["removeAllHosts"];
  572. _removeDesktopItemsMessage = Options.TranslationList["removeAllItems"];
  573. _removeModernAppsMessage = Options.TranslationList["removeModernApps"];
  574. _errorModernAppsMessage = Options.TranslationList["errorModernApps"];
  575. _resetMessage = Options.TranslationList["resetMessage"];
  576. listStartupItems.Columns[0].Text = translationList["startupItemName"];
  577. listStartupItems.Columns[1].Text = translationList["startupItemLocation"];
  578. listStartupItems.Columns[2].Text = translationList["startupItemType"];
  579. trayStartup.Text = translationList["trayStartup"];
  580. trayCleaner.Text = translationList["trayCleaner"];
  581. trayPinger.Text = translationList["trayPinger"];
  582. trayHosts.Text = translationList["trayHosts"];
  583. trayAD.Text = translationList["trayAD"];
  584. trayRestartExplorer.Text = translationList["trayRestartExplorer"];
  585. trayExit.Text = translationList["trayExit"];
  586. Control element;
  587. foreach (var x in translationList)
  588. {
  589. if (x.Key == null || x.Key == string.Empty) continue;
  590. element = this.Controls.Find(x.Key, true).FirstOrDefault();
  591. if (element == null) continue;
  592. if (element is ToggleSwitch)
  593. {
  594. ((ToggleSwitch)element).OnText = x.Value;
  595. continue;
  596. }
  597. element.Text = x.Value;
  598. }
  599. }
  600. txtVersion.Text = txtVersion.Text.Replace("{VN}", Program.GetCurrentVersionTostring());
  601. }
  602. private void GetFootprint()
  603. {
  604. ByteSize footprint = CleanHelper.CheckFootprint();
  605. lblFootprint.Text = footprint.ToString();
  606. }
  607. private void GetFeed()
  608. {
  609. WebClient client = new WebClient
  610. {
  611. Encoding = Encoding.UTF8
  612. };
  613. client.Headers.Add("Cache-Control", "no-cache");
  614. try
  615. {
  616. string tmpImageFileName = string.Empty;
  617. string tmpDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Optimizer-tmp");
  618. Directory.CreateDirectory(tmpDir);
  619. client.DownloadFile(_feedImages, Path.Combine(tmpDir, "feed-images.raw"));
  620. using (FileStream fs = new FileStream(Path.Combine(tmpDir, "feed-images.raw"), FileMode.Open))
  621. using (ZipArchive zip = new ZipArchive(fs))
  622. {
  623. var zipEntries = zip.Entries;
  624. try
  625. {
  626. string feed = client.DownloadString(_feedLink);
  627. AppsFromFeed = JsonConvert.DeserializeObject<List<FeedApp>>(feed);
  628. AppCard appCard;
  629. groupSystemTools.Controls.Clear();
  630. groupInternet.Controls.Clear();
  631. groupCoding.Controls.Clear();
  632. groupSoundVideo.Controls.Clear();
  633. foreach (FeedApp x in AppsFromFeed)
  634. {
  635. appCard = new AppCard();
  636. appCard.AutoSize = true;
  637. appCard.Anchor = AnchorStyles.None;
  638. appCard.Anchor = AnchorStyles.Top | AnchorStyles.Left;
  639. appCard.appTitle.Text = x.Title;
  640. appCard.appTitle.Name = x.Tag;
  641. appCard.appImage.SizeMode = PictureBoxSizeMode.Zoom;
  642. tmpImageFileName = x.Image.Substring(x.Image.LastIndexOf("/") + 1, x.Image.Length - (x.Image.LastIndexOf("/") + 1));
  643. appCard.appImage.Image = Image.FromStream(zipEntries.First(ifn => ifn.Name == tmpImageFileName).Open());
  644. switch (x.Group)
  645. {
  646. case "SystemTools":
  647. appCard.Location = new Point(0, groupSystemTools.Controls.Count * 30);
  648. groupSystemTools.Controls.Add(appCard);
  649. break;
  650. case "Internet":
  651. appCard.Location = new Point(0, groupInternet.Controls.Count * 30);
  652. groupInternet.Controls.Add(appCard);
  653. break;
  654. case "Coding":
  655. appCard.Location = new Point(0, groupCoding.Controls.Count * 30);
  656. groupCoding.Controls.Add(appCard);
  657. break;
  658. case "GraphicsSound":
  659. appCard.Location = new Point(0, groupSoundVideo.Controls.Count * 30);
  660. groupSoundVideo.Controls.Add(appCard);
  661. break;
  662. default:
  663. break;
  664. }
  665. }
  666. // UI handling
  667. btnDownloadApps.Enabled = true;
  668. txtFeedError.Visible = false;
  669. }
  670. catch (Exception ex)
  671. {
  672. btnDownloadApps.Enabled = false;
  673. txtFeedError.Visible = true;
  674. ErrorLogger.LogError("MainForm.GetFeed", ex.Message, ex.StackTrace);
  675. }
  676. }
  677. }
  678. catch (Exception ex)
  679. {
  680. btnDownloadApps.Enabled = false;
  681. txtFeedError.Visible = true;
  682. ErrorLogger.LogError("MainForm.GetFeed-DownloadImages", ex.Message, ex.StackTrace);
  683. }
  684. }
  685. private void CleanPC()
  686. {
  687. try
  688. {
  689. if (checkTemp.Checked)
  690. {
  691. CleanHelper.CleanTemporaries();
  692. }
  693. if (checkMiniDumps.Checked)
  694. {
  695. CleanHelper.CleanMiniDumps();
  696. }
  697. if (checkMediaCache.Checked)
  698. {
  699. CleanHelper.CleanMediaPlayersCache();
  700. }
  701. if (checkLogs.Checked)
  702. {
  703. CleanHelper.CleanLogs();
  704. }
  705. if (checkErrorReports.Checked)
  706. {
  707. CleanHelper.CleanErrorReports();
  708. }
  709. if (checkBin.Checked)
  710. {
  711. CleanHelper.EmptyRecycleBin();
  712. }
  713. }
  714. catch (Exception ex)
  715. {
  716. ErrorLogger.LogError("MainForm.CleanPC", ex.Message, ex.StackTrace);
  717. }
  718. finally
  719. {
  720. Cleaning(false);
  721. GetFootprint();
  722. }
  723. }
  724. private bool FixRegistry()
  725. {
  726. bool changeDetected = false;
  727. try
  728. {
  729. if (checkFirewall.Checked)
  730. {
  731. Utilities.EnableFirewall();
  732. changeDetected = true;
  733. }
  734. if (checkCommandPrompt.Checked)
  735. {
  736. Utilities.EnableCommandPrompt();
  737. changeDetected = true;
  738. }
  739. if (checkControlPanel.Checked)
  740. {
  741. Utilities.EnableControlPanel();
  742. changeDetected = true;
  743. }
  744. if (checkFolderOptions.Checked)
  745. {
  746. Utilities.EnableFolderOptions();
  747. changeDetected = true;
  748. }
  749. if (checkRunDialog.Checked)
  750. {
  751. Utilities.EnableRunDialog();
  752. changeDetected = true;
  753. }
  754. if (checkContextMenu.Checked)
  755. {
  756. Utilities.EnableContextMenu();
  757. changeDetected = true;
  758. }
  759. if (checkTaskManager.Checked)
  760. {
  761. Utilities.EnableTaskManager();
  762. changeDetected = true;
  763. }
  764. if (checkRegistryEditor.Checked)
  765. {
  766. Utilities.EnableRegistryEditor();
  767. changeDetected = true;
  768. }
  769. }
  770. catch (Exception ex)
  771. {
  772. ErrorLogger.LogError("MainForm.FixRegistry", ex.Message, ex.StackTrace);
  773. }
  774. return changeDetected;
  775. }
  776. private void LoadUniversalToggleStates()
  777. {
  778. performanceSw.Checked = Options.CurrentOptions.EnablePerformanceTweaks;
  779. networkSw.Checked = Options.CurrentOptions.DisableNetworkThrottling;
  780. defenderSw.Checked = Options.CurrentOptions.DisableWindowsDefender;
  781. systemRestoreSw.Checked = Options.CurrentOptions.DisableSystemRestore;
  782. printSw.Checked = Options.CurrentOptions.DisablePrintService;
  783. mediaSharingSw.Checked = Options.CurrentOptions.DisableMediaPlayerSharing;
  784. reportingSw.Checked = Options.CurrentOptions.DisableErrorReporting;
  785. homegroupSw.Checked = Options.CurrentOptions.DisableHomeGroup;
  786. superfetchSw.Checked = Options.CurrentOptions.DisableSuperfetch;
  787. telemetryTasksSw.Checked = Options.CurrentOptions.DisableTelemetryTasks;
  788. officeTelemetrySw.Checked = Options.CurrentOptions.DisableOffice2016Telemetry;
  789. compatSw.Checked = Options.CurrentOptions.DisableCompatibilityAssistant;
  790. faxSw.Checked = Options.CurrentOptions.DisableFaxService;
  791. smartScreenSw.Checked = Options.CurrentOptions.DisableSmartScreen;
  792. stickySw.Checked = Options.CurrentOptions.DisableStickyKeys;
  793. }
  794. private void LoadWindowsVIIIToggleStates()
  795. {
  796. disableOneDriveSw.Checked = Options.CurrentOptions.DisableOneDrive;
  797. }
  798. private void LoadWindowsXToggleStates()
  799. {
  800. oldMixerSw.Checked = Options.CurrentOptions.EnableLegacyVolumeSlider;
  801. uODSw.Checked = Options.CurrentOptions.UninstallOneDrive;
  802. gameBarSw.Checked = Options.CurrentOptions.DisableGameBar;
  803. cortanaSw.Checked = Options.CurrentOptions.DisableCortana;
  804. xboxSw.Checked = Options.CurrentOptions.DisableXboxLive;
  805. oldExplorerSw.Checked = Options.CurrentOptions.DisableQuickAccessHistory;
  806. colorBarSw.Checked = Options.CurrentOptions.EnableTaskbarColor;
  807. sensorSw.Checked = Options.CurrentOptions.DisableSensorServices;
  808. privacySw.Checked = Options.CurrentOptions.DisablePrivacyOptions;
  809. telemetryServicesSw.Checked = Options.CurrentOptions.DisableTelemetryServices;
  810. autoUpdatesSw.Checked = Options.CurrentOptions.DisableAutomaticUpdates;
  811. peopleSw.Checked = Options.CurrentOptions.DisableMyPeople;
  812. adsSw.Checked = Options.CurrentOptions.DisableStartMenuAds;
  813. darkSw.Checked = Options.CurrentOptions.EnableDarkTheme;
  814. spellSw.Checked = Options.CurrentOptions.DisableSpellingTyping;
  815. inkSw.Checked = Options.CurrentOptions.DisableWindowsInk;
  816. driversSw.Checked = Options.CurrentOptions.ExcludeDrivers;
  817. insiderSw.Checked = Options.CurrentOptions.DisableInsiderService;
  818. featuresSw.Checked = Options.CurrentOptions.DisableFeatureUpdates;
  819. ccSw.Checked = Options.CurrentOptions.DisableCloudClipboard;
  820. longPathsSw.Checked = Options.CurrentOptions.EnableLongPaths;
  821. castSw.Checked = Options.CurrentOptions.RemoveCastToDevice;
  822. actionSw.Checked = Options.CurrentOptions.DisableActionCenter;
  823. }
  824. private void Main_Load(object sender, EventArgs e)
  825. {
  826. }
  827. private void GetDesktopItems()
  828. {
  829. _desktopItems = Integrator.GetDesktopItems();
  830. listDesktopItems.Items.Clear();
  831. for (int i = 0; i < _desktopItems.Count; i++)
  832. {
  833. if (!string.IsNullOrEmpty(_desktopItems[i]))
  834. {
  835. listDesktopItems.Items.Add(_desktopItems[i]);
  836. }
  837. }
  838. if (_desktopItems.Count > 0) listDesktopItems.SelectedIndex = 0;
  839. }
  840. private void GetHostsEntries()
  841. {
  842. ((Control)this.hostsEditorTab).Enabled = false;
  843. _hostsEntries = HostsHelper.GetHostsEntries();
  844. listHostEntries.Items.Clear();
  845. listHostEntries.Items.AddRange(_hostsEntries.ToArray());
  846. chkReadOnly.Checked = HostsHelper.GetReadOnly();
  847. addHostB.Enabled = !chkReadOnly.Checked;
  848. removeAllHostsB.Enabled = !chkReadOnly.Checked;
  849. removeHostB.Enabled = !chkReadOnly.Checked;
  850. refreshHostsB.Enabled = !chkReadOnly.Checked;
  851. linkRestoreDefault.Enabled = !chkReadOnly.Checked;
  852. chkBlock.Enabled = !chkReadOnly.Checked;
  853. txtDomain.Enabled = !chkReadOnly.Checked;
  854. txtIP.Enabled = !chkReadOnly.Checked;
  855. adblockBasic.Enabled = !chkReadOnly.Checked;
  856. adblockS.Enabled = !chkReadOnly.Checked;
  857. adblockP.Enabled = !chkReadOnly.Checked;
  858. adblockUlti.Enabled = !chkReadOnly.Checked;
  859. ((Control)this.hostsEditorTab).Enabled = true;
  860. if (_hostsEntries.Count > 0) listHostEntries.SelectedIndex = 0;
  861. }
  862. private void GetStartupItems()
  863. {
  864. _startUpItems = Utilities.GetStartupItems();
  865. listStartupItems.Items.Clear();
  866. for (int i = 0; i < _startUpItems.Count; i++)
  867. {
  868. ListViewItem list = new ListViewItem(_startUpItems[i].Name);
  869. list.SubItems.Add(_startUpItems[i].FileLocation);
  870. list.SubItems.Add(_startUpItems[i].ToString());
  871. listStartupItems.Items.Add(list);
  872. }
  873. }
  874. private void GetModernApps(bool showAll)
  875. {
  876. uninstallModernAppsButton.Enabled = false;
  877. refreshModernAppsButton.Enabled = false;
  878. listModernApps.Enabled = false;
  879. listModernApps.Items.Clear();
  880. _modernApps = Utilities.GetModernApps(showAll);
  881. foreach (string x in _modernApps)
  882. {
  883. listModernApps.Items.Add(x);
  884. }
  885. uninstallModernAppsButton.Enabled = true;
  886. refreshModernAppsButton.Enabled = true;
  887. listModernApps.Enabled = true;
  888. if (_modernApps.Count > 0) listModernApps.SelectedIndex = 0;
  889. }
  890. private async void UninstallModernApps()
  891. {
  892. string selectedApps = string.Empty;
  893. if (listModernApps.CheckedItems.Count > 0)
  894. {
  895. foreach (string x in listModernApps.CheckedItems)
  896. {
  897. if (string.IsNullOrEmpty(selectedApps))
  898. {
  899. selectedApps = x;
  900. }
  901. else
  902. {
  903. selectedApps += Environment.NewLine + x;
  904. }
  905. }
  906. if (MessageBox.Show(_removeModernAppsMessage + "\n\n" + selectedApps, "Optimizer", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  907. {
  908. uninstallModernAppsButton.Enabled = false;
  909. refreshModernAppsButton.Enabled = false;
  910. listModernApps.Enabled = false;
  911. bool errorOccured = false;
  912. string failedApps = string.Empty;
  913. foreach (string app in listModernApps.CheckedItems)
  914. {
  915. await Task.Run(() => errorOccured = Utilities.UninstallModernApp(app));
  916. if (errorOccured)
  917. {
  918. failedApps += Environment.NewLine + app;
  919. }
  920. }
  921. if (!string.IsNullOrEmpty(failedApps))
  922. {
  923. MessageBox.Show(_errorModernAppsMessage + failedApps, "Optimizer", MessageBoxButtons.OK, MessageBoxIcon.Information);
  924. }
  925. GetModernApps(!chkOnlyRemovable.Checked);
  926. }
  927. }
  928. }
  929. private void GetCustomCommands()
  930. {
  931. _customCommands = Integrator.GetCustomCommands();
  932. listCustomCommands.Items.Clear();
  933. foreach (string s in _customCommands)
  934. {
  935. listCustomCommands.Items.Add(s);
  936. }
  937. if (_customCommands.Count > 0) listCustomCommands.SelectedIndex = 0;
  938. }
  939. private void Main_FormClosing(object sender, FormClosingEventArgs e)
  940. {
  941. if (_trayMenu)
  942. {
  943. e.Cancel = true;
  944. this.Hide();
  945. }
  946. else
  947. {
  948. Options.CurrentOptions.AppsFolder = txtDownloadFolder.Text;
  949. Options.SaveSettings();
  950. }
  951. }
  952. private void button39_Click(object sender, EventArgs e)
  953. {
  954. HelperForm f = new HelperForm(this, MessageType.Restart, _restartMessage);
  955. f.ShowDialog();
  956. }
  957. private void button43_Click(object sender, EventArgs e)
  958. {
  959. HelperForm f = new HelperForm(this, MessageType.Restart, _restartMessage);
  960. f.ShowDialog();
  961. }
  962. private void button44_Click(object sender, EventArgs e)
  963. {
  964. HelperForm f = new HelperForm(this, MessageType.Restart, _restartMessage);
  965. f.ShowDialog();
  966. }
  967. private void button45_Click(object sender, EventArgs e)
  968. {
  969. HelperForm f = new HelperForm(this, MessageType.Restart, _restartMessage);
  970. f.ShowDialog();
  971. }
  972. private void checkSelectAll_CheckedChanged(object sender, EventArgs e)
  973. {
  974. checkTemp.Checked = checkSelectAll.Checked;
  975. checkMiniDumps.Checked = checkSelectAll.Checked;
  976. checkMediaCache.Checked = checkSelectAll.Checked;
  977. checkLogs.Checked = checkSelectAll.Checked;
  978. checkBin.Checked = checkSelectAll.Checked;
  979. checkErrorReports.Checked = checkSelectAll.Checked;
  980. }
  981. private void button20_Click(object sender, EventArgs e)
  982. {
  983. Cleaning(true);
  984. Task t = new Task(() => CleanPC());
  985. t.Start();
  986. }
  987. private void Cleaning(bool enabled)
  988. {
  989. cleanDriveB.Enabled = !enabled;
  990. cleanDriveB.Text = (enabled) ? "..." : Options.TranslationList["cleanDriveB"];
  991. }
  992. private void button32_Click(object sender, EventArgs e)
  993. {
  994. if (listStartupItems.CheckedItems.Count <= 0) return;
  995. string report = string.Empty;
  996. foreach (ListViewItem i in listStartupItems.CheckedItems)
  997. {
  998. report += i.Text + Environment.NewLine;
  999. }
  1000. if (MessageBox.Show(_removeStartupItemsMessage + Environment.NewLine + Environment.NewLine + report, "Optimizer", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1001. {
  1002. foreach (int x in listStartupItems.CheckedIndices)
  1003. {
  1004. _startUpItems[x].Remove();
  1005. }
  1006. GetStartupItems();
  1007. }
  1008. //foreach (int x in listStartupItems.CheckedIndices)
  1009. //{
  1010. // MessageBox.Show(x.ToString());
  1011. //}
  1012. //if (listStartupItems.SelectedItems.Count == 1)
  1013. //{
  1014. // _startUpItems[listStartupItems.SelectedIndices[0]].Remove();
  1015. // GetStartupItems();
  1016. //}
  1017. }
  1018. internal void RemoveAllStartupItems()
  1019. {
  1020. foreach (ListViewItem i in listStartupItems.Items)
  1021. {
  1022. _startUpItems[i.Index].Remove();
  1023. }
  1024. GetStartupItems();
  1025. }
  1026. // REMOVE ALL STARTUP ITEMS BUTTON
  1027. //private void button22_Click(object sender, EventArgs e)
  1028. //{
  1029. // if (listStartupItems.Items.Count > 0)
  1030. // {
  1031. // HelperForm r = new HelperForm(this, MessageType.Startup, _removeStartupItemsMessage);
  1032. // r.ShowDialog(this);
  1033. // }
  1034. //}
  1035. private void button31_Click(object sender, EventArgs e)
  1036. {
  1037. if (listStartupItems.SelectedItems.Count == 1)
  1038. {
  1039. _startUpItems[listStartupItems.SelectedIndices[0]].LocateFile();
  1040. }
  1041. }
  1042. private void checkEnableAll_CheckedChanged(object sender, EventArgs e)
  1043. {
  1044. checkTaskManager.Checked = checkEnableAll.Checked;
  1045. checkCommandPrompt.Checked = checkEnableAll.Checked;
  1046. checkControlPanel.Checked = checkEnableAll.Checked;
  1047. checkFolderOptions.Checked = checkEnableAll.Checked;
  1048. checkRunDialog.Checked = checkEnableAll.Checked;
  1049. checkContextMenu.Checked = checkEnableAll.Checked;
  1050. checkFirewall.Checked = checkEnableAll.Checked;
  1051. checkRegistryEditor.Checked = checkEnableAll.Checked;
  1052. }
  1053. private void button33_Click(object sender, EventArgs e)
  1054. {
  1055. bool flag = FixRegistry();
  1056. if (flag)
  1057. {
  1058. panel2.Enabled = false;
  1059. regFixB.Enabled = false;
  1060. if (checkRestartExplorer.Checked)
  1061. {
  1062. Utilities.RestartExplorer();
  1063. }
  1064. panel2.Enabled = true;
  1065. regFixB.Enabled = true;
  1066. }
  1067. }
  1068. private void pictureBox1_Click(object sender, EventArgs e)
  1069. {
  1070. AboutForm f = new AboutForm();
  1071. f.ShowDialog(this);
  1072. }
  1073. private void button37_Click(object sender, EventArgs e)
  1074. {
  1075. GetStartupItems();
  1076. }
  1077. private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1078. {
  1079. HostsHelper.LocateHosts();
  1080. }
  1081. private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1082. {
  1083. HostsEditorForm f = new HostsEditorForm();
  1084. f.ShowDialog(this);
  1085. GetHostsEntries();
  1086. }
  1087. private void linkLabel4_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1088. {
  1089. HostsHelper.RestoreDefaultHosts();
  1090. GetHostsEntries();
  1091. }
  1092. private void button47_Click(object sender, EventArgs e)
  1093. {
  1094. if ((txtIP.Text != string.Empty) && (txtDomain.Text != string.Empty))
  1095. {
  1096. string ip = txtIP.Text.Trim();
  1097. string domain = txtDomain.Text.Trim();
  1098. string recommendedDomain = string.Empty;
  1099. if (!domain.StartsWith("www."))
  1100. {
  1101. recommendedDomain = "www." + domain;
  1102. }
  1103. else
  1104. {
  1105. recommendedDomain = domain.Replace("www.", string.Empty);
  1106. }
  1107. HostsHelper.AddEntry(HostsHelper.SanitizeEntry(ip) + " " + HostsHelper.SanitizeEntry(domain));
  1108. if (!string.IsNullOrEmpty(recommendedDomain))
  1109. {
  1110. HostsHelper.AddEntry(HostsHelper.SanitizeEntry(ip) + " " + HostsHelper.SanitizeEntry(recommendedDomain));
  1111. }
  1112. GetHostsEntries();
  1113. txtIP.Clear();
  1114. txtDomain.Clear();
  1115. chkBlock.Checked = false;
  1116. }
  1117. }
  1118. private void button41_Click(object sender, EventArgs e)
  1119. {
  1120. GetHostsEntries();
  1121. }
  1122. private void button42_Click(object sender, EventArgs e)
  1123. {
  1124. if (listHostEntries.SelectedItems.Count == 1)
  1125. {
  1126. HostsHelper.RemoveEntry(listHostEntries.SelectedItem.ToString().Replace(" : ", " "));
  1127. GetHostsEntries();
  1128. }
  1129. }
  1130. private void button46_Click(object sender, EventArgs e)
  1131. {
  1132. if (listHostEntries.Items.Count > 0)
  1133. {
  1134. HelperForm r = new HelperForm(this, MessageType.Hosts, _removeHostsEntriesMessage);
  1135. r.ShowDialog(this);
  1136. }
  1137. }
  1138. internal void RemoveAllHostsEntries()
  1139. {
  1140. List<string> collection = new List<string>();
  1141. foreach (string item in listHostEntries.Items)
  1142. {
  1143. collection.Add(item.Replace(" : ", " "));
  1144. }
  1145. HostsHelper.RemoveAllEntries(collection);
  1146. GetHostsEntries();
  1147. }
  1148. private void aio_SelectedIndexChanged(object sender, EventArgs e)
  1149. {
  1150. if (tabCollection.SelectedTab == hostsEditorTab) txtIP.Focus();
  1151. if (tabCollection.SelectedTab == pingerTab)
  1152. {
  1153. txtPingInput.Focus();
  1154. //_networkMonitor.StartMonitoring();
  1155. //NetworkMonitoring();
  1156. }
  1157. //else
  1158. //{
  1159. // _networkMonitor.StopMonitoring();
  1160. //}
  1161. }
  1162. private void button48_Click(object sender, EventArgs e)
  1163. {
  1164. defineCommandDialog.ShowDialog();
  1165. }
  1166. private void button50_Click(object sender, EventArgs e)
  1167. {
  1168. if (!string.IsNullOrEmpty(txtRunFile.Text) && !string.IsNullOrEmpty(txtRunKeyword.Text))
  1169. {
  1170. Integrator.CreateCustomCommand(txtRunFile.Text, txtRunKeyword.Text);
  1171. txtRunFile.Clear();
  1172. txtRunKeyword.Clear();
  1173. GetCustomCommands();
  1174. }
  1175. }
  1176. private void DefineCmd_FileOk(object sender, CancelEventArgs e)
  1177. {
  1178. txtRunFile.Text = defineCommandDialog.FileName;
  1179. txtRunKeyword.Text = Path.GetFileNameWithoutExtension(txtRunFile.Text).ToLower();
  1180. }
  1181. private void button59_Click(object sender, EventArgs e)
  1182. {
  1183. Utilities.ImportRegistryScript(Required.ReadyMadeMenusFolder + "\\PowerMenu.reg");
  1184. GetDesktopItems();
  1185. }
  1186. private void button53_Click(object sender, EventArgs e)
  1187. {
  1188. Utilities.ImportRegistryScript(Required.ReadyMadeMenusFolder + "\\SystemTools.reg");
  1189. GetDesktopItems();
  1190. }
  1191. private void button54_Click(object sender, EventArgs e)
  1192. {
  1193. Utilities.ImportRegistryScript(Required.ReadyMadeMenusFolder + "\\WindowsApps.reg");
  1194. GetDesktopItems();
  1195. }
  1196. private void button51_Click(object sender, EventArgs e)
  1197. {
  1198. Utilities.ImportRegistryScript(Required.ReadyMadeMenusFolder + "\\SystemShortcuts.reg");
  1199. GetDesktopItems();
  1200. }
  1201. private void button57_Click(object sender, EventArgs e)
  1202. {
  1203. Utilities.ImportRegistryScript(Required.ReadyMadeMenusFolder + "\\DesktopShortcuts.reg");
  1204. GetDesktopItems();
  1205. }
  1206. private void button60_Click(object sender, EventArgs e)
  1207. {
  1208. GetDesktopItems();
  1209. }
  1210. private void button61_Click(object sender, EventArgs e)
  1211. {
  1212. if (listDesktopItems.SelectedItems.Count == 1)
  1213. {
  1214. Integrator.RemoveItem(listDesktopItems.SelectedItem.ToString());
  1215. GetDesktopItems();
  1216. }
  1217. }
  1218. internal void RemoveAllDesktopItems()
  1219. {
  1220. List<string> collection = new List<string>();
  1221. foreach (string item in listDesktopItems.Items)
  1222. {
  1223. collection.Add(item);
  1224. }
  1225. Integrator.RemoveAllItems(collection);
  1226. GetDesktopItems();
  1227. }
  1228. private void button62_Click(object sender, EventArgs e)
  1229. {
  1230. if (listDesktopItems.Items.Count > 0)
  1231. {
  1232. HelperForm r = new HelperForm(this, MessageType.Integrator, _removeDesktopItemsMessage);
  1233. r.ShowDialog(this);
  1234. }
  1235. }
  1236. private void radioProgram_CheckedChanged(object sender, EventArgs e)
  1237. {
  1238. if (radioProgram.Checked)
  1239. {
  1240. btnBrowseItem.Enabled = true;
  1241. txtItem.Clear();
  1242. checkDefaultIcon.Checked = true;
  1243. txtIcon.Enabled = false;
  1244. btnBrowseIcon.Enabled = false;
  1245. itemtoaddgroup.Text = Options.TranslationList["itemtoaddgroup"];
  1246. checkDefaultIcon.Visible = true;
  1247. checkDefaultIcon.Text = Options.TranslationList["checkDefaultIcon"];
  1248. txtItemName.Clear();
  1249. txtItem.ReadOnly = true;
  1250. txtIcon.ReadOnly = true;
  1251. _desktopItemType = DesktopItemType.Program;
  1252. }
  1253. }
  1254. private void radioFolder_CheckedChanged(object sender, EventArgs e)
  1255. {
  1256. if (radioFolder.Checked)
  1257. {
  1258. checkDefaultIcon.Checked = true;
  1259. btnBrowseItem.Enabled = true;
  1260. txtItem.Clear();
  1261. itemtoaddgroup.Text = Options.TranslationList["folderToAdd"];
  1262. checkDefaultIcon.Text = Options.TranslationList["checkDefaultFolderIcon"];
  1263. txtItemName.Clear();
  1264. txtItem.ReadOnly = true;
  1265. txtIcon.ReadOnly = true;
  1266. _desktopItemType = DesktopItemType.Folder;
  1267. }
  1268. }
  1269. private void radioLink_CheckedChanged(object sender, EventArgs e)
  1270. {
  1271. if (radioLink.Checked)
  1272. {
  1273. checkDefaultIcon.Checked = true;
  1274. checkDefaultIcon.Text = Options.TranslationList["checkFavicon"];
  1275. btnBrowseItem.Enabled = false;
  1276. itemtoaddgroup.Text = Options.TranslationList["linkToAdd"];
  1277. checkDefaultIcon.Visible = true;
  1278. txtItem.Text = "http://";
  1279. txtItemName.Clear();
  1280. txtItem.ReadOnly = false;
  1281. txtIcon.ReadOnly = true;
  1282. _desktopItemType = DesktopItemType.Link;
  1283. }
  1284. }
  1285. private void radioFile_CheckedChanged(object sender, EventArgs e)
  1286. {
  1287. if (radioFile.Checked)
  1288. {
  1289. checkDefaultIcon.Checked = true;
  1290. checkDefaultIcon.Text = Options.TranslationList["checkNoIcon"];
  1291. btnBrowseItem.Enabled = true;
  1292. itemtoaddgroup.Text = Options.TranslationList["fileToAdd"];
  1293. checkDefaultIcon.Visible = true;
  1294. txtItem.Clear();
  1295. txtItemName.Clear();
  1296. txtItem.ReadOnly = true;
  1297. txtIcon.ReadOnly = true;
  1298. _desktopItemType = DesktopItemType.File;
  1299. }
  1300. }
  1301. private void radioCommand_CheckedChanged(object sender, EventArgs e)
  1302. {
  1303. if (radioCommand.Checked)
  1304. {
  1305. btnBrowseItem.Enabled = false;
  1306. txtItem.Clear();
  1307. checkDefaultIcon.Checked = true;
  1308. txtIcon.Enabled = false;
  1309. btnBrowseIcon.Enabled = false;
  1310. itemtoaddgroup.Text = Options.TranslationList["commandToAdd"];
  1311. checkDefaultIcon.Visible = true;
  1312. checkDefaultIcon.Text = Options.TranslationList["checkNoIcon"];
  1313. txtItemName.Clear();
  1314. txtItem.ReadOnly = false;
  1315. txtIcon.ReadOnly = true;
  1316. _desktopItemType = DesktopItemType.Command;
  1317. }
  1318. }
  1319. private void checkDefaultIcon_CheckedChanged(object sender, EventArgs e)
  1320. {
  1321. if (checkDefaultIcon.Checked)
  1322. {
  1323. txtIcon.Clear();
  1324. txtIcon.Enabled = false;
  1325. btnBrowseIcon.Enabled = false;
  1326. }
  1327. else
  1328. {
  1329. txtIcon.Clear();
  1330. txtIcon.Enabled = true;
  1331. btnBrowseIcon.Enabled = true;
  1332. }
  1333. }
  1334. private void btnBrowseItem_Click(object sender, EventArgs e)
  1335. {
  1336. switch (_desktopItemType)
  1337. {
  1338. case DesktopItemType.Program:
  1339. defineProgramDialog.ShowDialog();
  1340. break;
  1341. case DesktopItemType.Folder:
  1342. defineFolderDialog.ShowDialog();
  1343. txtItem.Text = defineFolderDialog.SelectedPath;
  1344. int i = defineFolderDialog.SelectedPath.LastIndexOf("\\");
  1345. txtItemName.Text = defineFolderDialog.SelectedPath.Remove(0, i + 1);
  1346. break;
  1347. case DesktopItemType.File:
  1348. defineFileDialog.ShowDialog();
  1349. break;
  1350. }
  1351. }
  1352. private void DefineProgramDialog_FileOk(object sender, CancelEventArgs e)
  1353. {
  1354. txtItem.Text = defineProgramDialog.FileName;
  1355. txtItemName.Text = defineProgramDialog.SafeFileName.Replace(".exe", string.Empty);
  1356. }
  1357. private void DefineFileDialog_FileOk(object sender, CancelEventArgs e)
  1358. {
  1359. txtItem.Text = defineFileDialog.FileName;
  1360. txtItemName.Text = defineFileDialog.SafeFileName;
  1361. }
  1362. private void btnBrowseIcon_Click(object sender, EventArgs e)
  1363. {
  1364. switch (_desktopItemType)
  1365. {
  1366. case DesktopItemType.Program:
  1367. DefineProgramIconDialog.ShowDialog();
  1368. break;
  1369. case DesktopItemType.Folder:
  1370. DefineFolderIconDialog.ShowDialog();
  1371. break;
  1372. case DesktopItemType.Link:
  1373. DefineURLIconDialog.ShowDialog();
  1374. break;
  1375. case DesktopItemType.File:
  1376. DefineFileIconDialog.ShowDialog();
  1377. break;
  1378. case DesktopItemType.Command:
  1379. DefineCommandIconDialog.ShowDialog();
  1380. break;
  1381. }
  1382. }
  1383. private void DefineProgramIconDialog_FileOk(object sender, CancelEventArgs e)
  1384. {
  1385. txtIcon.Text = DefineProgramIconDialog.FileName;
  1386. if (txtIcon.Text.Contains(".exe"))
  1387. {
  1388. string iconpath = Integrator.ExtractIconFromExecutable(txtItemName.Text, DefineProgramIconDialog.FileName);
  1389. txtIcon.Text = iconpath;
  1390. }
  1391. }
  1392. private void DefineFolderIconDialog_FileOk(object sender, CancelEventArgs e)
  1393. {
  1394. txtIcon.Text = DefineFolderIconDialog.FileName;
  1395. if (txtIcon.Text.Contains(".exe"))
  1396. {
  1397. string iconpath = Integrator.ExtractIconFromExecutable(txtItemName.Text, DefineFolderIconDialog.FileName);
  1398. txtIcon.Text = iconpath;
  1399. }
  1400. }
  1401. private void DefineURLIconDialog_FileOk(object sender, CancelEventArgs e)
  1402. {
  1403. txtIcon.Text = DefineURLIconDialog.FileName;
  1404. if (txtIcon.Text.Contains(".exe"))
  1405. {
  1406. string iconpath = Integrator.ExtractIconFromExecutable(txtItemName.Text, DefineURLIconDialog.FileName);
  1407. txtIcon.Text = iconpath;
  1408. }
  1409. }
  1410. private void DefineFileIconDialog_FileOk(object sender, CancelEventArgs e)
  1411. {
  1412. txtIcon.Text = DefineFileIconDialog.FileName;
  1413. if (txtIcon.Text.Contains(".exe"))
  1414. {
  1415. string iconpath = Integrator.ExtractIconFromExecutable(txtItemName.Text, DefineFileIconDialog.FileName);
  1416. txtIcon.Text = iconpath;
  1417. }
  1418. }
  1419. private void DefineCommandIconDialog_FileOk(object sender, CancelEventArgs e)
  1420. {
  1421. txtIcon.Text = DefineCommandIconDialog.FileName;
  1422. if (txtIcon.Text.Contains(".exe"))
  1423. {
  1424. string iconpath = Integrator.ExtractIconFromExecutable(txtItemName.Text, DefineCommandIconDialog.FileName);
  1425. txtIcon.Text = iconpath;
  1426. }
  1427. }
  1428. private void btnAddItem_Click(object sender, EventArgs e)
  1429. {
  1430. if (!checkDefaultIcon.Checked && (string.IsNullOrEmpty(txtItem.Text) || string.IsNullOrEmpty(txtItemName.Text) || string.IsNullOrEmpty(txtIcon.Text)))
  1431. {
  1432. return;
  1433. }
  1434. if (checkDefaultIcon.Checked && (string.IsNullOrEmpty(txtItem.Text) || string.IsNullOrEmpty(txtItemName.Text)))
  1435. {
  1436. return;
  1437. }
  1438. string icon = string.Empty;
  1439. switch (_desktopItemType)
  1440. {
  1441. case DesktopItemType.Program:
  1442. if (checkDefaultIcon.Checked)
  1443. {
  1444. icon = txtItem.Text;
  1445. }
  1446. else
  1447. {
  1448. icon = txtIcon.Text;
  1449. }
  1450. Integrator.AddItem(txtItemName.Text, txtItem.Text, icon, _desktopItemPosition, checkShift.Checked, DesktopItemType.Program);
  1451. break;
  1452. case DesktopItemType.Folder:
  1453. if (checkDefaultIcon.Checked)
  1454. {
  1455. icon = Integrator.FolderDefaultIcon;
  1456. }
  1457. else
  1458. {
  1459. icon = txtIcon.Text;
  1460. }
  1461. Integrator.AddItem(txtItemName.Text, txtItem.Text, icon, _desktopItemPosition, checkShift.Checked, DesktopItemType.Folder);
  1462. break;
  1463. case DesktopItemType.Link:
  1464. if (checkDefaultIcon.Checked)
  1465. {
  1466. icon = Integrator.DownloadFavicon(txtItem.Text, txtItemName.Text);
  1467. }
  1468. else
  1469. {
  1470. icon = txtIcon.Text;
  1471. }
  1472. Integrator.AddItem(txtItemName.Text, txtItem.Text, icon, _desktopItemPosition, checkShift.Checked, DesktopItemType.Link);
  1473. break;
  1474. case DesktopItemType.File:
  1475. if (!checkDefaultIcon.Checked)
  1476. {
  1477. icon = txtIcon.Text;
  1478. }
  1479. Integrator.AddItem(txtItemName.Text, txtItem.Text, icon, _desktopItemPosition, checkShift.Checked, DesktopItemType.File);
  1480. break;
  1481. case DesktopItemType.Command:
  1482. if (!checkDefaultIcon.Checked)
  1483. {
  1484. icon = txtIcon.Text;
  1485. }
  1486. Integrator.AddItem(txtItemName.Text, txtItem.Text, icon, _desktopItemPosition, checkShift.Checked, DesktopItemType.Command);
  1487. break;
  1488. }
  1489. GetDesktopItems();
  1490. ResetIntegratorForm();
  1491. }
  1492. private void radioTop_CheckedChanged(object sender, EventArgs e)
  1493. {
  1494. if (radioTop.Checked)
  1495. {
  1496. _desktopItemPosition = DesktopTypePosition.Top;
  1497. }
  1498. }
  1499. private void radioMiddle_CheckedChanged(object sender, EventArgs e)
  1500. {
  1501. if (radioMiddle.Checked)
  1502. {
  1503. _desktopItemPosition = DesktopTypePosition.Middle;
  1504. }
  1505. }
  1506. private void radioBottom_CheckedChanged(object sender, EventArgs e)
  1507. {
  1508. if (radioBottom.Checked)
  1509. {
  1510. _desktopItemPosition = DesktopTypePosition.Bottom;
  1511. }
  1512. }
  1513. private void ResetIntegratorForm()
  1514. {
  1515. txtItem.Clear();
  1516. txtIcon.Clear();
  1517. checkDefaultIcon.Checked = true;
  1518. txtItemName.Clear();
  1519. if (radioLink.Checked)
  1520. {
  1521. txtItem.Text = "http://";
  1522. }
  1523. }
  1524. private void radioOcean_CheckedChanged(object sender, EventArgs e)
  1525. {
  1526. Options.CurrentOptions.Color = Theme.Ocean;
  1527. Options.ApplyTheme(this);
  1528. }
  1529. private void radioMagma_CheckedChanged(object sender, EventArgs e)
  1530. {
  1531. Options.CurrentOptions.Color = Theme.Magma;
  1532. Options.ApplyTheme(this);
  1533. }
  1534. private void radioZerg_CheckedChanged(object sender, EventArgs e)
  1535. {
  1536. Options.CurrentOptions.Color = Theme.Zerg;
  1537. Options.ApplyTheme(this);
  1538. }
  1539. private void radioMinimal_CheckedChanged(object sender, EventArgs e)
  1540. {
  1541. Options.CurrentOptions.Color = Theme.Minimal;
  1542. Options.ApplyTheme(this);
  1543. }
  1544. private void radioCaramel_CheckedChanged(object sender, EventArgs e)
  1545. {
  1546. Options.CurrentOptions.Color = Theme.Caramel;
  1547. Options.ApplyTheme(this);
  1548. }
  1549. private void radioLime_CheckedChanged(object sender, EventArgs e)
  1550. {
  1551. Options.CurrentOptions.Color = Theme.Lime;
  1552. Options.ApplyTheme(this);
  1553. }
  1554. private void button64_Click(object sender, EventArgs e)
  1555. {
  1556. if (listStartupItems.SelectedItems.Count == 1)
  1557. {
  1558. _startUpItems[listStartupItems.SelectedIndices[0]].LocateKey();
  1559. }
  1560. }
  1561. private void button66_Click(object sender, EventArgs e)
  1562. {
  1563. Integrator.TakeOwnership(false);
  1564. }
  1565. private void button65_Click(object sender, EventArgs e)
  1566. {
  1567. Integrator.TakeOwnership(true);
  1568. }
  1569. private void listStartupItems_ColumnClick(object sender, ColumnClickEventArgs e)
  1570. {
  1571. if (e.Column == _columnSorter.CurrentColumn)
  1572. {
  1573. if (_columnSorter.SortOrder == SortOrder.Ascending)
  1574. {
  1575. _columnSorter.SortOrder = SortOrder.Descending;
  1576. }
  1577. else
  1578. {
  1579. _columnSorter.SortOrder = SortOrder.Ascending;
  1580. }
  1581. }
  1582. else
  1583. {
  1584. _columnSorter.CurrentColumn = e.Column;
  1585. _columnSorter.SortOrder = SortOrder.Ascending;
  1586. }
  1587. listStartupItems.Sort();
  1588. }
  1589. private void chkBlock_CheckedChanged(object sender, EventArgs e)
  1590. {
  1591. if (chkBlock.Checked)
  1592. {
  1593. txtIP.Text = _blockedIP;
  1594. txtIP.Enabled = false;
  1595. }
  1596. else
  1597. {
  1598. txtIP.Clear();
  1599. txtIP.Enabled = true;
  1600. }
  1601. }
  1602. private void button8_Click(object sender, EventArgs e)
  1603. {
  1604. GetCustomCommands();
  1605. }
  1606. private void button26_Click(object sender, EventArgs e)
  1607. {
  1608. if (listCustomCommands.SelectedItems.Count == 1)
  1609. {
  1610. Integrator.DeleteCustomCommand(listCustomCommands.SelectedItem.ToString());
  1611. GetCustomCommands();
  1612. }
  1613. }
  1614. private void button75_Click(object sender, EventArgs e)
  1615. {
  1616. GetModernApps(!chkOnlyRemovable.Checked);
  1617. }
  1618. private void button74_Click(object sender, EventArgs e)
  1619. {
  1620. UninstallModernApps();
  1621. }
  1622. private void chkSelectAllModernApps_CheckedChanged(object sender, EventArgs e)
  1623. {
  1624. for (int i = 0; i < listModernApps.Items.Count; i++)
  1625. {
  1626. listModernApps.SetItemChecked(i, chkSelectAllModernApps.Checked);
  1627. }
  1628. }
  1629. private void btnResetConfig_Click(object sender, EventArgs e)
  1630. {
  1631. if (MessageBox.Show(_resetMessage, "Optimizer", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1632. {
  1633. Utilities.ResetConfiguration();
  1634. }
  1635. }
  1636. private void toggleSwitch1_Click(object sender, EventArgs e)
  1637. {
  1638. if (!performanceSw.Checked)
  1639. {
  1640. Optimize.EnablePerformanceTweaks();
  1641. }
  1642. else
  1643. {
  1644. Optimize.DisablePerformanceTweaks();
  1645. }
  1646. Options.CurrentOptions.EnablePerformanceTweaks = !performanceSw.Checked;
  1647. }
  1648. private void toggleSwitch2_Click(object sender, EventArgs e)
  1649. {
  1650. if (!networkSw.Checked)
  1651. {
  1652. Optimize.DisableNetworkThrottling();
  1653. }
  1654. else
  1655. {
  1656. Optimize.EnableNetworkThrottling();
  1657. }
  1658. Options.CurrentOptions.DisableNetworkThrottling = !networkSw.Checked;
  1659. }
  1660. private void toggleSwitch3_Click(object sender, EventArgs e)
  1661. {
  1662. if (!defenderSw.Checked)
  1663. {
  1664. Optimize.DisableDefender();
  1665. }
  1666. else
  1667. {
  1668. Optimize.EnableDefender();
  1669. }
  1670. Options.CurrentOptions.DisableWindowsDefender = !defenderSw.Checked;
  1671. }
  1672. private void toggleSwitch4_Click(object sender, EventArgs e)
  1673. {
  1674. if (!systemRestoreSw.Checked)
  1675. {
  1676. Optimize.DisableSystemRestore();
  1677. }
  1678. else
  1679. {
  1680. Optimize.EnableSystemRestore();
  1681. }
  1682. Options.CurrentOptions.DisableSystemRestore = !systemRestoreSw.Checked;
  1683. }
  1684. private void toggleSwitch5_Click(object sender, EventArgs e)
  1685. {
  1686. if (!printSw.Checked)
  1687. {
  1688. Optimize.DisablePrintService();
  1689. }
  1690. else
  1691. {
  1692. Optimize.EnablePrintService();
  1693. }
  1694. Options.CurrentOptions.DisablePrintService = !printSw.Checked;
  1695. }
  1696. private void toggleSwitch6_Click(object sender, EventArgs e)
  1697. {
  1698. if (!mediaSharingSw.Checked)
  1699. {
  1700. Optimize.DisableMediaPlayerSharing();
  1701. }
  1702. else
  1703. {
  1704. Optimize.EnableMediaPlayerSharing();
  1705. }
  1706. Options.CurrentOptions.DisableMediaPlayerSharing = !mediaSharingSw.Checked;
  1707. }
  1708. private void toggleSwitch8_Click(object sender, EventArgs e)
  1709. {
  1710. if (!reportingSw.Checked)
  1711. {
  1712. Optimize.DisableErrorReporting();
  1713. }
  1714. else
  1715. {
  1716. Optimize.EnableErrorReporting();
  1717. }
  1718. Options.CurrentOptions.DisableErrorReporting = !reportingSw.Checked;
  1719. }
  1720. private void toggleSwitch9_Click(object sender, EventArgs e)
  1721. {
  1722. if (!homegroupSw.Checked)
  1723. {
  1724. Optimize.DisableHomeGroup();
  1725. }
  1726. else
  1727. {
  1728. Optimize.EnableHomeGroup();
  1729. }
  1730. Options.CurrentOptions.DisableHomeGroup = !homegroupSw.Checked;
  1731. }
  1732. private void toggleSwitch10_Click(object sender, EventArgs e)
  1733. {
  1734. if (!superfetchSw.Checked)
  1735. {
  1736. Optimize.DisableSuperfetch();
  1737. }
  1738. else
  1739. {
  1740. Optimize.EnableSuperfetch();
  1741. }
  1742. Options.CurrentOptions.DisableSuperfetch = !superfetchSw.Checked;
  1743. }
  1744. private void toggleSwitch11_Click(object sender, EventArgs e)
  1745. {
  1746. if (!telemetryTasksSw.Checked)
  1747. {
  1748. Optimize.DisableTelemetryTasks();
  1749. }
  1750. else
  1751. {
  1752. Optimize.EnableTelemetryTasks();
  1753. }
  1754. Options.CurrentOptions.DisableTelemetryTasks = !telemetryTasksSw.Checked;
  1755. }
  1756. private void toggleSwitch12_Click(object sender, EventArgs e)
  1757. {
  1758. if (!officeTelemetrySw.Checked)
  1759. {
  1760. Optimize.DisableOffice2016Telemetry();
  1761. }
  1762. else
  1763. {
  1764. Optimize.EnableOffice2016Telemetry();
  1765. }
  1766. Options.CurrentOptions.DisableOffice2016Telemetry = !officeTelemetrySw.Checked;
  1767. }
  1768. private void toggleSwitch13_Click(object sender, EventArgs e)
  1769. {
  1770. if (!oldMixerSw.Checked)
  1771. {
  1772. Optimize.EnableLegacyVolumeSlider();
  1773. }
  1774. else
  1775. {
  1776. Optimize.DisableLegacyVolumeSlider();
  1777. }
  1778. Options.CurrentOptions.EnableLegacyVolumeSlider = !oldMixerSw.Checked;
  1779. }
  1780. private void toggleSwitch19_Click(object sender, EventArgs e)
  1781. {
  1782. if (!colorBarSw.Checked)
  1783. {
  1784. Optimize.EnableTaskbarColor();
  1785. }
  1786. else
  1787. {
  1788. Optimize.DisableTaskbarColor();
  1789. }
  1790. Options.CurrentOptions.EnableTaskbarColor = !colorBarSw.Checked;
  1791. }
  1792. private void toggleSwitch18_Click(object sender, EventArgs e)
  1793. {
  1794. if (!oldExplorerSw.Checked)
  1795. {
  1796. Optimize.DisableQuickAccessHistory();
  1797. }
  1798. else
  1799. {
  1800. Optimize.EnableQuickAccessHistory();
  1801. }
  1802. Options.CurrentOptions.DisableQuickAccessHistory = !oldExplorerSw.Checked;
  1803. }
  1804. private void toggleSwitch26_Click(object sender, EventArgs e)
  1805. {
  1806. if (!adsSw.Checked)
  1807. {
  1808. Optimize.DisableStartMenuAds();
  1809. }
  1810. else
  1811. {
  1812. Optimize.EnableStartMenuAds();
  1813. }
  1814. Options.CurrentOptions.DisableStartMenuAds = !adsSw.Checked;
  1815. }
  1816. private void toggleSwitch27_Click(object sender, EventArgs e)
  1817. {
  1818. if (!darkSw.Checked)
  1819. {
  1820. Optimize.EnableDarkTheme();
  1821. }
  1822. else
  1823. {
  1824. Optimize.EnableLightTheme();
  1825. }
  1826. Options.CurrentOptions.EnableDarkTheme = !darkSw.Checked;
  1827. }
  1828. private void toggleSwitch14_Click(object sender, EventArgs e)
  1829. {
  1830. if (!uODSw.Checked)
  1831. {
  1832. Task t = new Task(() => Optimize.UninstallOneDrive());
  1833. t.Start();
  1834. }
  1835. else
  1836. {
  1837. Task t = new Task(() => Optimize.InstallOneDrive());
  1838. t.Start();
  1839. }
  1840. Options.CurrentOptions.UninstallOneDrive = !uODSw.Checked;
  1841. }
  1842. private void toggleSwitch25_Click(object sender, EventArgs e)
  1843. {
  1844. if (!peopleSw.Checked)
  1845. {
  1846. Optimize.DisableMyPeople();
  1847. }
  1848. else
  1849. {
  1850. Optimize.EnableMyPeople();
  1851. }
  1852. Options.CurrentOptions.DisableMyPeople = !peopleSw.Checked;
  1853. }
  1854. private void toggleSwitch24_Click(object sender, EventArgs e)
  1855. {
  1856. if (!autoUpdatesSw.Checked)
  1857. {
  1858. Optimize.DisableAutomaticUpdates();
  1859. }
  1860. else
  1861. {
  1862. Optimize.EnableAutomaticUpdates();
  1863. }
  1864. Options.CurrentOptions.DisableAutomaticUpdates = !autoUpdatesSw.Checked;
  1865. }
  1866. private void toggleSwitch30_Click(object sender, EventArgs e)
  1867. {
  1868. if (!driversSw.Checked)
  1869. {
  1870. Optimize.ExcludeDrivers();
  1871. }
  1872. else
  1873. {
  1874. Optimize.IncludeDrivers();
  1875. }
  1876. Options.CurrentOptions.ExcludeDrivers = !driversSw.Checked;
  1877. }
  1878. private void toggleSwitch23_Click(object sender, EventArgs e)
  1879. {
  1880. if (!telemetryServicesSw.Checked)
  1881. {
  1882. Optimize.DisableTelemetryServices();
  1883. }
  1884. else
  1885. {
  1886. Optimize.EnableTelemetryServices();
  1887. }
  1888. Options.CurrentOptions.DisableTelemetryServices = !telemetryServicesSw.Checked;
  1889. }
  1890. private void toggleSwitch21_Click(object sender, EventArgs e)
  1891. {
  1892. if (!privacySw.Checked)
  1893. {
  1894. Optimize.EnhancePrivacy();
  1895. }
  1896. else
  1897. {
  1898. Optimize.CompromisePrivacy();
  1899. }
  1900. Options.CurrentOptions.DisablePrivacyOptions = !privacySw.Checked;
  1901. }
  1902. private void toggleSwitch16_Click(object sender, EventArgs e)
  1903. {
  1904. if (!cortanaSw.Checked)
  1905. {
  1906. Optimize.DisableCortana();
  1907. }
  1908. else
  1909. {
  1910. Optimize.EnableCortana();
  1911. }
  1912. Options.CurrentOptions.DisableCortana = !cortanaSw.Checked;
  1913. }
  1914. private void toggleSwitch20_Click(object sender, EventArgs e)
  1915. {
  1916. if (!sensorSw.Checked)
  1917. {
  1918. Optimize.DisableSensorServices();
  1919. }
  1920. else
  1921. {
  1922. Optimize.EnableSensorServices();
  1923. }
  1924. Options.CurrentOptions.DisableSensorServices = !sensorSw.Checked;
  1925. }
  1926. private void toggleSwitch29_Click(object sender, EventArgs e)
  1927. {
  1928. if (!inkSw.Checked)
  1929. {
  1930. Optimize.DisableWindowsInk();
  1931. }
  1932. else
  1933. {
  1934. Optimize.EnableWindowsInk();
  1935. }
  1936. Options.CurrentOptions.DisableWindowsInk = !inkSw.Checked;
  1937. }
  1938. private void toggleSwitch28_Click(object sender, EventArgs e)
  1939. {
  1940. if (!spellSw.Checked)
  1941. {
  1942. Optimize.DisableSpellingAndTypingFeatures();
  1943. }
  1944. else
  1945. {
  1946. Optimize.EnableSpellingAndTypingFeatures();
  1947. }
  1948. Options.CurrentOptions.DisableSpellingTyping = !spellSw.Checked;
  1949. }
  1950. private void toggleSwitch17_Click(object sender, EventArgs e)
  1951. {
  1952. if (!xboxSw.Checked)
  1953. {
  1954. Optimize.DisableXboxLive();
  1955. }
  1956. else
  1957. {
  1958. Optimize.EnableXboxLive();
  1959. }
  1960. Options.CurrentOptions.DisableXboxLive = !xboxSw.Checked;
  1961. }
  1962. private void toggleSwitch15_Click(object sender, EventArgs e)
  1963. {
  1964. if (!gameBarSw.Checked)
  1965. {
  1966. Optimize.DisableGameBar();
  1967. }
  1968. else
  1969. {
  1970. Optimize.EnableGameBar();
  1971. }
  1972. Options.CurrentOptions.DisableGameBar = !gameBarSw.Checked;
  1973. }
  1974. private void toggleSwitch31_Click(object sender, EventArgs e)
  1975. {
  1976. if (!disableOneDriveSw.Checked)
  1977. {
  1978. Optimize.DisableOneDrive();
  1979. }
  1980. else
  1981. {
  1982. Optimize.EnableOneDrive();
  1983. }
  1984. Options.CurrentOptions.DisableOneDrive = !disableOneDriveSw.Checked;
  1985. }
  1986. private void toggleSwitch32_Click(object sender, EventArgs e)
  1987. {
  1988. if (!compatSw.Checked)
  1989. {
  1990. Optimize.DisableCompatibilityAssistant();
  1991. }
  1992. else
  1993. {
  1994. Optimize.EnableCompatibilityAssistant();
  1995. }
  1996. Options.CurrentOptions.DisableCompatibilityAssistant = !compatSw.Checked;
  1997. }
  1998. private void btnUpdate_Click(object sender, EventArgs e)
  1999. {
  2000. CheckForUpdate();
  2001. }
  2002. private void btnChangelog_Click(object sender, EventArgs e)
  2003. {
  2004. try
  2005. {
  2006. Process.Start(_changelogLink);
  2007. }
  2008. catch (Exception ex)
  2009. {
  2010. ErrorLogger.LogError("MainForm.btnChangelog_Click", ex.Message, ex.StackTrace);
  2011. MessageBox.Show(ex.Message, "Optimizer", MessageBoxButtons.OK, MessageBoxIcon.Information);
  2012. }
  2013. }
  2014. private void chkReadOnly_CheckedChanged(object sender, EventArgs e)
  2015. {
  2016. HostsHelper.ReadOnly(chkReadOnly.Checked);
  2017. addHostB.Enabled = !chkReadOnly.Checked;
  2018. removeAllHostsB.Enabled = !chkReadOnly.Checked;
  2019. removeHostB.Enabled = !chkReadOnly.Checked;
  2020. refreshHostsB.Enabled = !chkReadOnly.Checked;
  2021. linkRestoreDefault.Enabled = !chkReadOnly.Checked;
  2022. chkBlock.Enabled = !chkReadOnly.Checked;
  2023. txtDomain.Enabled = !chkReadOnly.Checked;
  2024. txtIP.Enabled = !chkReadOnly.Checked;
  2025. adblockBasic.Enabled = !chkReadOnly.Checked;
  2026. adblockS.Enabled = !chkReadOnly.Checked;
  2027. adblockP.Enabled = !chkReadOnly.Checked;
  2028. adblockUlti.Enabled = !chkReadOnly.Checked;
  2029. txtIP.Focus();
  2030. }
  2031. private void button1_Click(object sender, EventArgs e)
  2032. {
  2033. HostsHelper.AdblockBasic();
  2034. GetHostsEntries();
  2035. }
  2036. private void button3_Click(object sender, EventArgs e)
  2037. {
  2038. HostsHelper.AdBlockWithPorn();
  2039. GetHostsEntries();
  2040. }
  2041. private void button2_Click(object sender, EventArgs e)
  2042. {
  2043. HostsHelper.AdBlockWithSocial();
  2044. GetHostsEntries();
  2045. }
  2046. private void button4_Click(object sender, EventArgs e)
  2047. {
  2048. HostsHelper.AdBlockWithSocial();
  2049. GetHostsEntries();
  2050. }
  2051. private void RenderAppDownloaderBusy()
  2052. {
  2053. btnDownloadApps.Enabled = false;
  2054. changeDownDirB.Enabled = false;
  2055. txtDownloadFolder.ReadOnly = true;
  2056. linkWarnings.Visible = false;
  2057. }
  2058. private void RenderAppDownloaderFree()
  2059. {
  2060. btnDownloadApps.Enabled = true;
  2061. changeDownDirB.Enabled = true;
  2062. txtDownloadFolder.ReadOnly = false;
  2063. linkWarnings.Visible = !string.IsNullOrEmpty(downloadLog);
  2064. txtDownloadStatus.Text = Options.TranslationList["Finished"];
  2065. }
  2066. string appNameTemp = string.Empty;
  2067. int maxCount = 0;
  2068. int count = 0;
  2069. Process p;
  2070. string downloadLog = string.Empty;
  2071. private async void btnDownloadApps_Click(object sender, EventArgs e)
  2072. {
  2073. if (!Directory.Exists(txtDownloadFolder.Text))
  2074. {
  2075. MessageBox.Show(Options.TranslationList["downloadDirInvalid"].ToString(), "Optimizer", MessageBoxButtons.OK, MessageBoxIcon.Information);
  2076. return;
  2077. }
  2078. RenderAppDownloaderBusy();
  2079. maxCount = 0;
  2080. count = 0;
  2081. downloadLog = string.Empty;
  2082. foreach (Control c in Utilities.GetSelfAndChildrenRecursive(appsTab))
  2083. {
  2084. if (c.Name == "cAutoInstall") continue;
  2085. if (c is ColoredCheckBox && ((ColoredCheckBox)c).Checked) maxCount++;
  2086. }
  2087. ColoredCheckBox currentCheck;
  2088. Control[] temp;
  2089. foreach (FeedApp x in AppsFromFeed)
  2090. {
  2091. if (string.IsNullOrEmpty(x.Tag)) continue;
  2092. temp = appsTab.Controls.Find(x.Tag, true);
  2093. if (temp.Count() == 0) continue;
  2094. currentCheck = (ColoredCheckBox)temp[0];
  2095. if (currentCheck == null) continue;
  2096. if (!currentCheck.Checked) continue;
  2097. appNameTemp = x.Title;
  2098. if (c64.Checked)
  2099. {
  2100. count++;
  2101. if (string.IsNullOrEmpty(x.Link64))
  2102. {
  2103. downloadLog += "• " + x.Title + ":" + Environment.NewLine + Options.TranslationList["no64Download"] + Environment.NewLine + Environment.NewLine;
  2104. await DownloadApp(x, false);
  2105. }
  2106. else
  2107. {
  2108. await DownloadApp(x, true);
  2109. }
  2110. }
  2111. else
  2112. {
  2113. count++;
  2114. if (!string.IsNullOrEmpty(x.Link))
  2115. {
  2116. await DownloadApp(x, false);
  2117. }
  2118. else
  2119. {
  2120. downloadLog += "• " + x.Title + ":" + Environment.NewLine + Options.TranslationList["no32Download"] + Environment.NewLine + Environment.NewLine;
  2121. }
  2122. }
  2123. }
  2124. if (cAutoInstall.Checked)
  2125. {
  2126. count = 0;
  2127. foreach (string a in Directory.GetFiles(txtDownloadFolder.Text, "*.*", SearchOption.TopDirectoryOnly))
  2128. {
  2129. using (p = new Process())
  2130. {
  2131. count++;
  2132. p.StartInfo.FileName = a;
  2133. p.EnableRaisingEvents = true;
  2134. p.StartInfo.WorkingDirectory = txtDownloadFolder.Text;
  2135. // APP-SPECIFIC HACKS //
  2136. if (a.Contains("Sumatra")) p.StartInfo.Arguments = " -install";
  2137. // *** //
  2138. txtDownloadStatus.Text = string.Format("{0}/{1} - {2} {3} ...", count, maxCount, Options.TranslationList["installing"], Path.GetFileNameWithoutExtension(a));
  2139. await p.RunAsync();
  2140. };
  2141. }
  2142. }
  2143. // reset all checkboxes
  2144. foreach (Control c in Utilities.GetSelfAndChildrenRecursive(appsTab))
  2145. {
  2146. if (c.Name == "cAutoInstall") continue;
  2147. if (c is ColoredCheckBox && ((ColoredCheckBox)c).Checked) ((ColoredCheckBox)c).Checked = false;
  2148. }
  2149. RenderAppDownloaderFree();
  2150. }
  2151. string fileExtension = ".exe";
  2152. private async Task DownloadApp(FeedApp app, bool pref64)
  2153. {
  2154. try
  2155. {
  2156. using (WebClient downloader = new WebClient())
  2157. {
  2158. downloader.Headers.Add("User-Agent: Other");
  2159. downloader.Encoding = Encoding.UTF8;
  2160. downloader.DownloadProgressChanged += Downloader_DownloadProgressChanged;
  2161. downloader.DownloadFileCompleted += Downloader_DownloadFileCompleted;
  2162. if (pref64)
  2163. {
  2164. if (app.Link64.Contains(".msi"))
  2165. {
  2166. fileExtension = ".msi";
  2167. }
  2168. else
  2169. {
  2170. fileExtension = ".exe";
  2171. }
  2172. await downloader.DownloadFileTaskAsync(new Uri(app.Link64), Path.Combine(txtDownloadFolder.Text, app.Title + "-x64" + fileExtension));
  2173. }
  2174. else
  2175. {
  2176. if (app.Link.Contains(".msi"))
  2177. {
  2178. fileExtension = ".msi";
  2179. }
  2180. else
  2181. {
  2182. fileExtension = ".exe";
  2183. }
  2184. await downloader.DownloadFileTaskAsync(new Uri(app.Link), Path.Combine(txtDownloadFolder.Text, app.Title + "-x86" + fileExtension));
  2185. }
  2186. }
  2187. }
  2188. catch (Exception ex)
  2189. {
  2190. ErrorLogger.LogError("MainForm.DownloadApp", ex.Message, ex.StackTrace);
  2191. downloadLog += "• " + app.Title + ":" + Environment.NewLine + Options.TranslationList["linkInvalid"] + Environment.NewLine + Environment.NewLine;
  2192. if (pref64) try { File.Delete(Path.Combine(txtDownloadFolder.Text, app.Title + "-x64.exe")); } catch { }
  2193. if (!pref64) try { File.Delete(Path.Combine(txtDownloadFolder.Text, app.Title + "-x86.exe")); } catch { }
  2194. if (pref64) try { File.Delete(Path.Combine(txtDownloadFolder.Text, app.Title + "-x64.msi")); } catch { }
  2195. if (!pref64) try { File.Delete(Path.Combine(txtDownloadFolder.Text, app.Title + "-x86.msi")); } catch { }
  2196. }
  2197. }
  2198. private void Downloader_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
  2199. {
  2200. this.BeginInvoke((MethodInvoker)delegate
  2201. {
  2202. //txtDownloadStatus.Text = "Finished";
  2203. });
  2204. }
  2205. int tempProgress;
  2206. private void Downloader_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
  2207. {
  2208. this.BeginInvoke((MethodInvoker)delegate
  2209. {
  2210. double bytesIn = double.Parse(e.BytesReceived.ToString());
  2211. double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
  2212. double percentage = bytesIn / totalBytes * 100;
  2213. tempProgress = int.Parse(Math.Truncate(percentage).ToString());
  2214. // if Content-Length header is missing, just show an animation
  2215. if (Math.Abs(tempProgress) > 100)
  2216. {
  2217. txtDownloadStatus.Text = string.Format("({1}/{2}) - {0} ...", appNameTemp, count, maxCount);
  2218. progressDownloader.Style = ProgressBarStyle.Marquee;
  2219. }
  2220. // if not, show actual progress
  2221. else
  2222. {
  2223. txtDownloadStatus.Text = string.Format("({1}/{2}) - {0} - {3} / {4}", appNameTemp, count, maxCount, ByteSize.FromBytes(e.BytesReceived).ToString("MB"), ByteSize.FromBytes(e.TotalBytesToReceive).ToString("MB"));
  2224. progressDownloader.Style = ProgressBarStyle.Continuous;
  2225. progressDownloader.Value = tempProgress;
  2226. }
  2227. });
  2228. }
  2229. private void button5_Click(object sender, EventArgs e)
  2230. {
  2231. FolderBrowserDialog d = new FolderBrowserDialog();
  2232. if (d.ShowDialog() == DialogResult.OK)
  2233. {
  2234. txtDownloadFolder.Text = d.SelectedPath;
  2235. Options.CurrentOptions.AppsFolder = d.SelectedPath;
  2236. Options.SaveSettings();
  2237. }
  2238. }
  2239. private void button6_Click(object sender, EventArgs e)
  2240. {
  2241. Process.Start(txtDownloadFolder.Text);
  2242. }
  2243. private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  2244. {
  2245. InfoForm lf = new InfoForm(downloadLog);
  2246. lf.ShowDialog(this);
  2247. }
  2248. private void txtDownloadFolder_TextChanged(object sender, EventArgs e)
  2249. {
  2250. Options.CurrentOptions.AppsFolder = txtDownloadFolder.Text;
  2251. Options.SaveSettings();
  2252. }
  2253. private void chkOnlyRemovable_CheckedChanged(object sender, EventArgs e)
  2254. {
  2255. GetModernApps(!chkOnlyRemovable.Checked);
  2256. }
  2257. private void btnGetFeed_Click(object sender, EventArgs e)
  2258. {
  2259. GetFeed();
  2260. }
  2261. private void l2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  2262. {
  2263. AboutForm f = new AboutForm();
  2264. f.ShowDialog(this);
  2265. //Process.Start("https://github.com/hellzerg/optimizer");
  2266. }
  2267. private void btnViewLog_Click(object sender, EventArgs e)
  2268. {
  2269. if (File.Exists(ErrorLogger.ErrorLogFile))
  2270. {
  2271. InfoForm iform = new InfoForm(File.ReadAllText(ErrorLogger.ErrorLogFile, Encoding.UTF8));
  2272. iform.ShowDialog();
  2273. }
  2274. else
  2275. {
  2276. MessageBox.Show(Options.TranslationList["noErrorsM"].ToString(), "Optimizer", MessageBoxButtons.OK, MessageBoxIcon.Information);
  2277. }
  2278. }
  2279. private void btnOpenConf_Click(object sender, EventArgs e)
  2280. {
  2281. Process.Start(Required.CoreFolder);
  2282. }
  2283. private void btnPing_Click(object sender, EventArgs e)
  2284. {
  2285. if (string.IsNullOrEmpty(txtPingInput.Text)) return;
  2286. _pingResults = new List<PingReply>();
  2287. listPingResults.Items.Clear();
  2288. if (Utilities.PingHost(txtPingInput.Text) == null)
  2289. {
  2290. listPingResults.Items.Add(string.Format("{0} [{1}]", Options.TranslationList["hostNotFound"], txtPingInput.Text));
  2291. return;
  2292. }
  2293. Task pinger = new Task(() =>
  2294. {
  2295. btnShodan.Enabled = false;
  2296. btnPing.Enabled = false;
  2297. listPingResults.Items.Add(string.Format("{0} [{1}]", Options.TranslationList["pinging"], txtPingInput.Text));
  2298. listPingResults.Items.Add("");
  2299. for (int i = 0; i < 9; i++)
  2300. {
  2301. // wait before each pinging
  2302. System.Threading.Thread.Sleep(888);
  2303. tmpReply = Utilities.PingHost(txtPingInput.Text);
  2304. if (tmpReply.Address == null)
  2305. {
  2306. listPingResults.Items.Add(tmpReply.Status);
  2307. }
  2308. else
  2309. {
  2310. _pingResults.Add(tmpReply);
  2311. _shodanIP = _pingResults[i].Address.ToString();
  2312. listPingResults.Items.Add(string.Format("{0} - {1}: {2} ms - TTL: {3}", _pingResults[i].Status, Options.TranslationList["latency"], _pingResults[i].RoundtripTime, _pingResults[i].Options.Ttl));
  2313. }
  2314. }
  2315. listPingResults.Items.Add("");
  2316. // calculate statistics
  2317. if (_pingResults.Count > 0)
  2318. {
  2319. long maxLatency = _pingResults.Max(x => x.RoundtripTime);
  2320. long minLatency = _pingResults.Min(x => x.RoundtripTime);
  2321. double averageLatency = _pingResults.Average(x => x.RoundtripTime);
  2322. listPingResults.Items.Add(string.Format("{0} = {1}, {2} = {3}, {4} = {5:F2}", Options.TranslationList["min"], minLatency, Options.TranslationList["max"], maxLatency, Options.TranslationList["avg"], averageLatency));
  2323. }
  2324. else
  2325. {
  2326. listPingResults.Items.Add(Options.TranslationList["timeout"]);
  2327. }
  2328. btnPing.Enabled = true;
  2329. btnShodan.Enabled = true;
  2330. });
  2331. pinger.Start();
  2332. }
  2333. private void btnCheckFootprint_Click(object sender, EventArgs e)
  2334. {
  2335. CleanHelper.CheckFootprint();
  2336. }
  2337. private void btnShodan_Click(object sender, EventArgs e)
  2338. {
  2339. IPAddress tryIP;
  2340. if (IPAddress.TryParse(txtPingInput.Text, out tryIP))
  2341. {
  2342. Process.Start(string.Format("https://www.shodan.io/host/{0}", txtPingInput.Text));
  2343. return;
  2344. }
  2345. if (!string.IsNullOrEmpty(_shodanIP))
  2346. {
  2347. Process.Start(string.Format("https://www.shodan.io/host/{0}", _shodanIP));
  2348. return;
  2349. }
  2350. }
  2351. private void button9_Click(object sender, EventArgs e)
  2352. {
  2353. try
  2354. {
  2355. Clipboard.SetText(_shodanIP);
  2356. }
  2357. catch { }
  2358. }
  2359. private void button7_Click(object sender, EventArgs e)
  2360. {
  2361. try
  2362. {
  2363. Clipboard.SetText(txtPingInput.Text);
  2364. }
  2365. catch { }
  2366. }
  2367. private void txtPingInput_KeyDown(object sender, KeyEventArgs e)
  2368. {
  2369. if (e.KeyCode == Keys.Enter) btnPing.PerformClick();
  2370. }
  2371. private void btnExport_Click(object sender, EventArgs e)
  2372. {
  2373. if (ExportDialog.ShowDialog() == DialogResult.OK)
  2374. {
  2375. try
  2376. {
  2377. File.WriteAllLines(ExportDialog.FileName, listPingResults.Items.Cast<string>());
  2378. }
  2379. catch (Exception ex)
  2380. {
  2381. ErrorLogger.LogError("btnExport.Click", ex.Message, ex.StackTrace);
  2382. MessageBox.Show(ex.Message, "Optimizer", MessageBoxButtons.OK, MessageBoxIcon.Information);
  2383. }
  2384. }
  2385. }
  2386. private void startupItem_Click(object sender, EventArgs e)
  2387. {
  2388. tabCollection.SelectedTab = startupTab;
  2389. RestoreWindow();
  2390. }
  2391. private void cleanerItem_Click(object sender, EventArgs e)
  2392. {
  2393. tabCollection.SelectedTab = cleanerTab;
  2394. RestoreWindow();
  2395. }
  2396. private void pingerItem_Click(object sender, EventArgs e)
  2397. {
  2398. tabCollection.SelectedTab = pingerTab;
  2399. RestoreWindow();
  2400. txtPingInput.Focus();
  2401. }
  2402. private void hostsItem_Click(object sender, EventArgs e)
  2403. {
  2404. tabCollection.SelectedTab = hostsEditorTab;
  2405. RestoreWindow();
  2406. txtIP.Focus();
  2407. }
  2408. private void appsItem_Click(object sender, EventArgs e)
  2409. {
  2410. tabCollection.SelectedTab = appsTab;
  2411. RestoreWindow();
  2412. }
  2413. private void exitItem_Click(object sender, EventArgs e)
  2414. {
  2415. _trayMenu = false;
  2416. Options.CurrentOptions.AppsFolder = txtDownloadFolder.Text;
  2417. Options.SaveSettings();
  2418. Application.Exit();
  2419. }
  2420. private void RestoreWindow()
  2421. {
  2422. if (this.WindowState == FormWindowState.Minimized) this.WindowState = FormWindowState.Normal;
  2423. this.Show();
  2424. this.Activate();
  2425. this.Focus();
  2426. }
  2427. private void launcherIcon_MouseDoubleClick(object sender, MouseEventArgs e)
  2428. {
  2429. if (this.Visible)
  2430. {
  2431. if (this.WindowState == FormWindowState.Minimized) this.WindowState = FormWindowState.Normal;
  2432. this.Hide();
  2433. }
  2434. else
  2435. {
  2436. RestoreWindow();
  2437. }
  2438. }
  2439. private void quickAccessToggle_CheckedChanged(object sender, EventArgs e)
  2440. {
  2441. Options.CurrentOptions.EnableTray = quickAccessToggle.Checked;
  2442. Options.SaveSettings();
  2443. _trayMenu = quickAccessToggle.Checked;
  2444. launcherIcon.Visible = quickAccessToggle.Checked;
  2445. }
  2446. private void linkLabel5_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  2447. {
  2448. Process.Start(_licenseLink);
  2449. }
  2450. private void linkLabel6_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  2451. {
  2452. Process.Start(_openSourceLink);
  2453. }
  2454. private void linkUpdate_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  2455. {
  2456. CheckForUpdate();
  2457. }
  2458. private void restartExpolorerItem_Click(object sender, EventArgs e)
  2459. {
  2460. Utilities.RestartExplorer();
  2461. }
  2462. private void button10_Click(object sender, EventArgs e)
  2463. {
  2464. Utilities.FlushDNSCache();
  2465. }
  2466. private void helpTipsToggle_CheckedChanged(object sender, EventArgs e)
  2467. {
  2468. Options.CurrentOptions.ShowHelp = helpTipsToggle.Checked;
  2469. Options.SaveSettings();
  2470. helpBox.Active = helpTipsToggle.Checked;
  2471. }
  2472. private void button11_Click(object sender, EventArgs e)
  2473. {
  2474. ShowBackupConfirm();
  2475. }
  2476. private void ShowBackupConfirm()
  2477. {
  2478. removeStartupItemB.Visible = false;
  2479. locateFileB.Visible = false;
  2480. findInRegB.Visible = false;
  2481. refreshStartupB.Visible = false;
  2482. restoreStartupB.Visible = false;
  2483. backupStartupB.Visible = false;
  2484. lblBackupTitle.Visible = true;
  2485. doBackup.Visible = true;
  2486. cancelBackup.Visible = true;
  2487. txtBackupTitle.Visible = true;
  2488. }
  2489. private void HideBackupConfirm()
  2490. {
  2491. removeStartupItemB.Visible = true;
  2492. locateFileB.Visible = true;
  2493. findInRegB.Visible = true;
  2494. refreshStartupB.Visible = true;
  2495. restoreStartupB.Visible = true;
  2496. backupStartupB.Visible = true;
  2497. lblBackupTitle.Visible = false;
  2498. doBackup.Visible = false;
  2499. cancelBackup.Visible = false;
  2500. txtBackupTitle.Visible = false;
  2501. }
  2502. private void button12_Click(object sender, EventArgs e)
  2503. {
  2504. StartupRestoreForm f = new StartupRestoreForm();
  2505. f.ShowDialog(this);
  2506. GetStartupItems();
  2507. }
  2508. private void button14_Click(object sender, EventArgs e)
  2509. {
  2510. HideBackupConfirm();
  2511. }
  2512. private void button13_Click(object sender, EventArgs e)
  2513. {
  2514. if (!string.IsNullOrEmpty(txtBackupTitle.Text.Trim()))
  2515. {
  2516. HideBackupConfirm();
  2517. _backupItems.Clear();
  2518. foreach (var x in _startUpItems)
  2519. {
  2520. _backupItems.Add(new StartupBackupItem(x.Name, x.FileLocation, x.RegistryLocation.ToString(), x.StartupType.ToString()));
  2521. }
  2522. try
  2523. {
  2524. File.WriteAllText(Required.StartupItemsBackupFolder + Utilities.SanitizeFileFolderName(txtBackupTitle.Text + " - [" + DateTime.Now.ToShortDateString() + "-" + DateTime.Now.ToShortTimeString()) + "].json", JsonConvert.SerializeObject(_backupItems, Formatting.Indented));
  2525. }
  2526. catch (Exception ex)
  2527. {
  2528. ErrorLogger.LogError("MainForm.BackupStartupItems", ex.Message, ex.StackTrace);
  2529. }
  2530. }
  2531. }
  2532. private void pictureBox86_Click(object sender, EventArgs e)
  2533. {
  2534. radioEnglish.PerformClick();
  2535. }
  2536. private void pictureBox87_Click(object sender, EventArgs e)
  2537. {
  2538. radioRussian.PerformClick();
  2539. }
  2540. private void radioEnglish_Click(object sender, EventArgs e)
  2541. {
  2542. radioEnglish.Checked = true;
  2543. Options.CurrentOptions.LanguageCode = LanguageCode.EN;
  2544. Options.SaveSettings();
  2545. Options.LoadTranslation();
  2546. Translate();
  2547. }
  2548. private void radioRussian_Click(object sender, EventArgs e)
  2549. {
  2550. radioRussian.Checked = true;
  2551. Options.CurrentOptions.LanguageCode = LanguageCode.RU;
  2552. Options.SaveSettings();
  2553. Options.LoadTranslation();
  2554. Translate();
  2555. }
  2556. private void pictureBox88_Click(object sender, EventArgs e)
  2557. {
  2558. radioHellenic.PerformClick();
  2559. }
  2560. private void radioHellenic_Click(object sender, EventArgs e)
  2561. {
  2562. radioHellenic.Checked = true;
  2563. Options.CurrentOptions.LanguageCode = LanguageCode.EL;
  2564. Options.SaveSettings();
  2565. Options.LoadTranslation();
  2566. Translate();
  2567. }
  2568. private void pictureBox89_Click(object sender, EventArgs e)
  2569. {
  2570. radioTurkish.PerformClick();
  2571. }
  2572. private void radioTurkish_Click(object sender, EventArgs e)
  2573. {
  2574. radioTurkish.Checked = true;
  2575. Options.CurrentOptions.LanguageCode = LanguageCode.TR;
  2576. Options.SaveSettings();
  2577. Options.LoadTranslation();
  2578. Translate();
  2579. }
  2580. private void radioGerman_Click(object sender, EventArgs e)
  2581. {
  2582. radioGerman.Checked = true;
  2583. Options.CurrentOptions.LanguageCode = LanguageCode.DE;
  2584. Options.SaveSettings();
  2585. Options.LoadTranslation();
  2586. Translate();
  2587. }
  2588. private void pictureBox2_Click(object sender, EventArgs e)
  2589. {
  2590. radioGerman.PerformClick();
  2591. }
  2592. private void pictureBox3_Click(object sender, EventArgs e)
  2593. {
  2594. radioSpanish.PerformClick();
  2595. }
  2596. private void radioSpanish_Click(object sender, EventArgs e)
  2597. {
  2598. radioSpanish.Checked = true;
  2599. Options.CurrentOptions.LanguageCode = LanguageCode.ES;
  2600. Options.SaveSettings();
  2601. Options.LoadTranslation();
  2602. Translate();
  2603. }
  2604. private void radioPortuguese_Click(object sender, EventArgs e)
  2605. {
  2606. radioPortuguese.Checked = true;
  2607. Options.CurrentOptions.LanguageCode = LanguageCode.PT;
  2608. Options.SaveSettings();
  2609. Options.LoadTranslation();
  2610. Translate();
  2611. }
  2612. private void pictureBox4_Click(object sender, EventArgs e)
  2613. {
  2614. radioPortuguese.PerformClick();
  2615. }
  2616. private void txtIPv4_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  2617. {
  2618. Clipboard.SetText(txtIPv4.Text);
  2619. }
  2620. private void txtIPv4A_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  2621. {
  2622. Clipboard.SetText(txtIPv4A.Text);
  2623. }
  2624. private void txtIPv6_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  2625. {
  2626. Clipboard.SetText(txtIPv6.Text);
  2627. }
  2628. private void txtIPv6A_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  2629. {
  2630. Clipboard.SetText(txtIPv6A.Text);
  2631. }
  2632. private void btnOpenNetwork_Click(object sender, EventArgs e)
  2633. {
  2634. Process.Start("NCPA.cpl");
  2635. }
  2636. }
  2637. }