MainForm.cs 96 KB

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