MainForm.cs 102 KB

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