MainForm.cs 99 KB

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