MainForm.cs 108 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063
  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. if (Options.CurrentOptions.LanguageCode == LanguageCode.FR) radioFrench.Checked = true;
  505. Program.MainForm = this;
  506. if (string.IsNullOrEmpty(Options.CurrentOptions.AppsFolder))
  507. {
  508. txtDownloadFolder.Text = Path.Combine(Application.StartupPath, "Optimizer Downloads");
  509. Options.CurrentOptions.AppsFolder = Path.Combine(Application.StartupPath, "Optimizer Downloads");
  510. Directory.CreateDirectory(Options.CurrentOptions.AppsFolder);
  511. Options.SaveSettings();
  512. }
  513. else
  514. {
  515. if (!Directory.Exists(Options.CurrentOptions.AppsFolder))
  516. {
  517. try
  518. {
  519. Directory.CreateDirectory(Options.CurrentOptions.AppsFolder);
  520. }
  521. catch (Exception ex)
  522. {
  523. txtDownloadFolder.Text = string.Empty;
  524. ErrorLogger.LogError("MainForm.INIT", ex.Message, ex.StackTrace);
  525. }
  526. }
  527. txtDownloadFolder.Text = Options.CurrentOptions.AppsFolder;
  528. }
  529. if (!Program.EXPERIMENTAL_BUILD && Utilities.IsInternetAvailable()) CheckForUpdate(true);
  530. if (Program.EXPERIMENTAL_BUILD)
  531. {
  532. btnUpdate.Enabled = false;
  533. lblUpdateDisabled.Visible = true;
  534. }
  535. // Indicium-related
  536. //var CPUs = IndiciumHelper.GetCPUs();
  537. //var RAM = IndiciumHelper.GetRAM();
  538. //var GPUs = IndiciumHelper.GetGPUs();
  539. //var Motherboards = IndiciumHelper.GetMotherboards();
  540. //var Storage = IndiciumHelper.GetStorageDevices();
  541. //var Network = IndiciumHelper.GetNetworkDevices();
  542. // network monitoring
  543. //_networkMonitor = new NetworkMonitor();
  544. }
  545. //private void NetworkMonitoring()
  546. //{
  547. // while (true)
  548. // {
  549. // downloadSpeed = 0;
  550. // uploadSpeed = 0;
  551. // foreach (NetworkAdapter adapter in _networkMonitor.Adapters)
  552. // {
  553. // //adapter.Refresh();
  554. // downloadSpeed += Math.Round(adapter.DownloadSpeedMbps, 2);
  555. // uploadSpeed += Math.Round(adapter.UploadSpeedMbps, 2);
  556. // }
  557. // this.Text = string.Format("Optimizer - DOWN: {0} UP: {1}", downloadSpeed, uploadSpeed);
  558. // Thread.Sleep(1000);
  559. // }
  560. //}
  561. private void Translate(bool skipFull = false)
  562. {
  563. Dictionary<string, string> translationList = Options.TranslationList.ToObject<Dictionary<string, string>>();
  564. if (Environment.Is64BitOperatingSystem)
  565. {
  566. translationList["txtBitness"] = translationList["txtBitness"].Replace("{BITS}", translationList["c64"]);
  567. }
  568. else
  569. {
  570. translationList["txtBitness"] = translationList["txtBitness"].Replace("{BITS}", translationList["c32"]);
  571. }
  572. SetHelpBoxTranslation();
  573. if (!skipFull)
  574. {
  575. _noNewVersionMessage = Options.TranslationList["noNewVersion"];
  576. _betaVersionMessage = Options.TranslationList["betaVersion"];
  577. _restartMessage = Options.TranslationList["restartAndApply"];
  578. _removeStartupItemsMessage = Options.TranslationList["removeAllStartup"];
  579. _removeHostsEntriesMessage = Options.TranslationList["removeAllHosts"];
  580. _removeDesktopItemsMessage = Options.TranslationList["removeAllItems"];
  581. _removeModernAppsMessage = Options.TranslationList["removeModernApps"];
  582. _errorModernAppsMessage = Options.TranslationList["errorModernApps"];
  583. _resetMessage = Options.TranslationList["resetMessage"];
  584. listStartupItems.Columns[0].Text = translationList["startupItemName"];
  585. listStartupItems.Columns[1].Text = translationList["startupItemLocation"];
  586. listStartupItems.Columns[2].Text = translationList["startupItemType"];
  587. trayStartup.Text = translationList["trayStartup"];
  588. trayCleaner.Text = translationList["trayCleaner"];
  589. trayPinger.Text = translationList["trayPinger"];
  590. trayHosts.Text = translationList["trayHosts"];
  591. trayAD.Text = translationList["trayAD"];
  592. trayRestartExplorer.Text = translationList["trayRestartExplorer"];
  593. trayExit.Text = translationList["trayExit"];
  594. Control element;
  595. foreach (var x in translationList)
  596. {
  597. if (x.Key == null || x.Key == string.Empty) continue;
  598. element = this.Controls.Find(x.Key, true).FirstOrDefault();
  599. if (element == null) continue;
  600. if (element is ToggleSwitch)
  601. {
  602. ((ToggleSwitch)element).OnText = x.Value;
  603. continue;
  604. }
  605. element.Text = x.Value;
  606. }
  607. }
  608. txtVersion.Text = txtVersion.Text.Replace("{VN}", Program.GetCurrentVersionTostring());
  609. }
  610. private void GetFootprint()
  611. {
  612. ByteSize footprint = CleanHelper.CheckFootprint();
  613. lblFootprint.Text = footprint.ToString();
  614. }
  615. private void GetFeed()
  616. {
  617. WebClient client = new WebClient
  618. {
  619. Encoding = Encoding.UTF8
  620. };
  621. client.Headers.Add("Cache-Control", "no-cache");
  622. try
  623. {
  624. byte[] feedData;
  625. string tmpImageFileName = string.Empty;
  626. feedData = client.DownloadData(_feedImages);
  627. using (ZipArchive zip = new ZipArchive(new MemoryStream(feedData)))
  628. {
  629. var zipEntries = zip.Entries;
  630. try
  631. {
  632. string feed = client.DownloadString(_feedLink);
  633. AppsFromFeed = JsonConvert.DeserializeObject<List<FeedApp>>(feed);
  634. AppCard appCard;
  635. groupSystemTools.Controls.Clear();
  636. groupInternet.Controls.Clear();
  637. groupCoding.Controls.Clear();
  638. groupSoundVideo.Controls.Clear();
  639. foreach (FeedApp x in AppsFromFeed)
  640. {
  641. appCard = new AppCard();
  642. appCard.AutoSize = true;
  643. appCard.Anchor = AnchorStyles.None;
  644. appCard.Anchor = AnchorStyles.Top | AnchorStyles.Left;
  645. appCard.appTitle.Text = x.Title;
  646. appCard.appTitle.Name = x.Tag;
  647. appCard.appImage.SizeMode = PictureBoxSizeMode.Zoom;
  648. tmpImageFileName = x.Image.Substring(x.Image.LastIndexOf("/") + 1, x.Image.Length - (x.Image.LastIndexOf("/") + 1));
  649. appCard.appImage.Image = Image.FromStream(zipEntries.First(ifn => ifn.Name == tmpImageFileName).Open());
  650. switch (x.Group)
  651. {
  652. case "SystemTools":
  653. appCard.Location = new Point(0, groupSystemTools.Controls.Count * 30);
  654. groupSystemTools.Controls.Add(appCard);
  655. break;
  656. case "Internet":
  657. appCard.Location = new Point(0, groupInternet.Controls.Count * 30);
  658. groupInternet.Controls.Add(appCard);
  659. break;
  660. case "Coding":
  661. appCard.Location = new Point(0, groupCoding.Controls.Count * 30);
  662. groupCoding.Controls.Add(appCard);
  663. break;
  664. case "GraphicsSound":
  665. appCard.Location = new Point(0, groupSoundVideo.Controls.Count * 30);
  666. groupSoundVideo.Controls.Add(appCard);
  667. break;
  668. default:
  669. break;
  670. }
  671. }
  672. // UI handling
  673. btnDownloadApps.Enabled = true;
  674. txtFeedError.Visible = false;
  675. }
  676. catch (Exception ex)
  677. {
  678. btnDownloadApps.Enabled = false;
  679. txtFeedError.Visible = true;
  680. ErrorLogger.LogError("MainForm.GetFeed", ex.Message, ex.StackTrace);
  681. }
  682. }
  683. }
  684. catch (Exception ex)
  685. {
  686. btnDownloadApps.Enabled = false;
  687. txtFeedError.Visible = true;
  688. ErrorLogger.LogError("MainForm.GetFeed-DownloadImages", ex.Message, ex.StackTrace);
  689. }
  690. }
  691. private void CleanPC()
  692. {
  693. try
  694. {
  695. if (checkTemp.Checked)
  696. {
  697. CleanHelper.CleanTemporaries();
  698. }
  699. if (checkMiniDumps.Checked)
  700. {
  701. CleanHelper.CleanMiniDumps();
  702. }
  703. if (checkMediaCache.Checked)
  704. {
  705. CleanHelper.CleanMediaPlayersCache();
  706. }
  707. if (checkLogs.Checked)
  708. {
  709. CleanHelper.CleanLogs();
  710. }
  711. if (checkErrorReports.Checked)
  712. {
  713. CleanHelper.CleanErrorReports();
  714. }
  715. if (checkBin.Checked)
  716. {
  717. CleanHelper.EmptyRecycleBin();
  718. }
  719. }
  720. catch (Exception ex)
  721. {
  722. ErrorLogger.LogError("MainForm.CleanPC", ex.Message, ex.StackTrace);
  723. }
  724. finally
  725. {
  726. Cleaning(false);
  727. GetFootprint();
  728. }
  729. }
  730. private bool FixRegistry()
  731. {
  732. bool changeDetected = false;
  733. try
  734. {
  735. if (checkFirewall.Checked)
  736. {
  737. Utilities.EnableFirewall();
  738. changeDetected = true;
  739. }
  740. if (checkCommandPrompt.Checked)
  741. {
  742. Utilities.EnableCommandPrompt();
  743. changeDetected = true;
  744. }
  745. if (checkControlPanel.Checked)
  746. {
  747. Utilities.EnableControlPanel();
  748. changeDetected = true;
  749. }
  750. if (checkFolderOptions.Checked)
  751. {
  752. Utilities.EnableFolderOptions();
  753. changeDetected = true;
  754. }
  755. if (checkRunDialog.Checked)
  756. {
  757. Utilities.EnableRunDialog();
  758. changeDetected = true;
  759. }
  760. if (checkContextMenu.Checked)
  761. {
  762. Utilities.EnableContextMenu();
  763. changeDetected = true;
  764. }
  765. if (checkTaskManager.Checked)
  766. {
  767. Utilities.EnableTaskManager();
  768. changeDetected = true;
  769. }
  770. if (checkRegistryEditor.Checked)
  771. {
  772. Utilities.EnableRegistryEditor();
  773. changeDetected = true;
  774. }
  775. }
  776. catch (Exception ex)
  777. {
  778. ErrorLogger.LogError("MainForm.FixRegistry", ex.Message, ex.StackTrace);
  779. }
  780. return changeDetected;
  781. }
  782. private void LoadUniversalToggleStates()
  783. {
  784. performanceSw.Checked = Options.CurrentOptions.EnablePerformanceTweaks;
  785. networkSw.Checked = Options.CurrentOptions.DisableNetworkThrottling;
  786. defenderSw.Checked = Options.CurrentOptions.DisableWindowsDefender;
  787. systemRestoreSw.Checked = Options.CurrentOptions.DisableSystemRestore;
  788. printSw.Checked = Options.CurrentOptions.DisablePrintService;
  789. mediaSharingSw.Checked = Options.CurrentOptions.DisableMediaPlayerSharing;
  790. reportingSw.Checked = Options.CurrentOptions.DisableErrorReporting;
  791. homegroupSw.Checked = Options.CurrentOptions.DisableHomeGroup;
  792. superfetchSw.Checked = Options.CurrentOptions.DisableSuperfetch;
  793. telemetryTasksSw.Checked = Options.CurrentOptions.DisableTelemetryTasks;
  794. officeTelemetrySw.Checked = Options.CurrentOptions.DisableOffice2016Telemetry;
  795. compatSw.Checked = Options.CurrentOptions.DisableCompatibilityAssistant;
  796. faxSw.Checked = Options.CurrentOptions.DisableFaxService;
  797. smartScreenSw.Checked = Options.CurrentOptions.DisableSmartScreen;
  798. stickySw.Checked = Options.CurrentOptions.DisableStickyKeys;
  799. }
  800. private void LoadWindowsVIIIToggleStates()
  801. {
  802. disableOneDriveSw.Checked = Options.CurrentOptions.DisableOneDrive;
  803. }
  804. private void LoadWindowsXToggleStates()
  805. {
  806. oldMixerSw.Checked = Options.CurrentOptions.EnableLegacyVolumeSlider;
  807. uODSw.Checked = Options.CurrentOptions.UninstallOneDrive;
  808. gameBarSw.Checked = Options.CurrentOptions.DisableGameBar;
  809. cortanaSw.Checked = Options.CurrentOptions.DisableCortana;
  810. xboxSw.Checked = Options.CurrentOptions.DisableXboxLive;
  811. oldExplorerSw.Checked = Options.CurrentOptions.DisableQuickAccessHistory;
  812. colorBarSw.Checked = Options.CurrentOptions.EnableTaskbarColor;
  813. sensorSw.Checked = Options.CurrentOptions.DisableSensorServices;
  814. privacySw.Checked = Options.CurrentOptions.DisablePrivacyOptions;
  815. telemetryServicesSw.Checked = Options.CurrentOptions.DisableTelemetryServices;
  816. autoUpdatesSw.Checked = Options.CurrentOptions.DisableAutomaticUpdates;
  817. peopleSw.Checked = Options.CurrentOptions.DisableMyPeople;
  818. adsSw.Checked = Options.CurrentOptions.DisableStartMenuAds;
  819. darkSw.Checked = Options.CurrentOptions.EnableDarkTheme;
  820. spellSw.Checked = Options.CurrentOptions.DisableSpellingTyping;
  821. inkSw.Checked = Options.CurrentOptions.DisableWindowsInk;
  822. driversSw.Checked = Options.CurrentOptions.ExcludeDrivers;
  823. insiderSw.Checked = Options.CurrentOptions.DisableInsiderService;
  824. featuresSw.Checked = Options.CurrentOptions.DisableFeatureUpdates;
  825. ccSw.Checked = Options.CurrentOptions.DisableCloudClipboard;
  826. longPathsSw.Checked = Options.CurrentOptions.EnableLongPaths;
  827. castSw.Checked = Options.CurrentOptions.RemoveCastToDevice;
  828. actionSw.Checked = Options.CurrentOptions.DisableActionCenter;
  829. }
  830. private void Main_Load(object sender, EventArgs e)
  831. {
  832. }
  833. private void GetDesktopItems()
  834. {
  835. _desktopItems = Integrator.GetDesktopItems();
  836. listDesktopItems.Items.Clear();
  837. for (int i = 0; i < _desktopItems.Count; i++)
  838. {
  839. if (!string.IsNullOrEmpty(_desktopItems[i]))
  840. {
  841. listDesktopItems.Items.Add(_desktopItems[i]);
  842. }
  843. }
  844. if (_desktopItems.Count > 0) listDesktopItems.SelectedIndex = 0;
  845. }
  846. private void GetHostsEntries()
  847. {
  848. ((Control)this.hostsEditorTab).Enabled = false;
  849. _hostsEntries = HostsHelper.GetHostsEntries();
  850. listHostEntries.Items.Clear();
  851. listHostEntries.Items.AddRange(_hostsEntries.ToArray());
  852. chkReadOnly.Checked = HostsHelper.GetReadOnly();
  853. addHostB.Enabled = !chkReadOnly.Checked;
  854. removeAllHostsB.Enabled = !chkReadOnly.Checked;
  855. removeHostB.Enabled = !chkReadOnly.Checked;
  856. refreshHostsB.Enabled = !chkReadOnly.Checked;
  857. linkRestoreDefault.Enabled = !chkReadOnly.Checked;
  858. chkBlock.Enabled = !chkReadOnly.Checked;
  859. txtDomain.Enabled = !chkReadOnly.Checked;
  860. txtIP.Enabled = !chkReadOnly.Checked;
  861. adblockBasic.Enabled = !chkReadOnly.Checked;
  862. adblockS.Enabled = !chkReadOnly.Checked;
  863. adblockP.Enabled = !chkReadOnly.Checked;
  864. adblockUlti.Enabled = !chkReadOnly.Checked;
  865. ((Control)this.hostsEditorTab).Enabled = true;
  866. if (_hostsEntries.Count > 0) listHostEntries.SelectedIndex = 0;
  867. }
  868. private void GetStartupItems()
  869. {
  870. _startUpItems = Utilities.GetStartupItems();
  871. listStartupItems.Items.Clear();
  872. for (int i = 0; i < _startUpItems.Count; i++)
  873. {
  874. ListViewItem list = new ListViewItem(_startUpItems[i].Name);
  875. list.SubItems.Add(_startUpItems[i].FileLocation);
  876. list.SubItems.Add(_startUpItems[i].ToString());
  877. listStartupItems.Items.Add(list);
  878. }
  879. }
  880. private void GetModernApps(bool showAll)
  881. {
  882. uninstallModernAppsButton.Enabled = false;
  883. refreshModernAppsButton.Enabled = false;
  884. listModernApps.Enabled = false;
  885. listModernApps.Items.Clear();
  886. _modernApps = Utilities.GetModernApps(showAll);
  887. foreach (string x in _modernApps)
  888. {
  889. listModernApps.Items.Add(x);
  890. }
  891. uninstallModernAppsButton.Enabled = true;
  892. refreshModernAppsButton.Enabled = true;
  893. listModernApps.Enabled = true;
  894. if (_modernApps.Count > 0) listModernApps.SelectedIndex = 0;
  895. }
  896. private async void UninstallModernApps()
  897. {
  898. string selectedApps = string.Empty;
  899. if (listModernApps.CheckedItems.Count > 0)
  900. {
  901. foreach (string x in listModernApps.CheckedItems)
  902. {
  903. if (string.IsNullOrEmpty(selectedApps))
  904. {
  905. selectedApps = x;
  906. }
  907. else
  908. {
  909. selectedApps += Environment.NewLine + x;
  910. }
  911. }
  912. if (MessageBox.Show(_removeModernAppsMessage + "\n\n" + selectedApps, "Optimizer", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  913. {
  914. uninstallModernAppsButton.Enabled = false;
  915. refreshModernAppsButton.Enabled = false;
  916. listModernApps.Enabled = false;
  917. bool errorOccured = false;
  918. string failedApps = string.Empty;
  919. foreach (string app in listModernApps.CheckedItems)
  920. {
  921. await Task.Run(() => errorOccured = Utilities.UninstallModernApp(app));
  922. if (errorOccured)
  923. {
  924. failedApps += Environment.NewLine + app;
  925. }
  926. }
  927. if (!string.IsNullOrEmpty(failedApps))
  928. {
  929. MessageBox.Show(_errorModernAppsMessage + failedApps, "Optimizer", MessageBoxButtons.OK, MessageBoxIcon.Information);
  930. }
  931. GetModernApps(!chkOnlyRemovable.Checked);
  932. }
  933. }
  934. }
  935. private void GetCustomCommands()
  936. {
  937. _customCommands = Integrator.GetCustomCommands();
  938. listCustomCommands.Items.Clear();
  939. foreach (string s in _customCommands)
  940. {
  941. listCustomCommands.Items.Add(s);
  942. }
  943. if (_customCommands.Count > 0) listCustomCommands.SelectedIndex = 0;
  944. }
  945. private void Main_FormClosing(object sender, FormClosingEventArgs e)
  946. {
  947. if (_trayMenu)
  948. {
  949. e.Cancel = true;
  950. this.Hide();
  951. }
  952. else
  953. {
  954. Options.CurrentOptions.AppsFolder = txtDownloadFolder.Text;
  955. Options.SaveSettings();
  956. }
  957. }
  958. private void button39_Click(object sender, EventArgs e)
  959. {
  960. HelperForm f = new HelperForm(this, MessageType.Restart, _restartMessage);
  961. f.ShowDialog();
  962. }
  963. private void button43_Click(object sender, EventArgs e)
  964. {
  965. HelperForm f = new HelperForm(this, MessageType.Restart, _restartMessage);
  966. f.ShowDialog();
  967. }
  968. private void button44_Click(object sender, EventArgs e)
  969. {
  970. HelperForm f = new HelperForm(this, MessageType.Restart, _restartMessage);
  971. f.ShowDialog();
  972. }
  973. private void button45_Click(object sender, EventArgs e)
  974. {
  975. HelperForm f = new HelperForm(this, MessageType.Restart, _restartMessage);
  976. f.ShowDialog();
  977. }
  978. private void checkSelectAll_CheckedChanged(object sender, EventArgs e)
  979. {
  980. checkTemp.Checked = checkSelectAll.Checked;
  981. checkMiniDumps.Checked = checkSelectAll.Checked;
  982. checkMediaCache.Checked = checkSelectAll.Checked;
  983. checkLogs.Checked = checkSelectAll.Checked;
  984. checkBin.Checked = checkSelectAll.Checked;
  985. checkErrorReports.Checked = checkSelectAll.Checked;
  986. }
  987. private void button20_Click(object sender, EventArgs e)
  988. {
  989. Cleaning(true);
  990. Task t = new Task(() => CleanPC());
  991. t.Start();
  992. }
  993. private void Cleaning(bool enabled)
  994. {
  995. cleanDriveB.Enabled = !enabled;
  996. cleanDriveB.Text = (enabled) ? "..." : Options.TranslationList["cleanDriveB"];
  997. }
  998. private void button32_Click(object sender, EventArgs e)
  999. {
  1000. if (listStartupItems.CheckedItems.Count <= 0) return;
  1001. string report = string.Empty;
  1002. foreach (ListViewItem i in listStartupItems.CheckedItems)
  1003. {
  1004. report += i.Text + Environment.NewLine;
  1005. }
  1006. if (MessageBox.Show(_removeStartupItemsMessage + Environment.NewLine + Environment.NewLine + report, "Optimizer", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1007. {
  1008. foreach (int x in listStartupItems.CheckedIndices)
  1009. {
  1010. _startUpItems[x].Remove();
  1011. }
  1012. GetStartupItems();
  1013. }
  1014. //foreach (int x in listStartupItems.CheckedIndices)
  1015. //{
  1016. // MessageBox.Show(x.ToString());
  1017. //}
  1018. //if (listStartupItems.SelectedItems.Count == 1)
  1019. //{
  1020. // _startUpItems[listStartupItems.SelectedIndices[0]].Remove();
  1021. // GetStartupItems();
  1022. //}
  1023. }
  1024. internal void RemoveAllStartupItems()
  1025. {
  1026. foreach (ListViewItem i in listStartupItems.Items)
  1027. {
  1028. _startUpItems[i.Index].Remove();
  1029. }
  1030. GetStartupItems();
  1031. }
  1032. // REMOVE ALL STARTUP ITEMS BUTTON
  1033. //private void button22_Click(object sender, EventArgs e)
  1034. //{
  1035. // if (listStartupItems.Items.Count > 0)
  1036. // {
  1037. // HelperForm r = new HelperForm(this, MessageType.Startup, _removeStartupItemsMessage);
  1038. // r.ShowDialog(this);
  1039. // }
  1040. //}
  1041. private void button31_Click(object sender, EventArgs e)
  1042. {
  1043. if (listStartupItems.SelectedItems.Count == 1)
  1044. {
  1045. _startUpItems[listStartupItems.SelectedIndices[0]].LocateFile();
  1046. }
  1047. }
  1048. private void checkEnableAll_CheckedChanged(object sender, EventArgs e)
  1049. {
  1050. checkTaskManager.Checked = checkEnableAll.Checked;
  1051. checkCommandPrompt.Checked = checkEnableAll.Checked;
  1052. checkControlPanel.Checked = checkEnableAll.Checked;
  1053. checkFolderOptions.Checked = checkEnableAll.Checked;
  1054. checkRunDialog.Checked = checkEnableAll.Checked;
  1055. checkContextMenu.Checked = checkEnableAll.Checked;
  1056. checkFirewall.Checked = checkEnableAll.Checked;
  1057. checkRegistryEditor.Checked = checkEnableAll.Checked;
  1058. }
  1059. private void button33_Click(object sender, EventArgs e)
  1060. {
  1061. bool flag = FixRegistry();
  1062. if (flag)
  1063. {
  1064. panel2.Enabled = false;
  1065. regFixB.Enabled = false;
  1066. if (checkRestartExplorer.Checked)
  1067. {
  1068. Utilities.RestartExplorer();
  1069. }
  1070. panel2.Enabled = true;
  1071. regFixB.Enabled = true;
  1072. }
  1073. }
  1074. private void pictureBox1_Click(object sender, EventArgs e)
  1075. {
  1076. AboutForm f = new AboutForm();
  1077. f.ShowDialog(this);
  1078. }
  1079. private void button37_Click(object sender, EventArgs e)
  1080. {
  1081. GetStartupItems();
  1082. }
  1083. private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1084. {
  1085. HostsHelper.LocateHosts();
  1086. }
  1087. private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1088. {
  1089. HostsEditorForm f = new HostsEditorForm();
  1090. f.ShowDialog(this);
  1091. GetHostsEntries();
  1092. }
  1093. private void linkLabel4_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1094. {
  1095. HostsHelper.RestoreDefaultHosts();
  1096. GetHostsEntries();
  1097. }
  1098. private void button47_Click(object sender, EventArgs e)
  1099. {
  1100. if ((txtIP.Text != string.Empty) && (txtDomain.Text != string.Empty))
  1101. {
  1102. string ip = txtIP.Text.Trim();
  1103. string domain = txtDomain.Text.Trim();
  1104. string recommendedDomain = string.Empty;
  1105. if (!domain.StartsWith("www."))
  1106. {
  1107. recommendedDomain = "www." + domain;
  1108. }
  1109. else
  1110. {
  1111. recommendedDomain = domain.Replace("www.", string.Empty);
  1112. }
  1113. HostsHelper.AddEntry(HostsHelper.SanitizeEntry(ip) + " " + HostsHelper.SanitizeEntry(domain));
  1114. if (!string.IsNullOrEmpty(recommendedDomain))
  1115. {
  1116. HostsHelper.AddEntry(HostsHelper.SanitizeEntry(ip) + " " + HostsHelper.SanitizeEntry(recommendedDomain));
  1117. }
  1118. GetHostsEntries();
  1119. txtIP.Clear();
  1120. txtDomain.Clear();
  1121. chkBlock.Checked = false;
  1122. }
  1123. }
  1124. private void button41_Click(object sender, EventArgs e)
  1125. {
  1126. GetHostsEntries();
  1127. }
  1128. private void button42_Click(object sender, EventArgs e)
  1129. {
  1130. if (listHostEntries.SelectedItems.Count == 1)
  1131. {
  1132. HostsHelper.RemoveEntry(listHostEntries.SelectedItem.ToString().Replace(" : ", " "));
  1133. GetHostsEntries();
  1134. }
  1135. }
  1136. private void button46_Click(object sender, EventArgs e)
  1137. {
  1138. if (listHostEntries.Items.Count > 0)
  1139. {
  1140. HelperForm r = new HelperForm(this, MessageType.Hosts, _removeHostsEntriesMessage);
  1141. r.ShowDialog(this);
  1142. }
  1143. }
  1144. internal void RemoveAllHostsEntries()
  1145. {
  1146. List<string> collection = new List<string>();
  1147. foreach (string item in listHostEntries.Items)
  1148. {
  1149. collection.Add(item.Replace(" : ", " "));
  1150. }
  1151. HostsHelper.RemoveAllEntries(collection);
  1152. GetHostsEntries();
  1153. }
  1154. private void aio_SelectedIndexChanged(object sender, EventArgs e)
  1155. {
  1156. if (tabCollection.SelectedTab == hostsEditorTab) txtIP.Focus();
  1157. if (tabCollection.SelectedTab == pingerTab)
  1158. {
  1159. txtPingInput.Focus();
  1160. //_networkMonitor.StartMonitoring();
  1161. //NetworkMonitoring();
  1162. }
  1163. //else
  1164. //{
  1165. // _networkMonitor.StopMonitoring();
  1166. //}
  1167. }
  1168. private void button48_Click(object sender, EventArgs e)
  1169. {
  1170. defineCommandDialog.ShowDialog();
  1171. }
  1172. private void button50_Click(object sender, EventArgs e)
  1173. {
  1174. if (!string.IsNullOrEmpty(txtRunFile.Text) && !string.IsNullOrEmpty(txtRunKeyword.Text))
  1175. {
  1176. Integrator.CreateCustomCommand(txtRunFile.Text, txtRunKeyword.Text);
  1177. txtRunFile.Clear();
  1178. txtRunKeyword.Clear();
  1179. GetCustomCommands();
  1180. }
  1181. }
  1182. private void DefineCmd_FileOk(object sender, CancelEventArgs e)
  1183. {
  1184. txtRunFile.Text = defineCommandDialog.FileName;
  1185. txtRunKeyword.Text = Path.GetFileNameWithoutExtension(txtRunFile.Text).ToLower();
  1186. }
  1187. private void button59_Click(object sender, EventArgs e)
  1188. {
  1189. Utilities.ImportRegistryScript(Required.ReadyMadeMenusFolder + "\\PowerMenu.reg");
  1190. GetDesktopItems();
  1191. }
  1192. private void button53_Click(object sender, EventArgs e)
  1193. {
  1194. Utilities.ImportRegistryScript(Required.ReadyMadeMenusFolder + "\\SystemTools.reg");
  1195. GetDesktopItems();
  1196. }
  1197. private void button54_Click(object sender, EventArgs e)
  1198. {
  1199. Utilities.ImportRegistryScript(Required.ReadyMadeMenusFolder + "\\WindowsApps.reg");
  1200. GetDesktopItems();
  1201. }
  1202. private void button51_Click(object sender, EventArgs e)
  1203. {
  1204. Utilities.ImportRegistryScript(Required.ReadyMadeMenusFolder + "\\SystemShortcuts.reg");
  1205. GetDesktopItems();
  1206. }
  1207. private void button57_Click(object sender, EventArgs e)
  1208. {
  1209. Utilities.ImportRegistryScript(Required.ReadyMadeMenusFolder + "\\DesktopShortcuts.reg");
  1210. GetDesktopItems();
  1211. }
  1212. private void button60_Click(object sender, EventArgs e)
  1213. {
  1214. GetDesktopItems();
  1215. }
  1216. private void button61_Click(object sender, EventArgs e)
  1217. {
  1218. if (listDesktopItems.SelectedItems.Count == 1)
  1219. {
  1220. Integrator.RemoveItem(listDesktopItems.SelectedItem.ToString());
  1221. GetDesktopItems();
  1222. }
  1223. }
  1224. internal void RemoveAllDesktopItems()
  1225. {
  1226. List<string> collection = new List<string>();
  1227. foreach (string item in listDesktopItems.Items)
  1228. {
  1229. collection.Add(item);
  1230. }
  1231. Integrator.RemoveAllItems(collection);
  1232. GetDesktopItems();
  1233. }
  1234. private void button62_Click(object sender, EventArgs e)
  1235. {
  1236. if (listDesktopItems.Items.Count > 0)
  1237. {
  1238. HelperForm r = new HelperForm(this, MessageType.Integrator, _removeDesktopItemsMessage);
  1239. r.ShowDialog(this);
  1240. }
  1241. }
  1242. private void radioProgram_CheckedChanged(object sender, EventArgs e)
  1243. {
  1244. if (radioProgram.Checked)
  1245. {
  1246. btnBrowseItem.Enabled = true;
  1247. txtItem.Clear();
  1248. checkDefaultIcon.Checked = true;
  1249. txtIcon.Enabled = false;
  1250. btnBrowseIcon.Enabled = false;
  1251. itemtoaddgroup.Text = Options.TranslationList["itemtoaddgroup"];
  1252. checkDefaultIcon.Visible = true;
  1253. checkDefaultIcon.Text = Options.TranslationList["checkDefaultIcon"];
  1254. txtItemName.Clear();
  1255. txtItem.ReadOnly = true;
  1256. txtIcon.ReadOnly = true;
  1257. _desktopItemType = DesktopItemType.Program;
  1258. }
  1259. }
  1260. private void radioFolder_CheckedChanged(object sender, EventArgs e)
  1261. {
  1262. if (radioFolder.Checked)
  1263. {
  1264. checkDefaultIcon.Checked = true;
  1265. btnBrowseItem.Enabled = true;
  1266. txtItem.Clear();
  1267. itemtoaddgroup.Text = Options.TranslationList["folderToAdd"];
  1268. checkDefaultIcon.Text = Options.TranslationList["checkDefaultFolderIcon"];
  1269. txtItemName.Clear();
  1270. txtItem.ReadOnly = true;
  1271. txtIcon.ReadOnly = true;
  1272. _desktopItemType = DesktopItemType.Folder;
  1273. }
  1274. }
  1275. private void radioLink_CheckedChanged(object sender, EventArgs e)
  1276. {
  1277. if (radioLink.Checked)
  1278. {
  1279. checkDefaultIcon.Checked = true;
  1280. checkDefaultIcon.Text = Options.TranslationList["checkFavicon"];
  1281. btnBrowseItem.Enabled = false;
  1282. itemtoaddgroup.Text = Options.TranslationList["linkToAdd"];
  1283. checkDefaultIcon.Visible = true;
  1284. txtItem.Text = "http://";
  1285. txtItemName.Clear();
  1286. txtItem.ReadOnly = false;
  1287. txtIcon.ReadOnly = true;
  1288. _desktopItemType = DesktopItemType.Link;
  1289. }
  1290. }
  1291. private void radioFile_CheckedChanged(object sender, EventArgs e)
  1292. {
  1293. if (radioFile.Checked)
  1294. {
  1295. checkDefaultIcon.Checked = true;
  1296. checkDefaultIcon.Text = Options.TranslationList["checkNoIcon"];
  1297. btnBrowseItem.Enabled = true;
  1298. itemtoaddgroup.Text = Options.TranslationList["fileToAdd"];
  1299. checkDefaultIcon.Visible = true;
  1300. txtItem.Clear();
  1301. txtItemName.Clear();
  1302. txtItem.ReadOnly = true;
  1303. txtIcon.ReadOnly = true;
  1304. _desktopItemType = DesktopItemType.File;
  1305. }
  1306. }
  1307. private void radioCommand_CheckedChanged(object sender, EventArgs e)
  1308. {
  1309. if (radioCommand.Checked)
  1310. {
  1311. btnBrowseItem.Enabled = false;
  1312. txtItem.Clear();
  1313. checkDefaultIcon.Checked = true;
  1314. txtIcon.Enabled = false;
  1315. btnBrowseIcon.Enabled = false;
  1316. itemtoaddgroup.Text = Options.TranslationList["commandToAdd"];
  1317. checkDefaultIcon.Visible = true;
  1318. checkDefaultIcon.Text = Options.TranslationList["checkNoIcon"];
  1319. txtItemName.Clear();
  1320. txtItem.ReadOnly = false;
  1321. txtIcon.ReadOnly = true;
  1322. _desktopItemType = DesktopItemType.Command;
  1323. }
  1324. }
  1325. private void checkDefaultIcon_CheckedChanged(object sender, EventArgs e)
  1326. {
  1327. if (checkDefaultIcon.Checked)
  1328. {
  1329. txtIcon.Clear();
  1330. txtIcon.Enabled = false;
  1331. btnBrowseIcon.Enabled = false;
  1332. }
  1333. else
  1334. {
  1335. txtIcon.Clear();
  1336. txtIcon.Enabled = true;
  1337. btnBrowseIcon.Enabled = true;
  1338. }
  1339. }
  1340. private void btnBrowseItem_Click(object sender, EventArgs e)
  1341. {
  1342. switch (_desktopItemType)
  1343. {
  1344. case DesktopItemType.Program:
  1345. defineProgramDialog.ShowDialog();
  1346. break;
  1347. case DesktopItemType.Folder:
  1348. defineFolderDialog.ShowDialog();
  1349. txtItem.Text = defineFolderDialog.SelectedPath;
  1350. int i = defineFolderDialog.SelectedPath.LastIndexOf("\\");
  1351. txtItemName.Text = defineFolderDialog.SelectedPath.Remove(0, i + 1);
  1352. break;
  1353. case DesktopItemType.File:
  1354. defineFileDialog.ShowDialog();
  1355. break;
  1356. }
  1357. }
  1358. private void DefineProgramDialog_FileOk(object sender, CancelEventArgs e)
  1359. {
  1360. txtItem.Text = defineProgramDialog.FileName;
  1361. txtItemName.Text = defineProgramDialog.SafeFileName.Replace(".exe", string.Empty);
  1362. }
  1363. private void DefineFileDialog_FileOk(object sender, CancelEventArgs e)
  1364. {
  1365. txtItem.Text = defineFileDialog.FileName;
  1366. txtItemName.Text = defineFileDialog.SafeFileName;
  1367. }
  1368. private void btnBrowseIcon_Click(object sender, EventArgs e)
  1369. {
  1370. switch (_desktopItemType)
  1371. {
  1372. case DesktopItemType.Program:
  1373. DefineProgramIconDialog.ShowDialog();
  1374. break;
  1375. case DesktopItemType.Folder:
  1376. DefineFolderIconDialog.ShowDialog();
  1377. break;
  1378. case DesktopItemType.Link:
  1379. DefineURLIconDialog.ShowDialog();
  1380. break;
  1381. case DesktopItemType.File:
  1382. DefineFileIconDialog.ShowDialog();
  1383. break;
  1384. case DesktopItemType.Command:
  1385. DefineCommandIconDialog.ShowDialog();
  1386. break;
  1387. }
  1388. }
  1389. private void DefineProgramIconDialog_FileOk(object sender, CancelEventArgs e)
  1390. {
  1391. txtIcon.Text = DefineProgramIconDialog.FileName;
  1392. if (txtIcon.Text.Contains(".exe"))
  1393. {
  1394. string iconpath = Integrator.ExtractIconFromExecutable(txtItemName.Text, DefineProgramIconDialog.FileName);
  1395. txtIcon.Text = iconpath;
  1396. }
  1397. }
  1398. private void DefineFolderIconDialog_FileOk(object sender, CancelEventArgs e)
  1399. {
  1400. txtIcon.Text = DefineFolderIconDialog.FileName;
  1401. if (txtIcon.Text.Contains(".exe"))
  1402. {
  1403. string iconpath = Integrator.ExtractIconFromExecutable(txtItemName.Text, DefineFolderIconDialog.FileName);
  1404. txtIcon.Text = iconpath;
  1405. }
  1406. }
  1407. private void DefineURLIconDialog_FileOk(object sender, CancelEventArgs e)
  1408. {
  1409. txtIcon.Text = DefineURLIconDialog.FileName;
  1410. if (txtIcon.Text.Contains(".exe"))
  1411. {
  1412. string iconpath = Integrator.ExtractIconFromExecutable(txtItemName.Text, DefineURLIconDialog.FileName);
  1413. txtIcon.Text = iconpath;
  1414. }
  1415. }
  1416. private void DefineFileIconDialog_FileOk(object sender, CancelEventArgs e)
  1417. {
  1418. txtIcon.Text = DefineFileIconDialog.FileName;
  1419. if (txtIcon.Text.Contains(".exe"))
  1420. {
  1421. string iconpath = Integrator.ExtractIconFromExecutable(txtItemName.Text, DefineFileIconDialog.FileName);
  1422. txtIcon.Text = iconpath;
  1423. }
  1424. }
  1425. private void DefineCommandIconDialog_FileOk(object sender, CancelEventArgs e)
  1426. {
  1427. txtIcon.Text = DefineCommandIconDialog.FileName;
  1428. if (txtIcon.Text.Contains(".exe"))
  1429. {
  1430. string iconpath = Integrator.ExtractIconFromExecutable(txtItemName.Text, DefineCommandIconDialog.FileName);
  1431. txtIcon.Text = iconpath;
  1432. }
  1433. }
  1434. private void btnAddItem_Click(object sender, EventArgs e)
  1435. {
  1436. if (!checkDefaultIcon.Checked && (string.IsNullOrEmpty(txtItem.Text) || string.IsNullOrEmpty(txtItemName.Text) || string.IsNullOrEmpty(txtIcon.Text)))
  1437. {
  1438. return;
  1439. }
  1440. if (checkDefaultIcon.Checked && (string.IsNullOrEmpty(txtItem.Text) || string.IsNullOrEmpty(txtItemName.Text)))
  1441. {
  1442. return;
  1443. }
  1444. string icon = string.Empty;
  1445. switch (_desktopItemType)
  1446. {
  1447. case DesktopItemType.Program:
  1448. if (checkDefaultIcon.Checked)
  1449. {
  1450. icon = txtItem.Text;
  1451. }
  1452. else
  1453. {
  1454. icon = txtIcon.Text;
  1455. }
  1456. Integrator.AddItem(txtItemName.Text, txtItem.Text, icon, _desktopItemPosition, checkShift.Checked, DesktopItemType.Program);
  1457. break;
  1458. case DesktopItemType.Folder:
  1459. if (checkDefaultIcon.Checked)
  1460. {
  1461. icon = Integrator.FolderDefaultIcon;
  1462. }
  1463. else
  1464. {
  1465. icon = txtIcon.Text;
  1466. }
  1467. Integrator.AddItem(txtItemName.Text, txtItem.Text, icon, _desktopItemPosition, checkShift.Checked, DesktopItemType.Folder);
  1468. break;
  1469. case DesktopItemType.Link:
  1470. if (checkDefaultIcon.Checked)
  1471. {
  1472. icon = Integrator.DownloadFavicon(txtItem.Text, txtItemName.Text);
  1473. }
  1474. else
  1475. {
  1476. icon = txtIcon.Text;
  1477. }
  1478. Integrator.AddItem(txtItemName.Text, txtItem.Text, icon, _desktopItemPosition, checkShift.Checked, DesktopItemType.Link);
  1479. break;
  1480. case DesktopItemType.File:
  1481. if (!checkDefaultIcon.Checked)
  1482. {
  1483. icon = txtIcon.Text;
  1484. }
  1485. Integrator.AddItem(txtItemName.Text, txtItem.Text, icon, _desktopItemPosition, checkShift.Checked, DesktopItemType.File);
  1486. break;
  1487. case DesktopItemType.Command:
  1488. if (!checkDefaultIcon.Checked)
  1489. {
  1490. icon = txtIcon.Text;
  1491. }
  1492. Integrator.AddItem(txtItemName.Text, txtItem.Text, icon, _desktopItemPosition, checkShift.Checked, DesktopItemType.Command);
  1493. break;
  1494. }
  1495. GetDesktopItems();
  1496. ResetIntegratorForm();
  1497. }
  1498. private void radioTop_CheckedChanged(object sender, EventArgs e)
  1499. {
  1500. if (radioTop.Checked)
  1501. {
  1502. _desktopItemPosition = DesktopTypePosition.Top;
  1503. }
  1504. }
  1505. private void radioMiddle_CheckedChanged(object sender, EventArgs e)
  1506. {
  1507. if (radioMiddle.Checked)
  1508. {
  1509. _desktopItemPosition = DesktopTypePosition.Middle;
  1510. }
  1511. }
  1512. private void radioBottom_CheckedChanged(object sender, EventArgs e)
  1513. {
  1514. if (radioBottom.Checked)
  1515. {
  1516. _desktopItemPosition = DesktopTypePosition.Bottom;
  1517. }
  1518. }
  1519. private void ResetIntegratorForm()
  1520. {
  1521. txtItem.Clear();
  1522. txtIcon.Clear();
  1523. checkDefaultIcon.Checked = true;
  1524. txtItemName.Clear();
  1525. if (radioLink.Checked)
  1526. {
  1527. txtItem.Text = "http://";
  1528. }
  1529. }
  1530. private void radioOcean_CheckedChanged(object sender, EventArgs e)
  1531. {
  1532. Options.CurrentOptions.Color = Theme.Ocean;
  1533. Options.ApplyTheme(this);
  1534. }
  1535. private void radioMagma_CheckedChanged(object sender, EventArgs e)
  1536. {
  1537. Options.CurrentOptions.Color = Theme.Magma;
  1538. Options.ApplyTheme(this);
  1539. }
  1540. private void radioZerg_CheckedChanged(object sender, EventArgs e)
  1541. {
  1542. Options.CurrentOptions.Color = Theme.Zerg;
  1543. Options.ApplyTheme(this);
  1544. }
  1545. private void radioMinimal_CheckedChanged(object sender, EventArgs e)
  1546. {
  1547. Options.CurrentOptions.Color = Theme.Minimal;
  1548. Options.ApplyTheme(this);
  1549. }
  1550. private void radioCaramel_CheckedChanged(object sender, EventArgs e)
  1551. {
  1552. Options.CurrentOptions.Color = Theme.Caramel;
  1553. Options.ApplyTheme(this);
  1554. }
  1555. private void radioLime_CheckedChanged(object sender, EventArgs e)
  1556. {
  1557. Options.CurrentOptions.Color = Theme.Lime;
  1558. Options.ApplyTheme(this);
  1559. }
  1560. private void button64_Click(object sender, EventArgs e)
  1561. {
  1562. if (listStartupItems.SelectedItems.Count == 1)
  1563. {
  1564. _startUpItems[listStartupItems.SelectedIndices[0]].LocateKey();
  1565. }
  1566. }
  1567. private void button66_Click(object sender, EventArgs e)
  1568. {
  1569. Integrator.TakeOwnership(false);
  1570. }
  1571. private void button65_Click(object sender, EventArgs e)
  1572. {
  1573. Integrator.TakeOwnership(true);
  1574. }
  1575. private void listStartupItems_ColumnClick(object sender, ColumnClickEventArgs e)
  1576. {
  1577. if (e.Column == _columnSorter.CurrentColumn)
  1578. {
  1579. if (_columnSorter.SortOrder == SortOrder.Ascending)
  1580. {
  1581. _columnSorter.SortOrder = SortOrder.Descending;
  1582. }
  1583. else
  1584. {
  1585. _columnSorter.SortOrder = SortOrder.Ascending;
  1586. }
  1587. }
  1588. else
  1589. {
  1590. _columnSorter.CurrentColumn = e.Column;
  1591. _columnSorter.SortOrder = SortOrder.Ascending;
  1592. }
  1593. listStartupItems.Sort();
  1594. }
  1595. private void chkBlock_CheckedChanged(object sender, EventArgs e)
  1596. {
  1597. if (chkBlock.Checked)
  1598. {
  1599. txtIP.Text = _blockedIP;
  1600. txtIP.Enabled = false;
  1601. }
  1602. else
  1603. {
  1604. txtIP.Clear();
  1605. txtIP.Enabled = true;
  1606. }
  1607. }
  1608. private void button8_Click(object sender, EventArgs e)
  1609. {
  1610. GetCustomCommands();
  1611. }
  1612. private void button26_Click(object sender, EventArgs e)
  1613. {
  1614. if (listCustomCommands.SelectedItems.Count == 1)
  1615. {
  1616. Integrator.DeleteCustomCommand(listCustomCommands.SelectedItem.ToString());
  1617. GetCustomCommands();
  1618. }
  1619. }
  1620. private void button75_Click(object sender, EventArgs e)
  1621. {
  1622. GetModernApps(!chkOnlyRemovable.Checked);
  1623. }
  1624. private void button74_Click(object sender, EventArgs e)
  1625. {
  1626. UninstallModernApps();
  1627. }
  1628. private void chkSelectAllModernApps_CheckedChanged(object sender, EventArgs e)
  1629. {
  1630. for (int i = 0; i < listModernApps.Items.Count; i++)
  1631. {
  1632. listModernApps.SetItemChecked(i, chkSelectAllModernApps.Checked);
  1633. }
  1634. }
  1635. private void btnResetConfig_Click(object sender, EventArgs e)
  1636. {
  1637. if (MessageBox.Show(_resetMessage, "Optimizer", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  1638. {
  1639. Utilities.ResetConfiguration();
  1640. }
  1641. }
  1642. private void toggleSwitch1_Click(object sender, EventArgs e)
  1643. {
  1644. if (!performanceSw.Checked)
  1645. {
  1646. Optimize.EnablePerformanceTweaks();
  1647. }
  1648. else
  1649. {
  1650. Optimize.DisablePerformanceTweaks();
  1651. }
  1652. Options.CurrentOptions.EnablePerformanceTweaks = !performanceSw.Checked;
  1653. }
  1654. private void toggleSwitch2_Click(object sender, EventArgs e)
  1655. {
  1656. if (!networkSw.Checked)
  1657. {
  1658. Optimize.DisableNetworkThrottling();
  1659. }
  1660. else
  1661. {
  1662. Optimize.EnableNetworkThrottling();
  1663. }
  1664. Options.CurrentOptions.DisableNetworkThrottling = !networkSw.Checked;
  1665. }
  1666. private void toggleSwitch3_Click(object sender, EventArgs e)
  1667. {
  1668. if (!defenderSw.Checked)
  1669. {
  1670. Optimize.DisableDefender();
  1671. }
  1672. else
  1673. {
  1674. Optimize.EnableDefender();
  1675. }
  1676. Options.CurrentOptions.DisableWindowsDefender = !defenderSw.Checked;
  1677. }
  1678. private void toggleSwitch4_Click(object sender, EventArgs e)
  1679. {
  1680. if (!systemRestoreSw.Checked)
  1681. {
  1682. Optimize.DisableSystemRestore();
  1683. }
  1684. else
  1685. {
  1686. Optimize.EnableSystemRestore();
  1687. }
  1688. Options.CurrentOptions.DisableSystemRestore = !systemRestoreSw.Checked;
  1689. }
  1690. private void toggleSwitch5_Click(object sender, EventArgs e)
  1691. {
  1692. if (!printSw.Checked)
  1693. {
  1694. Optimize.DisablePrintService();
  1695. }
  1696. else
  1697. {
  1698. Optimize.EnablePrintService();
  1699. }
  1700. Options.CurrentOptions.DisablePrintService = !printSw.Checked;
  1701. }
  1702. private void toggleSwitch6_Click(object sender, EventArgs e)
  1703. {
  1704. if (!mediaSharingSw.Checked)
  1705. {
  1706. Optimize.DisableMediaPlayerSharing();
  1707. }
  1708. else
  1709. {
  1710. Optimize.EnableMediaPlayerSharing();
  1711. }
  1712. Options.CurrentOptions.DisableMediaPlayerSharing = !mediaSharingSw.Checked;
  1713. }
  1714. private void toggleSwitch8_Click(object sender, EventArgs e)
  1715. {
  1716. if (!reportingSw.Checked)
  1717. {
  1718. Optimize.DisableErrorReporting();
  1719. }
  1720. else
  1721. {
  1722. Optimize.EnableErrorReporting();
  1723. }
  1724. Options.CurrentOptions.DisableErrorReporting = !reportingSw.Checked;
  1725. }
  1726. private void toggleSwitch9_Click(object sender, EventArgs e)
  1727. {
  1728. if (!homegroupSw.Checked)
  1729. {
  1730. Optimize.DisableHomeGroup();
  1731. }
  1732. else
  1733. {
  1734. Optimize.EnableHomeGroup();
  1735. }
  1736. Options.CurrentOptions.DisableHomeGroup = !homegroupSw.Checked;
  1737. }
  1738. private void toggleSwitch10_Click(object sender, EventArgs e)
  1739. {
  1740. if (!superfetchSw.Checked)
  1741. {
  1742. Optimize.DisableSuperfetch();
  1743. }
  1744. else
  1745. {
  1746. Optimize.EnableSuperfetch();
  1747. }
  1748. Options.CurrentOptions.DisableSuperfetch = !superfetchSw.Checked;
  1749. }
  1750. private void toggleSwitch11_Click(object sender, EventArgs e)
  1751. {
  1752. if (!telemetryTasksSw.Checked)
  1753. {
  1754. Optimize.DisableTelemetryTasks();
  1755. }
  1756. else
  1757. {
  1758. Optimize.EnableTelemetryTasks();
  1759. }
  1760. Options.CurrentOptions.DisableTelemetryTasks = !telemetryTasksSw.Checked;
  1761. }
  1762. private void toggleSwitch12_Click(object sender, EventArgs e)
  1763. {
  1764. if (!officeTelemetrySw.Checked)
  1765. {
  1766. Optimize.DisableOffice2016Telemetry();
  1767. }
  1768. else
  1769. {
  1770. Optimize.EnableOffice2016Telemetry();
  1771. }
  1772. Options.CurrentOptions.DisableOffice2016Telemetry = !officeTelemetrySw.Checked;
  1773. }
  1774. private void toggleSwitch13_Click(object sender, EventArgs e)
  1775. {
  1776. if (!oldMixerSw.Checked)
  1777. {
  1778. Optimize.EnableLegacyVolumeSlider();
  1779. }
  1780. else
  1781. {
  1782. Optimize.DisableLegacyVolumeSlider();
  1783. }
  1784. Options.CurrentOptions.EnableLegacyVolumeSlider = !oldMixerSw.Checked;
  1785. }
  1786. private void toggleSwitch19_Click(object sender, EventArgs e)
  1787. {
  1788. if (!colorBarSw.Checked)
  1789. {
  1790. Optimize.EnableTaskbarColor();
  1791. }
  1792. else
  1793. {
  1794. Optimize.DisableTaskbarColor();
  1795. }
  1796. Options.CurrentOptions.EnableTaskbarColor = !colorBarSw.Checked;
  1797. }
  1798. private void toggleSwitch18_Click(object sender, EventArgs e)
  1799. {
  1800. if (!oldExplorerSw.Checked)
  1801. {
  1802. Optimize.DisableQuickAccessHistory();
  1803. }
  1804. else
  1805. {
  1806. Optimize.EnableQuickAccessHistory();
  1807. }
  1808. Options.CurrentOptions.DisableQuickAccessHistory = !oldExplorerSw.Checked;
  1809. }
  1810. private void toggleSwitch26_Click(object sender, EventArgs e)
  1811. {
  1812. if (!adsSw.Checked)
  1813. {
  1814. Optimize.DisableStartMenuAds();
  1815. }
  1816. else
  1817. {
  1818. Optimize.EnableStartMenuAds();
  1819. }
  1820. Options.CurrentOptions.DisableStartMenuAds = !adsSw.Checked;
  1821. }
  1822. private void toggleSwitch27_Click(object sender, EventArgs e)
  1823. {
  1824. if (!darkSw.Checked)
  1825. {
  1826. Optimize.EnableDarkTheme();
  1827. }
  1828. else
  1829. {
  1830. Optimize.EnableLightTheme();
  1831. }
  1832. Options.CurrentOptions.EnableDarkTheme = !darkSw.Checked;
  1833. }
  1834. private void toggleSwitch14_Click(object sender, EventArgs e)
  1835. {
  1836. if (!uODSw.Checked)
  1837. {
  1838. Task t = new Task(() => Optimize.UninstallOneDrive());
  1839. t.Start();
  1840. }
  1841. else
  1842. {
  1843. Task t = new Task(() => Optimize.InstallOneDrive());
  1844. t.Start();
  1845. }
  1846. Options.CurrentOptions.UninstallOneDrive = !uODSw.Checked;
  1847. }
  1848. private void toggleSwitch25_Click(object sender, EventArgs e)
  1849. {
  1850. if (!peopleSw.Checked)
  1851. {
  1852. Optimize.DisableMyPeople();
  1853. }
  1854. else
  1855. {
  1856. Optimize.EnableMyPeople();
  1857. }
  1858. Options.CurrentOptions.DisableMyPeople = !peopleSw.Checked;
  1859. }
  1860. private void toggleSwitch24_Click(object sender, EventArgs e)
  1861. {
  1862. if (!autoUpdatesSw.Checked)
  1863. {
  1864. Optimize.DisableAutomaticUpdates();
  1865. }
  1866. else
  1867. {
  1868. Optimize.EnableAutomaticUpdates();
  1869. }
  1870. Options.CurrentOptions.DisableAutomaticUpdates = !autoUpdatesSw.Checked;
  1871. }
  1872. private void toggleSwitch30_Click(object sender, EventArgs e)
  1873. {
  1874. if (!driversSw.Checked)
  1875. {
  1876. Optimize.ExcludeDrivers();
  1877. }
  1878. else
  1879. {
  1880. Optimize.IncludeDrivers();
  1881. }
  1882. Options.CurrentOptions.ExcludeDrivers = !driversSw.Checked;
  1883. }
  1884. private void toggleSwitch23_Click(object sender, EventArgs e)
  1885. {
  1886. if (!telemetryServicesSw.Checked)
  1887. {
  1888. Optimize.DisableTelemetryServices();
  1889. }
  1890. else
  1891. {
  1892. Optimize.EnableTelemetryServices();
  1893. }
  1894. Options.CurrentOptions.DisableTelemetryServices = !telemetryServicesSw.Checked;
  1895. }
  1896. private void toggleSwitch21_Click(object sender, EventArgs e)
  1897. {
  1898. if (!privacySw.Checked)
  1899. {
  1900. Optimize.EnhancePrivacy();
  1901. }
  1902. else
  1903. {
  1904. Optimize.CompromisePrivacy();
  1905. }
  1906. Options.CurrentOptions.DisablePrivacyOptions = !privacySw.Checked;
  1907. }
  1908. private void toggleSwitch16_Click(object sender, EventArgs e)
  1909. {
  1910. if (!cortanaSw.Checked)
  1911. {
  1912. Optimize.DisableCortana();
  1913. }
  1914. else
  1915. {
  1916. Optimize.EnableCortana();
  1917. }
  1918. Options.CurrentOptions.DisableCortana = !cortanaSw.Checked;
  1919. }
  1920. private void toggleSwitch20_Click(object sender, EventArgs e)
  1921. {
  1922. if (!sensorSw.Checked)
  1923. {
  1924. Optimize.DisableSensorServices();
  1925. }
  1926. else
  1927. {
  1928. Optimize.EnableSensorServices();
  1929. }
  1930. Options.CurrentOptions.DisableSensorServices = !sensorSw.Checked;
  1931. }
  1932. private void toggleSwitch29_Click(object sender, EventArgs e)
  1933. {
  1934. if (!inkSw.Checked)
  1935. {
  1936. Optimize.DisableWindowsInk();
  1937. }
  1938. else
  1939. {
  1940. Optimize.EnableWindowsInk();
  1941. }
  1942. Options.CurrentOptions.DisableWindowsInk = !inkSw.Checked;
  1943. }
  1944. private void toggleSwitch28_Click(object sender, EventArgs e)
  1945. {
  1946. if (!spellSw.Checked)
  1947. {
  1948. Optimize.DisableSpellingAndTypingFeatures();
  1949. }
  1950. else
  1951. {
  1952. Optimize.EnableSpellingAndTypingFeatures();
  1953. }
  1954. Options.CurrentOptions.DisableSpellingTyping = !spellSw.Checked;
  1955. }
  1956. private void toggleSwitch17_Click(object sender, EventArgs e)
  1957. {
  1958. if (!xboxSw.Checked)
  1959. {
  1960. Optimize.DisableXboxLive();
  1961. }
  1962. else
  1963. {
  1964. Optimize.EnableXboxLive();
  1965. }
  1966. Options.CurrentOptions.DisableXboxLive = !xboxSw.Checked;
  1967. }
  1968. private void toggleSwitch15_Click(object sender, EventArgs e)
  1969. {
  1970. if (!gameBarSw.Checked)
  1971. {
  1972. Optimize.DisableGameBar();
  1973. }
  1974. else
  1975. {
  1976. Optimize.EnableGameBar();
  1977. }
  1978. Options.CurrentOptions.DisableGameBar = !gameBarSw.Checked;
  1979. }
  1980. private void toggleSwitch31_Click(object sender, EventArgs e)
  1981. {
  1982. if (!disableOneDriveSw.Checked)
  1983. {
  1984. Optimize.DisableOneDrive();
  1985. }
  1986. else
  1987. {
  1988. Optimize.EnableOneDrive();
  1989. }
  1990. Options.CurrentOptions.DisableOneDrive = !disableOneDriveSw.Checked;
  1991. }
  1992. private void toggleSwitch32_Click(object sender, EventArgs e)
  1993. {
  1994. if (!compatSw.Checked)
  1995. {
  1996. Optimize.DisableCompatibilityAssistant();
  1997. }
  1998. else
  1999. {
  2000. Optimize.EnableCompatibilityAssistant();
  2001. }
  2002. Options.CurrentOptions.DisableCompatibilityAssistant = !compatSw.Checked;
  2003. }
  2004. private void btnUpdate_Click(object sender, EventArgs e)
  2005. {
  2006. CheckForUpdate();
  2007. }
  2008. private void btnChangelog_Click(object sender, EventArgs e)
  2009. {
  2010. try
  2011. {
  2012. Process.Start(_changelogLink);
  2013. }
  2014. catch (Exception ex)
  2015. {
  2016. ErrorLogger.LogError("MainForm.btnChangelog_Click", ex.Message, ex.StackTrace);
  2017. MessageBox.Show(ex.Message, "Optimizer", MessageBoxButtons.OK, MessageBoxIcon.Information);
  2018. }
  2019. }
  2020. private void chkReadOnly_CheckedChanged(object sender, EventArgs e)
  2021. {
  2022. HostsHelper.ReadOnly(chkReadOnly.Checked);
  2023. addHostB.Enabled = !chkReadOnly.Checked;
  2024. removeAllHostsB.Enabled = !chkReadOnly.Checked;
  2025. removeHostB.Enabled = !chkReadOnly.Checked;
  2026. refreshHostsB.Enabled = !chkReadOnly.Checked;
  2027. linkRestoreDefault.Enabled = !chkReadOnly.Checked;
  2028. chkBlock.Enabled = !chkReadOnly.Checked;
  2029. txtDomain.Enabled = !chkReadOnly.Checked;
  2030. txtIP.Enabled = !chkReadOnly.Checked;
  2031. adblockBasic.Enabled = !chkReadOnly.Checked;
  2032. adblockS.Enabled = !chkReadOnly.Checked;
  2033. adblockP.Enabled = !chkReadOnly.Checked;
  2034. adblockUlti.Enabled = !chkReadOnly.Checked;
  2035. txtIP.Focus();
  2036. }
  2037. private void button1_Click(object sender, EventArgs e)
  2038. {
  2039. HostsHelper.AdblockBasic();
  2040. GetHostsEntries();
  2041. }
  2042. private void button3_Click(object sender, EventArgs e)
  2043. {
  2044. HostsHelper.AdBlockWithPorn();
  2045. GetHostsEntries();
  2046. }
  2047. private void button2_Click(object sender, EventArgs e)
  2048. {
  2049. HostsHelper.AdBlockWithSocial();
  2050. GetHostsEntries();
  2051. }
  2052. private void button4_Click(object sender, EventArgs e)
  2053. {
  2054. HostsHelper.AdBlockWithSocial();
  2055. GetHostsEntries();
  2056. }
  2057. private void RenderAppDownloaderBusy()
  2058. {
  2059. btnDownloadApps.Enabled = false;
  2060. changeDownDirB.Enabled = false;
  2061. txtDownloadFolder.ReadOnly = true;
  2062. linkWarnings.Visible = false;
  2063. }
  2064. private void RenderAppDownloaderFree()
  2065. {
  2066. btnDownloadApps.Enabled = true;
  2067. changeDownDirB.Enabled = true;
  2068. txtDownloadFolder.ReadOnly = false;
  2069. linkWarnings.Visible = !string.IsNullOrEmpty(downloadLog);
  2070. txtDownloadStatus.Text = Options.TranslationList["Finished"];
  2071. }
  2072. string appNameTemp = string.Empty;
  2073. int maxCount = 0;
  2074. int count = 0;
  2075. Process p;
  2076. string downloadLog = string.Empty;
  2077. private async void btnDownloadApps_Click(object sender, EventArgs e)
  2078. {
  2079. if (!Directory.Exists(txtDownloadFolder.Text))
  2080. {
  2081. MessageBox.Show(Options.TranslationList["downloadDirInvalid"].ToString(), "Optimizer", MessageBoxButtons.OK, MessageBoxIcon.Information);
  2082. return;
  2083. }
  2084. RenderAppDownloaderBusy();
  2085. maxCount = 0;
  2086. count = 0;
  2087. downloadLog = string.Empty;
  2088. foreach (Control c in Utilities.GetSelfAndChildrenRecursive(appsTab))
  2089. {
  2090. if (c.Name == "cAutoInstall") continue;
  2091. if (c is ColoredCheckBox && ((ColoredCheckBox)c).Checked) maxCount++;
  2092. }
  2093. ColoredCheckBox currentCheck;
  2094. Control[] temp;
  2095. foreach (FeedApp x in AppsFromFeed)
  2096. {
  2097. if (string.IsNullOrEmpty(x.Tag)) continue;
  2098. temp = appsTab.Controls.Find(x.Tag, true);
  2099. if (temp.Count() == 0) continue;
  2100. currentCheck = (ColoredCheckBox)temp[0];
  2101. if (currentCheck == null) continue;
  2102. if (!currentCheck.Checked) continue;
  2103. appNameTemp = x.Title;
  2104. if (c64.Checked)
  2105. {
  2106. count++;
  2107. if (string.IsNullOrEmpty(x.Link64))
  2108. {
  2109. downloadLog += "• " + x.Title + ":" + Environment.NewLine + Options.TranslationList["no64Download"] + Environment.NewLine + Environment.NewLine;
  2110. await DownloadApp(x, false);
  2111. }
  2112. else
  2113. {
  2114. await DownloadApp(x, true);
  2115. }
  2116. }
  2117. else
  2118. {
  2119. count++;
  2120. if (!string.IsNullOrEmpty(x.Link))
  2121. {
  2122. await DownloadApp(x, false);
  2123. }
  2124. else
  2125. {
  2126. downloadLog += "• " + x.Title + ":" + Environment.NewLine + Options.TranslationList["no32Download"] + Environment.NewLine + Environment.NewLine;
  2127. }
  2128. }
  2129. }
  2130. if (cAutoInstall.Checked)
  2131. {
  2132. count = 0;
  2133. foreach (string a in Directory.GetFiles(txtDownloadFolder.Text, "*.*", SearchOption.TopDirectoryOnly))
  2134. {
  2135. using (p = new Process())
  2136. {
  2137. count++;
  2138. p.StartInfo.FileName = a;
  2139. p.EnableRaisingEvents = true;
  2140. p.StartInfo.WorkingDirectory = txtDownloadFolder.Text;
  2141. // APP-SPECIFIC HACKS //
  2142. if (a.Contains("Sumatra")) p.StartInfo.Arguments = " -install";
  2143. // *** //
  2144. txtDownloadStatus.Text = string.Format("{0}/{1} - {2} {3} ...", count, maxCount, Options.TranslationList["installing"], Path.GetFileNameWithoutExtension(a));
  2145. await p.RunAsync();
  2146. };
  2147. }
  2148. }
  2149. // reset all checkboxes
  2150. foreach (Control c in Utilities.GetSelfAndChildrenRecursive(appsTab))
  2151. {
  2152. if (c.Name == "cAutoInstall") continue;
  2153. if (c is ColoredCheckBox && ((ColoredCheckBox)c).Checked) ((ColoredCheckBox)c).Checked = false;
  2154. }
  2155. RenderAppDownloaderFree();
  2156. }
  2157. string fileExtension = ".exe";
  2158. private async Task DownloadApp(FeedApp app, bool pref64)
  2159. {
  2160. try
  2161. {
  2162. using (WebClient downloader = new WebClient())
  2163. {
  2164. downloader.Headers.Add("User-Agent: Other");
  2165. downloader.Encoding = Encoding.UTF8;
  2166. downloader.DownloadProgressChanged += Downloader_DownloadProgressChanged;
  2167. downloader.DownloadFileCompleted += Downloader_DownloadFileCompleted;
  2168. if (pref64)
  2169. {
  2170. if (app.Link64.Contains(".msi"))
  2171. {
  2172. fileExtension = ".msi";
  2173. }
  2174. else
  2175. {
  2176. fileExtension = ".exe";
  2177. }
  2178. await downloader.DownloadFileTaskAsync(new Uri(app.Link64), Path.Combine(txtDownloadFolder.Text, app.Title + "-x64" + fileExtension));
  2179. }
  2180. else
  2181. {
  2182. if (app.Link.Contains(".msi"))
  2183. {
  2184. fileExtension = ".msi";
  2185. }
  2186. else
  2187. {
  2188. fileExtension = ".exe";
  2189. }
  2190. await downloader.DownloadFileTaskAsync(new Uri(app.Link), Path.Combine(txtDownloadFolder.Text, app.Title + "-x86" + fileExtension));
  2191. }
  2192. }
  2193. }
  2194. catch (Exception ex)
  2195. {
  2196. ErrorLogger.LogError("MainForm.DownloadApp", ex.Message, ex.StackTrace);
  2197. downloadLog += "• " + app.Title + ":" + Environment.NewLine + Options.TranslationList["linkInvalid"] + Environment.NewLine + Environment.NewLine;
  2198. if (pref64) try { File.Delete(Path.Combine(txtDownloadFolder.Text, app.Title + "-x64.exe")); } catch { }
  2199. if (!pref64) try { File.Delete(Path.Combine(txtDownloadFolder.Text, app.Title + "-x86.exe")); } catch { }
  2200. if (pref64) try { File.Delete(Path.Combine(txtDownloadFolder.Text, app.Title + "-x64.msi")); } catch { }
  2201. if (!pref64) try { File.Delete(Path.Combine(txtDownloadFolder.Text, app.Title + "-x86.msi")); } catch { }
  2202. }
  2203. }
  2204. private void Downloader_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
  2205. {
  2206. this.BeginInvoke((MethodInvoker)delegate
  2207. {
  2208. //txtDownloadStatus.Text = "Finished";
  2209. });
  2210. }
  2211. int tempProgress;
  2212. private void Downloader_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
  2213. {
  2214. this.BeginInvoke((MethodInvoker)delegate
  2215. {
  2216. double bytesIn = double.Parse(e.BytesReceived.ToString());
  2217. double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
  2218. double percentage = bytesIn / totalBytes * 100;
  2219. tempProgress = int.Parse(Math.Truncate(percentage).ToString());
  2220. // if Content-Length header is missing, just show an animation
  2221. if (Math.Abs(tempProgress) > 100)
  2222. {
  2223. txtDownloadStatus.Text = string.Format("({1}/{2}) - {0} ...", appNameTemp, count, maxCount);
  2224. progressDownloader.Style = ProgressBarStyle.Marquee;
  2225. }
  2226. // if not, show actual progress
  2227. else
  2228. {
  2229. txtDownloadStatus.Text = string.Format("({1}/{2}) - {0} - {3} / {4}", appNameTemp, count, maxCount, ByteSize.FromBytes(e.BytesReceived).ToString("MB"), ByteSize.FromBytes(e.TotalBytesToReceive).ToString("MB"));
  2230. progressDownloader.Style = ProgressBarStyle.Continuous;
  2231. progressDownloader.Value = tempProgress;
  2232. }
  2233. });
  2234. }
  2235. private void button5_Click(object sender, EventArgs e)
  2236. {
  2237. FolderBrowserDialog d = new FolderBrowserDialog();
  2238. if (d.ShowDialog() == DialogResult.OK)
  2239. {
  2240. txtDownloadFolder.Text = d.SelectedPath;
  2241. Options.CurrentOptions.AppsFolder = d.SelectedPath;
  2242. Options.SaveSettings();
  2243. }
  2244. }
  2245. private void button6_Click(object sender, EventArgs e)
  2246. {
  2247. Process.Start(txtDownloadFolder.Text);
  2248. }
  2249. private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  2250. {
  2251. InfoForm lf = new InfoForm(downloadLog);
  2252. lf.ShowDialog(this);
  2253. }
  2254. private void txtDownloadFolder_TextChanged(object sender, EventArgs e)
  2255. {
  2256. Options.CurrentOptions.AppsFolder = txtDownloadFolder.Text;
  2257. Options.SaveSettings();
  2258. }
  2259. private void chkOnlyRemovable_CheckedChanged(object sender, EventArgs e)
  2260. {
  2261. GetModernApps(!chkOnlyRemovable.Checked);
  2262. }
  2263. private void btnGetFeed_Click(object sender, EventArgs e)
  2264. {
  2265. GetFeed();
  2266. }
  2267. private void l2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  2268. {
  2269. AboutForm f = new AboutForm();
  2270. f.ShowDialog(this);
  2271. //Process.Start("https://github.com/hellzerg/optimizer");
  2272. }
  2273. private void btnViewLog_Click(object sender, EventArgs e)
  2274. {
  2275. if (File.Exists(ErrorLogger.ErrorLogFile))
  2276. {
  2277. InfoForm iform = new InfoForm(File.ReadAllText(ErrorLogger.ErrorLogFile, Encoding.UTF8));
  2278. iform.ShowDialog();
  2279. }
  2280. else
  2281. {
  2282. MessageBox.Show(Options.TranslationList["noErrorsM"].ToString(), "Optimizer", MessageBoxButtons.OK, MessageBoxIcon.Information);
  2283. }
  2284. }
  2285. private void btnOpenConf_Click(object sender, EventArgs e)
  2286. {
  2287. Process.Start(Required.CoreFolder);
  2288. }
  2289. private void btnPing_Click(object sender, EventArgs e)
  2290. {
  2291. if (string.IsNullOrEmpty(txtPingInput.Text)) return;
  2292. _pingResults = new List<PingReply>();
  2293. listPingResults.Items.Clear();
  2294. if (Utilities.PingHost(txtPingInput.Text) == null)
  2295. {
  2296. listPingResults.Items.Add(string.Format("{0} [{1}]", Options.TranslationList["hostNotFound"], txtPingInput.Text));
  2297. return;
  2298. }
  2299. Task pinger = new Task(() =>
  2300. {
  2301. btnShodan.Enabled = false;
  2302. btnPing.Enabled = false;
  2303. listPingResults.Items.Add(string.Format("{0} [{1}]", Options.TranslationList["pinging"], txtPingInput.Text));
  2304. listPingResults.Items.Add("");
  2305. for (int i = 0; i < 9; i++)
  2306. {
  2307. // wait before each pinging
  2308. System.Threading.Thread.Sleep(888);
  2309. tmpReply = Utilities.PingHost(txtPingInput.Text);
  2310. if (tmpReply.Address == null)
  2311. {
  2312. listPingResults.Items.Add(tmpReply.Status);
  2313. }
  2314. else
  2315. {
  2316. _pingResults.Add(tmpReply);
  2317. _shodanIP = _pingResults[i].Address.ToString();
  2318. listPingResults.Items.Add(string.Format("{0} - {1}: {2} ms - TTL: {3}", _pingResults[i].Status, Options.TranslationList["latency"], _pingResults[i].RoundtripTime, _pingResults[i].Options.Ttl));
  2319. }
  2320. }
  2321. listPingResults.Items.Add("");
  2322. // calculate statistics
  2323. if (_pingResults.Count > 0)
  2324. {
  2325. long maxLatency = _pingResults.Max(x => x.RoundtripTime);
  2326. long minLatency = _pingResults.Min(x => x.RoundtripTime);
  2327. double averageLatency = _pingResults.Average(x => x.RoundtripTime);
  2328. listPingResults.Items.Add(string.Format("{0} = {1}, {2} = {3}, {4} = {5:F2}", Options.TranslationList["min"], minLatency, Options.TranslationList["max"], maxLatency, Options.TranslationList["avg"], averageLatency));
  2329. }
  2330. else
  2331. {
  2332. listPingResults.Items.Add(Options.TranslationList["timeout"]);
  2333. }
  2334. btnPing.Enabled = true;
  2335. btnShodan.Enabled = true;
  2336. });
  2337. pinger.Start();
  2338. }
  2339. private void btnCheckFootprint_Click(object sender, EventArgs e)
  2340. {
  2341. CleanHelper.CheckFootprint();
  2342. }
  2343. private void btnShodan_Click(object sender, EventArgs e)
  2344. {
  2345. IPAddress tryIP;
  2346. if (IPAddress.TryParse(txtPingInput.Text, out tryIP))
  2347. {
  2348. Process.Start(string.Format("https://www.shodan.io/host/{0}", txtPingInput.Text));
  2349. return;
  2350. }
  2351. if (!string.IsNullOrEmpty(_shodanIP))
  2352. {
  2353. Process.Start(string.Format("https://www.shodan.io/host/{0}", _shodanIP));
  2354. return;
  2355. }
  2356. }
  2357. private void button9_Click(object sender, EventArgs e)
  2358. {
  2359. try
  2360. {
  2361. Clipboard.SetText(_shodanIP);
  2362. }
  2363. catch { }
  2364. }
  2365. private void button7_Click(object sender, EventArgs e)
  2366. {
  2367. try
  2368. {
  2369. Clipboard.SetText(txtPingInput.Text);
  2370. }
  2371. catch { }
  2372. }
  2373. private void txtPingInput_KeyDown(object sender, KeyEventArgs e)
  2374. {
  2375. if (e.KeyCode == Keys.Enter) btnPing.PerformClick();
  2376. }
  2377. private void btnExport_Click(object sender, EventArgs e)
  2378. {
  2379. if (ExportDialog.ShowDialog() == DialogResult.OK)
  2380. {
  2381. try
  2382. {
  2383. File.WriteAllLines(ExportDialog.FileName, listPingResults.Items.Cast<string>());
  2384. }
  2385. catch (Exception ex)
  2386. {
  2387. ErrorLogger.LogError("btnExport.Click", ex.Message, ex.StackTrace);
  2388. MessageBox.Show(ex.Message, "Optimizer", MessageBoxButtons.OK, MessageBoxIcon.Information);
  2389. }
  2390. }
  2391. }
  2392. private void startupItem_Click(object sender, EventArgs e)
  2393. {
  2394. tabCollection.SelectedTab = startupTab;
  2395. RestoreWindow();
  2396. }
  2397. private void cleanerItem_Click(object sender, EventArgs e)
  2398. {
  2399. tabCollection.SelectedTab = cleanerTab;
  2400. RestoreWindow();
  2401. }
  2402. private void pingerItem_Click(object sender, EventArgs e)
  2403. {
  2404. tabCollection.SelectedTab = pingerTab;
  2405. RestoreWindow();
  2406. txtPingInput.Focus();
  2407. }
  2408. private void hostsItem_Click(object sender, EventArgs e)
  2409. {
  2410. tabCollection.SelectedTab = hostsEditorTab;
  2411. RestoreWindow();
  2412. txtIP.Focus();
  2413. }
  2414. private void appsItem_Click(object sender, EventArgs e)
  2415. {
  2416. tabCollection.SelectedTab = appsTab;
  2417. RestoreWindow();
  2418. }
  2419. private void exitItem_Click(object sender, EventArgs e)
  2420. {
  2421. _trayMenu = false;
  2422. Options.CurrentOptions.AppsFolder = txtDownloadFolder.Text;
  2423. Options.SaveSettings();
  2424. Application.Exit();
  2425. }
  2426. private void RestoreWindow()
  2427. {
  2428. if (this.WindowState == FormWindowState.Minimized) this.WindowState = FormWindowState.Normal;
  2429. this.Show();
  2430. this.Activate();
  2431. this.Focus();
  2432. }
  2433. private void launcherIcon_MouseDoubleClick(object sender, MouseEventArgs e)
  2434. {
  2435. if (this.Visible)
  2436. {
  2437. if (this.WindowState == FormWindowState.Minimized) this.WindowState = FormWindowState.Normal;
  2438. this.Hide();
  2439. }
  2440. else
  2441. {
  2442. RestoreWindow();
  2443. }
  2444. }
  2445. private void quickAccessToggle_CheckedChanged(object sender, EventArgs e)
  2446. {
  2447. Options.CurrentOptions.EnableTray = quickAccessToggle.Checked;
  2448. Options.SaveSettings();
  2449. _trayMenu = quickAccessToggle.Checked;
  2450. launcherIcon.Visible = quickAccessToggle.Checked;
  2451. }
  2452. private void linkLabel5_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  2453. {
  2454. Process.Start(_licenseLink);
  2455. }
  2456. private void linkLabel6_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  2457. {
  2458. Process.Start(_openSourceLink);
  2459. }
  2460. private void linkUpdate_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  2461. {
  2462. CheckForUpdate();
  2463. }
  2464. private void restartExpolorerItem_Click(object sender, EventArgs e)
  2465. {
  2466. Utilities.RestartExplorer();
  2467. }
  2468. private void button10_Click(object sender, EventArgs e)
  2469. {
  2470. Utilities.FlushDNSCache();
  2471. }
  2472. private void helpTipsToggle_CheckedChanged(object sender, EventArgs e)
  2473. {
  2474. Options.CurrentOptions.ShowHelp = helpTipsToggle.Checked;
  2475. Options.SaveSettings();
  2476. helpBox.Active = helpTipsToggle.Checked;
  2477. }
  2478. private void button11_Click(object sender, EventArgs e)
  2479. {
  2480. ShowBackupConfirm();
  2481. }
  2482. private void ShowBackupConfirm()
  2483. {
  2484. removeStartupItemB.Visible = false;
  2485. locateFileB.Visible = false;
  2486. findInRegB.Visible = false;
  2487. refreshStartupB.Visible = false;
  2488. restoreStartupB.Visible = false;
  2489. backupStartupB.Visible = false;
  2490. lblBackupTitle.Visible = true;
  2491. doBackup.Visible = true;
  2492. cancelBackup.Visible = true;
  2493. txtBackupTitle.Visible = true;
  2494. }
  2495. private void HideBackupConfirm()
  2496. {
  2497. removeStartupItemB.Visible = true;
  2498. locateFileB.Visible = true;
  2499. findInRegB.Visible = true;
  2500. refreshStartupB.Visible = true;
  2501. restoreStartupB.Visible = true;
  2502. backupStartupB.Visible = true;
  2503. lblBackupTitle.Visible = false;
  2504. doBackup.Visible = false;
  2505. cancelBackup.Visible = false;
  2506. txtBackupTitle.Visible = false;
  2507. }
  2508. private void button12_Click(object sender, EventArgs e)
  2509. {
  2510. StartupRestoreForm f = new StartupRestoreForm();
  2511. f.ShowDialog(this);
  2512. GetStartupItems();
  2513. }
  2514. private void button14_Click(object sender, EventArgs e)
  2515. {
  2516. HideBackupConfirm();
  2517. }
  2518. private void button13_Click(object sender, EventArgs e)
  2519. {
  2520. if (!string.IsNullOrEmpty(txtBackupTitle.Text.Trim()))
  2521. {
  2522. HideBackupConfirm();
  2523. _backupItems.Clear();
  2524. foreach (var x in _startUpItems)
  2525. {
  2526. _backupItems.Add(new StartupBackupItem(x.Name, x.FileLocation, x.RegistryLocation.ToString(), x.StartupType.ToString()));
  2527. }
  2528. try
  2529. {
  2530. File.WriteAllText(Required.StartupItemsBackupFolder + Utilities.SanitizeFileFolderName(txtBackupTitle.Text + " - [" + DateTime.Now.ToShortDateString() + "-" + DateTime.Now.ToShortTimeString()) + "].json", JsonConvert.SerializeObject(_backupItems, Formatting.Indented));
  2531. }
  2532. catch (Exception ex)
  2533. {
  2534. ErrorLogger.LogError("MainForm.BackupStartupItems", ex.Message, ex.StackTrace);
  2535. }
  2536. }
  2537. }
  2538. private void pictureBox86_Click(object sender, EventArgs e)
  2539. {
  2540. radioEnglish.PerformClick();
  2541. }
  2542. private void pictureBox87_Click(object sender, EventArgs e)
  2543. {
  2544. radioRussian.PerformClick();
  2545. }
  2546. private void radioEnglish_Click(object sender, EventArgs e)
  2547. {
  2548. radioEnglish.Checked = true;
  2549. Options.CurrentOptions.LanguageCode = LanguageCode.EN;
  2550. Options.SaveSettings();
  2551. Options.LoadTranslation();
  2552. Translate();
  2553. }
  2554. private void radioRussian_Click(object sender, EventArgs e)
  2555. {
  2556. radioRussian.Checked = true;
  2557. Options.CurrentOptions.LanguageCode = LanguageCode.RU;
  2558. Options.SaveSettings();
  2559. Options.LoadTranslation();
  2560. Translate();
  2561. }
  2562. private void pictureBox88_Click(object sender, EventArgs e)
  2563. {
  2564. radioHellenic.PerformClick();
  2565. }
  2566. private void radioHellenic_Click(object sender, EventArgs e)
  2567. {
  2568. radioHellenic.Checked = true;
  2569. Options.CurrentOptions.LanguageCode = LanguageCode.EL;
  2570. Options.SaveSettings();
  2571. Options.LoadTranslation();
  2572. Translate();
  2573. }
  2574. private void pictureBox89_Click(object sender, EventArgs e)
  2575. {
  2576. radioTurkish.PerformClick();
  2577. }
  2578. private void radioTurkish_Click(object sender, EventArgs e)
  2579. {
  2580. radioTurkish.Checked = true;
  2581. Options.CurrentOptions.LanguageCode = LanguageCode.TR;
  2582. Options.SaveSettings();
  2583. Options.LoadTranslation();
  2584. Translate();
  2585. }
  2586. private void radioGerman_Click(object sender, EventArgs e)
  2587. {
  2588. radioGerman.Checked = true;
  2589. Options.CurrentOptions.LanguageCode = LanguageCode.DE;
  2590. Options.SaveSettings();
  2591. Options.LoadTranslation();
  2592. Translate();
  2593. }
  2594. private void pictureBox2_Click(object sender, EventArgs e)
  2595. {
  2596. radioGerman.PerformClick();
  2597. }
  2598. private void pictureBox3_Click(object sender, EventArgs e)
  2599. {
  2600. radioSpanish.PerformClick();
  2601. }
  2602. private void radioSpanish_Click(object sender, EventArgs e)
  2603. {
  2604. radioSpanish.Checked = true;
  2605. Options.CurrentOptions.LanguageCode = LanguageCode.ES;
  2606. Options.SaveSettings();
  2607. Options.LoadTranslation();
  2608. Translate();
  2609. }
  2610. private void radioPortuguese_Click(object sender, EventArgs e)
  2611. {
  2612. radioPortuguese.Checked = true;
  2613. Options.CurrentOptions.LanguageCode = LanguageCode.PT;
  2614. Options.SaveSettings();
  2615. Options.LoadTranslation();
  2616. Translate();
  2617. }
  2618. private void pictureBox4_Click(object sender, EventArgs e)
  2619. {
  2620. radioPortuguese.PerformClick();
  2621. }
  2622. private void txtIPv4_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  2623. {
  2624. Clipboard.SetText(txtIPv4.Text);
  2625. }
  2626. private void txtIPv4A_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  2627. {
  2628. Clipboard.SetText(txtIPv4A.Text);
  2629. }
  2630. private void txtIPv6_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  2631. {
  2632. Clipboard.SetText(txtIPv6.Text);
  2633. }
  2634. private void txtIPv6A_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  2635. {
  2636. Clipboard.SetText(txtIPv6A.Text);
  2637. }
  2638. private void btnOpenNetwork_Click(object sender, EventArgs e)
  2639. {
  2640. Process.Start("NCPA.cpl");
  2641. }
  2642. private void radioFrench_Click(object sender, EventArgs e)
  2643. {
  2644. radioFrench.Checked = true;
  2645. Options.CurrentOptions.LanguageCode = LanguageCode.FR;
  2646. Options.SaveSettings();
  2647. Options.LoadTranslation();
  2648. Translate();
  2649. }
  2650. private void pictureBox5_Click(object sender, EventArgs e)
  2651. {
  2652. radioFrench.PerformClick();
  2653. }
  2654. }
  2655. }