2
0

MainForm.cs 96 KB

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