MainForm.cs 101 KB

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