MainForm.cs 108 KB

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