MainForm.cs 107 KB

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