MainForm.cs 100 KB

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