MainForm.cs 100 KB

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