123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862 |
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Diagnostics;
- using System.Drawing;
- using System.Globalization;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Net.NetworkInformation;
- using System.Reflection;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace Optimizer
- {
- public partial class MainForm : Form
- {
- ListViewColumnSorter _columnSorter;
- List<StartupItem> _startUpItems = new List<StartupItem>();
- List<StartupBackupItem> _backupItems = new List<StartupBackupItem>();
- List<string> _hostsEntries = new List<string>();
- List<string> _customCommands = new List<string>();
- List<string> _desktopItems = new List<string>();
- List<string> _modernApps = new List<string>();
- bool _trayMenu = false;
- List<PingReply> _pingResults;
- string _shodanIP = string.Empty;
- PingReply tmpReply;
- NetworkMonitor _networkMonitor;
- double uploadSpeed = 0;
- double downloadSpeed = 0;
- DesktopItemType _desktopItemType = DesktopItemType.Program;
- DesktopTypePosition _desktopItemPosition = DesktopTypePosition.Top;
- public List<FeedApp> AppsFromFeed = new List<FeedApp>();
- readonly string _feedLink = "https://raw.githubusercontent.com/hellzerg/optimizer/master/feed.json";
- readonly string _licenseLink = "https://www.gnu.org/licenses/gpl-3.0.en.html";
- readonly string _openSourceLink = "https://opensource.org/";
- readonly string _latestVersionLink = "https://raw.githubusercontent.com/hellzerg/optimizer/master/version.txt";
- readonly string _changelogLink = "https://github.com/hellzerg/optimizer/blob/master/CHANGELOG.md";
- string _noNewVersionMessage = "You already have the latest version!";
- string _betaVersionMessage = "You are using an experimental version!";
- readonly string _blockedIP = "0.0.0.0";
- string _restartMessage = "Restart to apply changes?";
- string _removeStartupItemsMessage = "Are you sure you want to delete all startup items?";
- string _removeHostsEntriesMessage = "Are you sure you want to delete all hosts entries?";
- string _removeDesktopItemsMessage = "Are you sure you want to delete all desktop items?";
- string _removeModernAppsMessage = "Are you sure you want to uninstall the following app(s)?";
- string _errorModernAppsMessage = "The following app(s) couldn't be uninstalled:\n";
- 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!";
- private string NewVersionMessage(string latestVersion)
- {
- return Options.TranslationList["newVersion"].ToString().Replace("{LATEST}", latestVersion).Replace("{CURRENT}", Program.GetCurrentVersionTostring());
- }
- private string NewDownloadLink(string latestVersion)
- {
- return string.Format("https://github.com/hellzerg/optimizer/releases/download/{0}/Optimizer-{0}.exe", latestVersion);
- }
- private void CheckForUpdate(bool silentCheck = false)
- {
- WebClient client = new WebClient
- {
- Encoding = Encoding.UTF8
- };
- string latestVersion = string.Empty;
- try
- {
- latestVersion = client.DownloadString(_latestVersionLink).Trim();
- }
- catch (Exception ex)
- {
- ErrorLogger.LogError("MainForm.CheckForUpdate", ex.Message, ex.StackTrace);
- MessageBox.Show(ex.Message, "Optimizer", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- if (!string.IsNullOrEmpty(latestVersion))
- {
- if (float.Parse(latestVersion) > Program.GetCurrentVersion())
- {
- // show UPDATE AVAILABLE on app launch
- if (silentCheck)
- {
- linkUpdate.Visible = true;
- return;
- }
- if (MessageBox.Show(NewVersionMessage(latestVersion), "Optimizer", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- // PATCHING PROCESS
- try
- {
- Assembly currentAssembly = Assembly.GetEntryAssembly();
- if (currentAssembly == null)
- {
- currentAssembly = Assembly.GetCallingAssembly();
- }
- string appFolder = Path.GetDirectoryName(currentAssembly.Location);
- string appName = Path.GetFileNameWithoutExtension(currentAssembly.Location);
- string appExtension = Path.GetExtension(currentAssembly.Location);
- string archiveFile = Path.Combine(appFolder, "Optimizer_old" + appExtension);
- string appFile = Path.Combine(appFolder, appName + appExtension);
- string tempFile = Path.Combine(appFolder, "Optimizer_tmp" + appExtension);
- // DOWNLOAD NEW VERSION
- client.DownloadFile(NewDownloadLink(latestVersion), tempFile);
- // DELETE PREVIOUS BACK-UP
- if (File.Exists(archiveFile))
- {
- File.Delete(archiveFile);
- }
- // MAKE BACK-UP
- File.Move(appFile, archiveFile);
- // PATCH
- File.Move(tempFile, appFile);
- _trayMenu = false;
- Application.Restart();
- }
- catch (Exception ex)
- {
- ErrorLogger.LogError("MainForm.CheckForUpdate", ex.Message, ex.StackTrace);
- MessageBox.Show(ex.Message);
- }
- }
- }
- else if (float.Parse(latestVersion) == Program.GetCurrentVersion())
- {
- if (!silentCheck) MessageBox.Show(_noNewVersionMessage, "Optimizer", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- else
- {
- if (!silentCheck) MessageBox.Show(_betaVersionMessage, "Optimizer", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- }
- private void EnableToggleEvents()
- {
- actionSw.Click += new EventHandler(ToggleSwitch7_Click);
- officeTelemetrySw.Click += new EventHandler(toggleSwitch12_Click);
- telemetryTasksSw.Click += new EventHandler(toggleSwitch11_Click);
- superfetchSw.Click += new EventHandler(toggleSwitch10_Click);
- homegroupSw.Click += new EventHandler(toggleSwitch9_Click);
- reportingSw.Click += new EventHandler(toggleSwitch8_Click);
- mediaSharingSw.Click += new EventHandler(toggleSwitch6_Click);
- printSw.Click += new EventHandler(toggleSwitch5_Click);
- systemRestoreSw.Click += new EventHandler(toggleSwitch4_Click);
- performanceSw.Click += new EventHandler(toggleSwitch1_Click);
- defenderSw.Click += new EventHandler(toggleSwitch3_Click);
- networkSw.Click += new EventHandler(toggleSwitch2_Click);
- darkSw.Click += new EventHandler(toggleSwitch27_Click);
- spellSw.Click += new EventHandler(toggleSwitch28_Click);
- inkSw.Click += new EventHandler(toggleSwitch29_Click);
- driversSw.Click += new EventHandler(toggleSwitch30_Click);
- sensorSw.Click += new EventHandler(toggleSwitch20_Click);
- privacySw.Click += new EventHandler(toggleSwitch21_Click);
- telemetryServicesSw.Click += new EventHandler(toggleSwitch23_Click);
- autoUpdatesSw.Click += new EventHandler(toggleSwitch24_Click);
- peopleSw.Click += new EventHandler(toggleSwitch25_Click);
- adsSw.Click += new EventHandler(toggleSwitch26_Click);
- xboxSw.Click += new EventHandler(toggleSwitch17_Click);
- cortanaSw.Click += new EventHandler(toggleSwitch16_Click);
- gameBarSw.Click += new EventHandler(toggleSwitch15_Click);
- uODSw.Click += new EventHandler(toggleSwitch14_Click);
- oldMixerSw.Click += new EventHandler(toggleSwitch13_Click);
- disableOneDriveSw.Click += new EventHandler(toggleSwitch31_Click);
- oldExplorerSw.Click += new EventHandler(toggleSwitch18_Click);
- colorBarSw.Click += new EventHandler(toggleSwitch19_Click);
- compatSw.Click += new EventHandler(toggleSwitch32_Click);
- faxSw.Click += new EventHandler(ToggleSwitch33_Click);
- insiderSw.Click += new EventHandler(ToggleSwitch34_Click);
- featuresSw.Click += new EventHandler(ToggleSwitch35_Click);
- smartScreenSw.Click += new EventHandler(ToggleSwitch36_Click);
- ccSw.Click += new EventHandler(ToggleSwitch37_Click);
- stickySw.Click += new EventHandler(ToggleSwitch38_Click);
- longPathsSw.Click += new EventHandler(ToggleSwitch39_Click);
- castSw.Click += new EventHandler(ToggleSwitch40_Click);
- }
- private void SetHelpBoxTranslation()
- {
- helpBox.SetToolTip(performanceSw, Options.TranslationList["performanceTip"].ToString());
- helpBox.SetToolTip(networkSw, Options.TranslationList["networkTip"].ToString());
- helpBox.SetToolTip(defenderSw, Options.TranslationList["defenderTip"].ToString());
- helpBox.SetToolTip(smartScreenSw, Options.TranslationList["smartScreenTip"].ToString());
- helpBox.SetToolTip(systemRestoreSw, Options.TranslationList["systemRestoreTip"].ToString());
- helpBox.SetToolTip(reportingSw, Options.TranslationList["reportingTip"].ToString());
- helpBox.SetToolTip(telemetryTasksSw, Options.TranslationList["telemetryTasksTip"].ToString());
- helpBox.SetToolTip(officeTelemetrySw, Options.TranslationList["officeTelemetryTip"].ToString());
- helpBox.SetToolTip(printSw, Options.TranslationList["printTip"].ToString());
- helpBox.SetToolTip(faxSw, Options.TranslationList["faxTip"].ToString());
- helpBox.SetToolTip(mediaSharingSw, Options.TranslationList["mediaSharingTip"].ToString());
- helpBox.SetToolTip(stickySw, Options.TranslationList["stickyTip"].ToString());
- helpBox.SetToolTip(homegroupSw, Options.TranslationList["homegroupTip"].ToString());
- helpBox.SetToolTip(superfetchSw, Options.TranslationList["superfetchTip"].ToString());
- helpBox.SetToolTip(compatSw, Options.TranslationList["compatTip"].ToString());
- helpBox.SetToolTip(disableOneDriveSw, Options.TranslationList["disableOneDriveTip"].ToString());
- helpBox.SetToolTip(oldMixerSw, Options.TranslationList["oldMixerTip"].ToString());
- helpBox.SetToolTip(colorBarSw, Options.TranslationList["colorBarTip"].ToString());
- helpBox.SetToolTip(oldExplorerSw, Options.TranslationList["oldExplorerTip"].ToString());
- helpBox.SetToolTip(adsSw, Options.TranslationList["adsTip"].ToString());
- helpBox.SetToolTip(darkSw, Options.TranslationList["darkTip"].ToString());
- helpBox.SetToolTip(uODSw, Options.TranslationList["uODTip"].ToString());
- helpBox.SetToolTip(peopleSw, Options.TranslationList["peopleTip"].ToString());
- helpBox.SetToolTip(longPathsSw, Options.TranslationList["longPathsTip"].ToString());
- helpBox.SetToolTip(inkSw, Options.TranslationList["inkTip"].ToString());
- helpBox.SetToolTip(spellSw, Options.TranslationList["spellTip"].ToString());
- helpBox.SetToolTip(xboxSw, Options.TranslationList["xboxTip"].ToString());
- helpBox.SetToolTip(actionSw, Options.TranslationList["actionTip"].ToString());
- helpBox.SetToolTip(autoUpdatesSw, Options.TranslationList["autoUpdatesTip"].ToString());
- helpBox.SetToolTip(driversSw, Options.TranslationList["driversTip"].ToString());
- helpBox.SetToolTip(telemetryServicesSw, Options.TranslationList["telemetryServicesTip"].ToString());
- helpBox.SetToolTip(privacySw, Options.TranslationList["privacyTip"].ToString());
- helpBox.SetToolTip(ccSw, Options.TranslationList["ccTip"].ToString());
- helpBox.SetToolTip(cortanaSw, Options.TranslationList["cortanaTip"].ToString());
- helpBox.SetToolTip(sensorSw, Options.TranslationList["sensorTip"].ToString());
- helpBox.SetToolTip(castSw, Options.TranslationList["castTip"].ToString());
- helpBox.SetToolTip(gameBarSw, Options.TranslationList["gameBarTip"].ToString());
- helpBox.SetToolTip(insiderSw, Options.TranslationList["insiderTip"].ToString());
- helpBox.SetToolTip(featuresSw, Options.TranslationList["featuresTip"].ToString());
- helpBox.ToolTipTitle = Options.TranslationList["tipWhatsThis"].ToString();
- }
- private void ToggleSwitch7_Click(object sender, EventArgs e)
- {
- if (!actionSw.Checked)
- {
- Optimize.DisableActionCenter();
- }
- else
- {
- Optimize.EnableActionCenter();
- }
- Options.CurrentOptions.DisableActionCenter = !actionSw.Checked;
- }
- private void ToggleSwitch40_Click(object sender, EventArgs e)
- {
- if (!castSw.Checked)
- {
- Optimize.RemoveCastToDevice();
- }
- else
- {
- Optimize.AddCastToDevice();
- }
- Options.CurrentOptions.RemoveCastToDevice = !castSw.Checked;
- }
- private void ToggleSwitch39_Click(object sender, EventArgs e)
- {
- if (!longPathsSw.Checked)
- {
- Optimize.EnableLongPaths();
- }
- else
- {
- Optimize.DisableLongPaths();
- }
- Options.CurrentOptions.EnableLongPaths = !longPathsSw.Checked;
- }
- private void ToggleSwitch38_Click(object sender, EventArgs e)
- {
- if (!stickySw.Checked)
- {
- Optimize.DisableStickyKeys();
- }
- else
- {
- Optimize.EnableStickyKeys();
- }
- Options.CurrentOptions.DisableStickyKeys = !stickySw.Checked;
- }
- private void ToggleSwitch37_Click(object sender, EventArgs e)
- {
- if (!ccSw.Checked)
- {
- Optimize.DisableCloudClipboard();
- }
- else
- {
- Optimize.EnableCloudClipboard();
- }
- Options.CurrentOptions.DisableCloudClipboard = !ccSw.Checked;
- }
- private void ToggleSwitch36_Click(object sender, EventArgs e)
- {
- if (!smartScreenSw.Checked)
- {
- Optimize.DisableSmartScreen();
- }
- else
- {
- Optimize.EnableSmartScreen();
- }
- Options.CurrentOptions.DisableSmartScreen = !smartScreenSw.Checked;
- }
- private void ToggleSwitch35_Click(object sender, EventArgs e)
- {
- if (!featuresSw.Checked)
- {
- Optimize.DisableForcedFeatureUpdates();
- }
- else
- {
- Optimize.EnableForcedFeatureUpdates();
- }
- Options.CurrentOptions.DisableFeatureUpdates = !featuresSw.Checked;
- }
- private void ToggleSwitch34_Click(object sender, EventArgs e)
- {
- if (!insiderSw.Checked)
- {
- Optimize.DisableInsiderService();
- }
- else
- {
- Optimize.EnableInsiderService();
- }
- Options.CurrentOptions.DisableInsiderService = !insiderSw.Checked;
- }
- private void ToggleSwitch33_Click(object sender, EventArgs e)
- {
- if (!faxSw.Checked)
- {
- Optimize.DisableFaxService();
- }
- else
- {
- Optimize.EnableFaxService();
- }
- Options.CurrentOptions.DisableFaxService = !faxSw.Checked;
- }
- private void LoadSettings()
- {
- switch (Options.CurrentOptions.Color)
- {
- case Theme.Caramel:
- radioCaramel.Checked = true;
- break;
- case Theme.Lime:
- radioLime.Checked = true;
- break;
- case Theme.Magma:
- radioMagma.Checked = true;
- break;
- case Theme.Minimal:
- radioMinimal.Checked = true;
- break;
- case Theme.Ocean:
- radioOcean.Checked = true;
- break;
- case Theme.Zerg:
- radioZerg.Checked = true;
- break;
- }
- }
- //INIT
- public MainForm()
- {
- InitializeComponent();
- CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
- CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("en-US");
- CheckForIllegalCrossThreadCalls = false;
- EnableToggleEvents();
- // theming
- Options.ApplyTheme(this);
- launcherMenu.Renderer = new ToolStripRendererMaterial();
- progressDownloader.BackColor = Options.ForegroundColor;
- progressDownloader.ForeColor = Options.ForegroundAccentColor;
- // quick access
- _trayMenu = Options.CurrentOptions.EnableTray;
- quickAccessToggle.Checked = Options.CurrentOptions.EnableTray;
- launcherIcon.Visible = Options.CurrentOptions.EnableTray;
- // help tips
- helpBox.Active = Options.CurrentOptions.ShowHelp;
- helpTipsToggle.Checked = Options.CurrentOptions.ShowHelp;
- // fix SSL/TLS error when contacting internet
- ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
- // initial states
- chkOnlyRemovable.Checked = true;
- checkDefaultIcon.Checked = true;
- radioProgram.Checked = true;
- radioTop.Checked = true;
- c64.Checked = Environment.Is64BitOperatingSystem;
- c32.Checked = !Environment.Is64BitOperatingSystem;
- // EXPERIMENTAL message
- lblLab.Visible = Program.EXPERIMENTAL_BUILD;
- // Windows version, architecture, .NET Framework
- txtOS.Text = Utilities.GetOS();
- txtBitness.Text = Utilities.GetBitness();
- txtNetFw.Text = ".NET Framework " + Utilities.CheckNETFramework();
- if (Utilities.CurrentWindowsVersion == WindowsVersion.Unsupported)
- {
- tabCollection.TabPages.Remove(universalTab);
- tabCollection.TabPages.Remove(windowsVIIITab);
- tabCollection.TabPages.Remove(windowsXTab);
- tabCollection.TabPages.Remove(modernAppsTab);
- }
- if (Utilities.CurrentWindowsVersion == WindowsVersion.Windows7)
- {
- LoadUniversalToggleStates();
- tabCollection.TabPages.Remove(windowsVIIITab);
- tabCollection.TabPages.Remove(windowsXTab);
- tabCollection.TabPages.Remove(modernAppsTab);
- }
- if (Utilities.CurrentWindowsVersion == WindowsVersion.Windows8)
- {
- LoadUniversalToggleStates();
- LoadWindowsVIIIToggleStates();
- tabCollection.TabPages.Remove(windowsXTab);
- GetModernApps(false);
- }
- if (Utilities.CurrentWindowsVersion == WindowsVersion.Windows10)
- {
- LoadUniversalToggleStates();
- LoadWindowsXToggleStates();
- tabCollection.TabPages.Remove(windowsVIIITab);
- GetModernApps(false);
- }
- _columnSorter = new ListViewColumnSorter();
- listStartupItems.ListViewItemSorter = _columnSorter;
- GetStartupItems();
- GetHostsEntries();
- GetDesktopItems();
- GetCustomCommands();
- GetFeed();
- GetFootprint();
- LoadSettings();
- // Translation-related
- if (Options.CurrentOptions.LanguageCode == LanguageCode.EN)
- {
- radioEnglish.Checked = true;
- Translate(true);
- }
- else
- {
- Translate();
- }
- if (Options.CurrentOptions.LanguageCode == LanguageCode.RU) radioRussian.Checked = true;
- if (Options.CurrentOptions.LanguageCode == LanguageCode.TR) radioTurkish.Checked = true;
- if (Options.CurrentOptions.LanguageCode == LanguageCode.EL) radioHellenic.Checked = true;
- if (Options.CurrentOptions.LanguageCode == LanguageCode.DE) radioGerman.Checked = true;
- Program.MainForm = this;
- if (string.IsNullOrEmpty(Options.CurrentOptions.AppsFolder))
- {
- txtDownloadFolder.Text = Path.Combine(Application.StartupPath, "Optimizer Downloads");
- Options.CurrentOptions.AppsFolder = Path.Combine(Application.StartupPath, "Optimizer Downloads");
- Directory.CreateDirectory(Options.CurrentOptions.AppsFolder);
- Options.SaveSettings();
- }
- else
- {
- if (!Directory.Exists(Options.CurrentOptions.AppsFolder))
- {
- try
- {
- Directory.CreateDirectory(Options.CurrentOptions.AppsFolder);
- }
- catch (Exception ex)
- {
- txtDownloadFolder.Text = string.Empty;
- ErrorLogger.LogError("MainForm.INIT", ex.Message, ex.StackTrace);
- }
- }
- txtDownloadFolder.Text = Options.CurrentOptions.AppsFolder;
- }
- if (!Program.EXPERIMENTAL_BUILD && Utilities.IsInternetAvailable()) CheckForUpdate(true);
- if (Program.EXPERIMENTAL_BUILD)
- {
- btnUpdate.Enabled = false;
- lblUpdateDisabled.Visible = true;
- }
- // network monitoring
- _networkMonitor = new NetworkMonitor();
- }
- private void NetworkMonitoring()
- {
- while (true)
- {
- downloadSpeed = 0;
- uploadSpeed = 0;
- foreach (NetworkAdapter adapter in _networkMonitor.Adapters)
- {
- //adapter.Refresh();
- downloadSpeed += Math.Round(adapter.DownloadSpeedMbps, 2);
- uploadSpeed += Math.Round(adapter.UploadSpeedMbps, 2);
- }
- this.Text = string.Format("Optimizer - DOWN: {0} UP: {1}", downloadSpeed, uploadSpeed);
- Thread.Sleep(1000);
- }
- }
- private void Translate(bool skipFull = false)
- {
- Dictionary<string, string> translationList = Options.TranslationList.ToObject<Dictionary<string, string>>();
- if (Environment.Is64BitOperatingSystem)
- {
- translationList["txtBitness"] = translationList["txtBitness"].Replace("{BITS}", translationList["c64"]);
- }
- else
- {
- translationList["txtBitness"] = translationList["txtBitness"].Replace("{BITS}", translationList["c32"]);
- }
- SetHelpBoxTranslation();
- if (!skipFull)
- {
- _noNewVersionMessage = Options.TranslationList["noNewVersion"];
- _betaVersionMessage = Options.TranslationList["betaVersion"];
- _restartMessage = Options.TranslationList["restartAndApply"];
- _removeStartupItemsMessage = Options.TranslationList["removeAllStartup"];
- _removeHostsEntriesMessage = Options.TranslationList["removeAllHosts"];
- _removeDesktopItemsMessage = Options.TranslationList["removeAllItems"];
- _removeModernAppsMessage = Options.TranslationList["removeModernApps"];
- _errorModernAppsMessage = Options.TranslationList["errorModernApps"];
- _resetMessage = Options.TranslationList["resetMessage"];
- listStartupItems.Columns[0].Text = translationList["startupItemName"];
- listStartupItems.Columns[1].Text = translationList["startupItemLocation"];
- listStartupItems.Columns[2].Text = translationList["startupItemType"];
- trayStartup.Text = translationList["trayStartup"];
- trayCleaner.Text = translationList["trayCleaner"];
- trayPinger.Text = translationList["trayPinger"];
- trayHosts.Text = translationList["trayHosts"];
- trayAD.Text = translationList["trayAD"];
- trayRestartExplorer.Text = translationList["trayRestartExplorer"];
- trayExit.Text = translationList["trayExit"];
- Control element;
- foreach (var x in translationList)
- {
- if (x.Key == null || x.Key == string.Empty) continue;
- element = this.Controls.Find(x.Key, true).FirstOrDefault();
- if (element == null) continue;
- if (element is ToggleSwitch)
- {
- ((ToggleSwitch)element).OnText = x.Value;
- continue;
- }
- element.Text = x.Value;
- }
- }
- txtVersion.Text = txtVersion.Text.Replace("{VN}", Program.GetCurrentVersionTostring());
- }
- private void GetFootprint()
- {
- ByteSize footprint = CleanHelper.CheckFootprint();
- lblFootprint.Text = footprint.ToString();
- }
- private void GetFeed()
- {
- WebClient client = new WebClient
- {
- Encoding = Encoding.UTF8
- };
- client.Headers.Add("Cache-Control", "no-cache");
- try
- {
- string feed = client.DownloadString(_feedLink);
- AppsFromFeed = JsonConvert.DeserializeObject<List<FeedApp>>(feed);
- AppCard appCard;
- groupSystemTools.Controls.Clear();
- groupInternet.Controls.Clear();
- groupCoding.Controls.Clear();
- groupSoundVideo.Controls.Clear();
- foreach (FeedApp x in AppsFromFeed)
- {
- appCard = new AppCard();
- appCard.AutoSize = true;
- appCard.Anchor = AnchorStyles.None;
- appCard.Anchor = AnchorStyles.Top | AnchorStyles.Left;
- appCard.appTitle.Text = x.Title;
- appCard.appTitle.Name = x.Tag;
- appCard.appImage.SizeMode = PictureBoxSizeMode.Zoom;
- appCard.appImage.LoadAsync(x.Image);
- switch (x.Group)
- {
- case "SystemTools":
- appCard.Location = new Point(0, groupSystemTools.Controls.Count * 30);
- groupSystemTools.Controls.Add(appCard);
- break;
- case "Internet":
- appCard.Location = new Point(0, groupInternet.Controls.Count * 30);
- groupInternet.Controls.Add(appCard);
- break;
- case "Coding":
- appCard.Location = new Point(0, groupCoding.Controls.Count * 30);
- groupCoding.Controls.Add(appCard);
- break;
- case "GraphicsSound":
- appCard.Location = new Point(0, groupSoundVideo.Controls.Count * 30);
- groupSoundVideo.Controls.Add(appCard);
- break;
- default:
- break;
- }
- }
- // UI handling
- btnDownloadApps.Enabled = true;
- txtFeedError.Visible = false;
- }
- catch (Exception ex)
- {
- btnDownloadApps.Enabled = false;
- txtFeedError.Visible = true;
- ErrorLogger.LogError("MainForm.GetFeed", ex.Message, ex.StackTrace);
- }
- }
- private void CleanPC()
- {
- try
- {
- if (checkTemp.Checked)
- {
- CleanHelper.CleanTemporaries();
- }
- if (checkMiniDumps.Checked)
- {
- CleanHelper.CleanMiniDumps();
- }
- if (checkMediaCache.Checked)
- {
- CleanHelper.CleanMediaPlayersCache();
- }
- if (checkLogs.Checked)
- {
- CleanHelper.CleanLogs();
- }
- if (checkErrorReports.Checked)
- {
- CleanHelper.CleanErrorReports();
- }
- if (checkBin.Checked)
- {
- CleanHelper.EmptyRecycleBin();
- }
- }
- catch (Exception ex)
- {
- ErrorLogger.LogError("MainForm.CleanPC", ex.Message, ex.StackTrace);
- }
- finally
- {
- Cleaning(false);
- GetFootprint();
- }
- }
- private bool FixRegistry()
- {
- bool changeDetected = false;
- try
- {
- if (checkFirewall.Checked)
- {
- Utilities.EnableFirewall();
- changeDetected = true;
- }
- if (checkCommandPrompt.Checked)
- {
- Utilities.EnableCommandPrompt();
- changeDetected = true;
- }
- if (checkControlPanel.Checked)
- {
- Utilities.EnableControlPanel();
- changeDetected = true;
- }
- if (checkFolderOptions.Checked)
- {
- Utilities.EnableFolderOptions();
- changeDetected = true;
- }
- if (checkRunDialog.Checked)
- {
- Utilities.EnableRunDialog();
- changeDetected = true;
- }
- if (checkContextMenu.Checked)
- {
- Utilities.EnableContextMenu();
- changeDetected = true;
- }
- if (checkTaskManager.Checked)
- {
- Utilities.EnableTaskManager();
- changeDetected = true;
- }
- if (checkRegistryEditor.Checked)
- {
- Utilities.EnableRegistryEditor();
- changeDetected = true;
- }
- }
- catch (Exception ex)
- {
- ErrorLogger.LogError("MainForm.FixRegistry", ex.Message, ex.StackTrace);
- }
- return changeDetected;
- }
- private void LoadUniversalToggleStates()
- {
- performanceSw.Checked = Options.CurrentOptions.EnablePerformanceTweaks;
- networkSw.Checked = Options.CurrentOptions.DisableNetworkThrottling;
- defenderSw.Checked = Options.CurrentOptions.DisableWindowsDefender;
- systemRestoreSw.Checked = Options.CurrentOptions.DisableSystemRestore;
- printSw.Checked = Options.CurrentOptions.DisablePrintService;
- mediaSharingSw.Checked = Options.CurrentOptions.DisableMediaPlayerSharing;
- reportingSw.Checked = Options.CurrentOptions.DisableErrorReporting;
- homegroupSw.Checked = Options.CurrentOptions.DisableHomeGroup;
- superfetchSw.Checked = Options.CurrentOptions.DisableSuperfetch;
- telemetryTasksSw.Checked = Options.CurrentOptions.DisableTelemetryTasks;
- officeTelemetrySw.Checked = Options.CurrentOptions.DisableOffice2016Telemetry;
- compatSw.Checked = Options.CurrentOptions.DisableCompatibilityAssistant;
- faxSw.Checked = Options.CurrentOptions.DisableFaxService;
- smartScreenSw.Checked = Options.CurrentOptions.DisableSmartScreen;
- stickySw.Checked = Options.CurrentOptions.DisableStickyKeys;
- }
- private void LoadWindowsVIIIToggleStates()
- {
- disableOneDriveSw.Checked = Options.CurrentOptions.DisableOneDrive;
- }
- private void LoadWindowsXToggleStates()
- {
- oldMixerSw.Checked = Options.CurrentOptions.EnableLegacyVolumeSlider;
- uODSw.Checked = Options.CurrentOptions.UninstallOneDrive;
- gameBarSw.Checked = Options.CurrentOptions.DisableGameBar;
- cortanaSw.Checked = Options.CurrentOptions.DisableCortana;
- xboxSw.Checked = Options.CurrentOptions.DisableXboxLive;
- oldExplorerSw.Checked = Options.CurrentOptions.DisableQuickAccessHistory;
- colorBarSw.Checked = Options.CurrentOptions.EnableTaskbarColor;
- sensorSw.Checked = Options.CurrentOptions.DisableSensorServices;
- privacySw.Checked = Options.CurrentOptions.DisablePrivacyOptions;
- telemetryServicesSw.Checked = Options.CurrentOptions.DisableTelemetryServices;
- autoUpdatesSw.Checked = Options.CurrentOptions.DisableAutomaticUpdates;
- peopleSw.Checked = Options.CurrentOptions.DisableMyPeople;
- adsSw.Checked = Options.CurrentOptions.DisableStartMenuAds;
- darkSw.Checked = Options.CurrentOptions.EnableDarkTheme;
- spellSw.Checked = Options.CurrentOptions.DisableSpellingTyping;
- inkSw.Checked = Options.CurrentOptions.DisableWindowsInk;
- driversSw.Checked = Options.CurrentOptions.ExcludeDrivers;
- insiderSw.Checked = Options.CurrentOptions.DisableInsiderService;
- featuresSw.Checked = Options.CurrentOptions.DisableFeatureUpdates;
- ccSw.Checked = Options.CurrentOptions.DisableCloudClipboard;
- longPathsSw.Checked = Options.CurrentOptions.EnableLongPaths;
- castSw.Checked = Options.CurrentOptions.RemoveCastToDevice;
- actionSw.Checked = Options.CurrentOptions.DisableActionCenter;
- }
- private void Main_Load(object sender, EventArgs e)
- {
- }
- private void GetDesktopItems()
- {
- _desktopItems = Integrator.GetDesktopItems();
- listDesktopItems.Items.Clear();
- for (int i = 0; i < _desktopItems.Count; i++)
- {
- if (!string.IsNullOrEmpty(_desktopItems[i]))
- {
- listDesktopItems.Items.Add(_desktopItems[i]);
- }
- }
- }
- private void GetHostsEntries()
- {
- ((Control)this.hostsEditorTab).Enabled = false;
- _hostsEntries = HostsHelper.GetHostsEntries();
- listHostEntries.Items.Clear();
- listHostEntries.Items.AddRange(_hostsEntries.ToArray());
- chkReadOnly.Checked = HostsHelper.GetReadOnly();
- addHostB.Enabled = !chkReadOnly.Checked;
- removeAllHostsB.Enabled = !chkReadOnly.Checked;
- removeHostB.Enabled = !chkReadOnly.Checked;
- refreshHostsB.Enabled = !chkReadOnly.Checked;
- linkRestoreDefault.Enabled = !chkReadOnly.Checked;
- chkBlock.Enabled = !chkReadOnly.Checked;
- txtDomain.Enabled = !chkReadOnly.Checked;
- txtIP.Enabled = !chkReadOnly.Checked;
- adblockBasic.Enabled = !chkReadOnly.Checked;
- adblockS.Enabled = !chkReadOnly.Checked;
- adblockP.Enabled = !chkReadOnly.Checked;
- adblockUlti.Enabled = !chkReadOnly.Checked;
- ((Control)this.hostsEditorTab).Enabled = true;
- }
- private void GetStartupItems()
- {
- _startUpItems = Utilities.GetStartupItems();
- listStartupItems.Items.Clear();
- for (int i = 0; i < _startUpItems.Count; i++)
- {
- ListViewItem list = new ListViewItem(_startUpItems[i].Name);
- list.SubItems.Add(_startUpItems[i].FileLocation);
- list.SubItems.Add(_startUpItems[i].ToString());
- listStartupItems.Items.Add(list);
- }
- }
- private void GetModernApps(bool showAll)
- {
- uninstallModernAppsButton.Enabled = false;
- refreshModernAppsButton.Enabled = false;
- listModernApps.Enabled = false;
- listModernApps.Items.Clear();
- _modernApps = Utilities.GetModernApps(showAll);
- foreach (string x in _modernApps)
- {
- listModernApps.Items.Add(x);
- }
- uninstallModernAppsButton.Enabled = true;
- refreshModernAppsButton.Enabled = true;
- listModernApps.Enabled = true;
- }
- private async void UninstallModernApps()
- {
- string selectedApps = string.Empty;
- if (listModernApps.CheckedItems.Count > 0)
- {
- foreach (string x in listModernApps.CheckedItems)
- {
- if (string.IsNullOrEmpty(selectedApps))
- {
- selectedApps = x;
- }
- else
- {
- selectedApps += Environment.NewLine + x;
- }
- }
- if (MessageBox.Show(_removeModernAppsMessage + "\n\n" + selectedApps, "Optimizer", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- uninstallModernAppsButton.Enabled = false;
- refreshModernAppsButton.Enabled = false;
- listModernApps.Enabled = false;
- bool errorOccured = false;
- string failedApps = string.Empty;
- foreach (string app in listModernApps.CheckedItems)
- {
- await Task.Run(() => errorOccured = Utilities.UninstallModernApp(app));
- if (errorOccured)
- {
- failedApps += Environment.NewLine + app;
- }
- }
- if (!string.IsNullOrEmpty(failedApps))
- {
- MessageBox.Show(_errorModernAppsMessage + failedApps, "Optimizer", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- GetModernApps(!chkOnlyRemovable.Checked);
- }
- }
- }
- private void GetCustomCommands()
- {
- _customCommands = Integrator.GetCustomCommands();
- listCustomCommands.Items.Clear();
- foreach (string s in _customCommands)
- {
- listCustomCommands.Items.Add(s);
- }
- }
- private void Main_FormClosing(object sender, FormClosingEventArgs e)
- {
- if (_trayMenu)
- {
- e.Cancel = true;
- this.Hide();
- }
- else
- {
- Options.CurrentOptions.AppsFolder = txtDownloadFolder.Text;
- Options.SaveSettings();
- }
- }
- private void button39_Click(object sender, EventArgs e)
- {
- HelperForm f = new HelperForm(this, MessageType.Restart, _restartMessage);
- f.ShowDialog();
- }
- private void button43_Click(object sender, EventArgs e)
- {
- HelperForm f = new HelperForm(this, MessageType.Restart, _restartMessage);
- f.ShowDialog();
- }
- private void button44_Click(object sender, EventArgs e)
- {
- HelperForm f = new HelperForm(this, MessageType.Restart, _restartMessage);
- f.ShowDialog();
- }
- private void button45_Click(object sender, EventArgs e)
- {
- HelperForm f = new HelperForm(this, MessageType.Restart, _restartMessage);
- f.ShowDialog();
- }
- private void checkSelectAll_CheckedChanged(object sender, EventArgs e)
- {
- checkTemp.Checked = checkSelectAll.Checked;
- checkMiniDumps.Checked = checkSelectAll.Checked;
- checkMediaCache.Checked = checkSelectAll.Checked;
- checkLogs.Checked = checkSelectAll.Checked;
- checkBin.Checked = checkSelectAll.Checked;
- checkErrorReports.Checked = checkSelectAll.Checked;
- }
- private void button20_Click(object sender, EventArgs e)
- {
- Cleaning(true);
- Task t = new Task(() => CleanPC());
- t.Start();
- }
- private void Cleaning(bool enabled)
- {
- cleanDriveB.Enabled = !enabled;
- cleanDriveB.Text = (enabled) ? "..." : Options.TranslationList["cleanDriveB"];
- }
- private void button32_Click(object sender, EventArgs e)
- {
- if (listStartupItems.SelectedItems.Count == 1)
- {
- _startUpItems[listStartupItems.SelectedIndices[0]].Remove();
- GetStartupItems();
- }
- }
- internal void RemoveAllStartupItems()
- {
- foreach (ListViewItem i in listStartupItems.Items)
- {
- _startUpItems[i.Index].Remove();
- }
- GetStartupItems();
- }
- // REMOVE ALL STARTUP ITEMS BUTTON
- //private void button22_Click(object sender, EventArgs e)
- //{
- // if (listStartupItems.Items.Count > 0)
- // {
- // HelperForm r = new HelperForm(this, MessageType.Startup, _removeStartupItemsMessage);
- // r.ShowDialog(this);
- // }
- //}
- private void button31_Click(object sender, EventArgs e)
- {
- if (listStartupItems.SelectedItems.Count == 1)
- {
- _startUpItems[listStartupItems.SelectedIndices[0]].LocateFile();
- }
- }
- private void checkEnableAll_CheckedChanged(object sender, EventArgs e)
- {
- checkTaskManager.Checked = checkEnableAll.Checked;
- checkCommandPrompt.Checked = checkEnableAll.Checked;
- checkControlPanel.Checked = checkEnableAll.Checked;
- checkFolderOptions.Checked = checkEnableAll.Checked;
- checkRunDialog.Checked = checkEnableAll.Checked;
- checkContextMenu.Checked = checkEnableAll.Checked;
- checkFirewall.Checked = checkEnableAll.Checked;
- checkRegistryEditor.Checked = checkEnableAll.Checked;
- }
- private void button33_Click(object sender, EventArgs e)
- {
- bool flag = FixRegistry();
- if (flag)
- {
- panel2.Enabled = false;
- regFixB.Enabled = false;
- if (checkRestartExplorer.Checked)
- {
- Utilities.RestartExplorer();
- }
- panel2.Enabled = true;
- regFixB.Enabled = true;
- }
- }
- private void pictureBox1_Click(object sender, EventArgs e)
- {
- AboutForm f = new AboutForm();
- f.ShowDialog(this);
- }
- private void button37_Click(object sender, EventArgs e)
- {
- GetStartupItems();
- }
- private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
- {
- HostsHelper.LocateHosts();
- }
- private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
- {
- HostsEditorForm f = new HostsEditorForm();
- f.ShowDialog(this);
- GetHostsEntries();
- }
- private void linkLabel4_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
- {
- HostsHelper.RestoreDefaultHosts();
- GetHostsEntries();
- }
- private void button47_Click(object sender, EventArgs e)
- {
- if ((txtIP.Text != string.Empty) && (txtDomain.Text != string.Empty))
- {
- string ip = txtIP.Text.Trim();
- string domain = txtDomain.Text.Trim();
- string recommendedDomain = string.Empty;
- if (!domain.StartsWith("www."))
- {
- recommendedDomain = "www." + domain;
- }
- else
- {
- recommendedDomain = domain.Replace("www.", string.Empty);
- }
- HostsHelper.AddEntry(HostsHelper.SanitizeEntry(ip) + " " + HostsHelper.SanitizeEntry(domain));
- if (!string.IsNullOrEmpty(recommendedDomain))
- {
- HostsHelper.AddEntry(HostsHelper.SanitizeEntry(ip) + " " + HostsHelper.SanitizeEntry(recommendedDomain));
- }
- GetHostsEntries();
- txtIP.Clear();
- txtDomain.Clear();
- chkBlock.Checked = false;
- }
- }
- private void button41_Click(object sender, EventArgs e)
- {
- GetHostsEntries();
- }
- private void button42_Click(object sender, EventArgs e)
- {
- if (listHostEntries.SelectedItems.Count == 1)
- {
- HostsHelper.RemoveEntry(listHostEntries.SelectedItem.ToString().Replace(" : ", " "));
- GetHostsEntries();
- }
- }
- private void button46_Click(object sender, EventArgs e)
- {
- if (listHostEntries.Items.Count > 0)
- {
- HelperForm r = new HelperForm(this, MessageType.Hosts, _removeHostsEntriesMessage);
- r.ShowDialog(this);
- }
- }
- internal void RemoveAllHostsEntries()
- {
- List<string> collection = new List<string>();
- foreach (string item in listHostEntries.Items)
- {
- collection.Add(item.Replace(" : ", " "));
- }
- HostsHelper.RemoveAllEntries(collection);
- GetHostsEntries();
- }
- private void aio_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (tabCollection.SelectedTab == hostsEditorTab) txtIP.Focus();
- if (tabCollection.SelectedTab == pingerTab)
- {
- txtPingInput.Focus();
- //_networkMonitor.StartMonitoring();
- //NetworkMonitoring();
- }
- //else
- //{
- // _networkMonitor.StopMonitoring();
- //}
- }
- private void button48_Click(object sender, EventArgs e)
- {
- defineCommandDialog.ShowDialog();
- }
- private void button50_Click(object sender, EventArgs e)
- {
- if (!string.IsNullOrEmpty(txtRunFile.Text) && !string.IsNullOrEmpty(txtRunKeyword.Text))
- {
- Integrator.CreateCustomCommand(txtRunFile.Text, txtRunKeyword.Text);
- txtRunFile.Clear();
- txtRunKeyword.Clear();
- GetCustomCommands();
- }
- }
- private void DefineCmd_FileOk(object sender, CancelEventArgs e)
- {
- txtRunFile.Text = defineCommandDialog.FileName;
- txtRunKeyword.Text = Path.GetFileNameWithoutExtension(txtRunFile.Text).ToLower();
- }
- private void button59_Click(object sender, EventArgs e)
- {
- Utilities.ImportRegistryScript(Required.ReadyMadeMenusFolder + "\\PowerMenu.reg");
- GetDesktopItems();
- }
- private void button53_Click(object sender, EventArgs e)
- {
- Utilities.ImportRegistryScript(Required.ReadyMadeMenusFolder + "\\SystemTools.reg");
- GetDesktopItems();
- }
- private void button54_Click(object sender, EventArgs e)
- {
- Utilities.ImportRegistryScript(Required.ReadyMadeMenusFolder + "\\WindowsApps.reg");
- GetDesktopItems();
- }
- private void button51_Click(object sender, EventArgs e)
- {
- Utilities.ImportRegistryScript(Required.ReadyMadeMenusFolder + "\\SystemShortcuts.reg");
- GetDesktopItems();
- }
- private void button57_Click(object sender, EventArgs e)
- {
- Utilities.ImportRegistryScript(Required.ReadyMadeMenusFolder + "\\DesktopShortcuts.reg");
- GetDesktopItems();
- }
- private void button60_Click(object sender, EventArgs e)
- {
- GetDesktopItems();
- }
- private void button61_Click(object sender, EventArgs e)
- {
- if (listDesktopItems.SelectedItems.Count == 1)
- {
- Integrator.RemoveItem(listDesktopItems.SelectedItem.ToString());
- GetDesktopItems();
- }
- }
- internal void RemoveAllDesktopItems()
- {
- List<string> collection = new List<string>();
- foreach (string item in listDesktopItems.Items)
- {
- collection.Add(item);
- }
- Integrator.RemoveAllItems(collection);
- GetDesktopItems();
- }
- private void button62_Click(object sender, EventArgs e)
- {
- if (listDesktopItems.Items.Count > 0)
- {
- HelperForm r = new HelperForm(this, MessageType.Integrator, _removeDesktopItemsMessage);
- r.ShowDialog(this);
- }
- }
- private void radioProgram_CheckedChanged(object sender, EventArgs e)
- {
- if (radioProgram.Checked)
- {
- btnBrowseItem.Enabled = true;
- txtItem.Clear();
- checkDefaultIcon.Checked = true;
- txtIcon.Enabled = false;
- btnBrowseIcon.Enabled = false;
- itemtoaddgroup.Text = Options.TranslationList["itemtoaddgroup"];
- checkDefaultIcon.Visible = true;
- checkDefaultIcon.Text = Options.TranslationList["checkDefaultIcon"];
- txtItemName.Clear();
- txtItem.ReadOnly = true;
- txtIcon.ReadOnly = true;
- _desktopItemType = DesktopItemType.Program;
- }
- }
- private void radioFolder_CheckedChanged(object sender, EventArgs e)
- {
- if (radioFolder.Checked)
- {
- checkDefaultIcon.Checked = true;
- btnBrowseItem.Enabled = true;
- txtItem.Clear();
- itemtoaddgroup.Text = Options.TranslationList["folderToAdd"];
- checkDefaultIcon.Text = Options.TranslationList["checkDefaultFolderIcon"];
- txtItemName.Clear();
- txtItem.ReadOnly = true;
- txtIcon.ReadOnly = true;
- _desktopItemType = DesktopItemType.Folder;
- }
- }
- private void radioLink_CheckedChanged(object sender, EventArgs e)
- {
- if (radioLink.Checked)
- {
- checkDefaultIcon.Checked = true;
- checkDefaultIcon.Text = Options.TranslationList["checkFavicon"];
- btnBrowseItem.Enabled = false;
- itemtoaddgroup.Text = Options.TranslationList["linkToAdd"];
- checkDefaultIcon.Visible = true;
- txtItem.Text = "http://";
- txtItemName.Clear();
- txtItem.ReadOnly = false;
- txtIcon.ReadOnly = true;
- _desktopItemType = DesktopItemType.Link;
- }
- }
- private void radioFile_CheckedChanged(object sender, EventArgs e)
- {
- if (radioFile.Checked)
- {
- checkDefaultIcon.Checked = true;
- checkDefaultIcon.Text = Options.TranslationList["checkNoIcon"];
- btnBrowseItem.Enabled = true;
- itemtoaddgroup.Text = Options.TranslationList["fileToAdd"];
- checkDefaultIcon.Visible = true;
- txtItem.Clear();
- txtItemName.Clear();
- txtItem.ReadOnly = true;
- txtIcon.ReadOnly = true;
- _desktopItemType = DesktopItemType.File;
- }
- }
- private void radioCommand_CheckedChanged(object sender, EventArgs e)
- {
- if (radioCommand.Checked)
- {
- btnBrowseItem.Enabled = false;
- txtItem.Clear();
- checkDefaultIcon.Checked = true;
- txtIcon.Enabled = false;
- btnBrowseIcon.Enabled = false;
- itemtoaddgroup.Text = Options.TranslationList["commandToAdd"];
- checkDefaultIcon.Visible = true;
- checkDefaultIcon.Text = Options.TranslationList["checkNoIcon"];
- txtItemName.Clear();
- txtItem.ReadOnly = false;
- txtIcon.ReadOnly = true;
- _desktopItemType = DesktopItemType.Command;
- }
- }
- private void checkDefaultIcon_CheckedChanged(object sender, EventArgs e)
- {
- if (checkDefaultIcon.Checked)
- {
- txtIcon.Clear();
- txtIcon.Enabled = false;
- btnBrowseIcon.Enabled = false;
- }
- else
- {
- txtIcon.Clear();
- txtIcon.Enabled = true;
- btnBrowseIcon.Enabled = true;
- }
- }
- private void btnBrowseItem_Click(object sender, EventArgs e)
- {
- switch (_desktopItemType)
- {
- case DesktopItemType.Program:
- defineProgramDialog.ShowDialog();
- break;
- case DesktopItemType.Folder:
- defineFolderDialog.ShowDialog();
- txtItem.Text = defineFolderDialog.SelectedPath;
- int i = defineFolderDialog.SelectedPath.LastIndexOf("\\");
- txtItemName.Text = defineFolderDialog.SelectedPath.Remove(0, i + 1);
- break;
- case DesktopItemType.File:
- defineFileDialog.ShowDialog();
- break;
- }
- }
- private void DefineProgramDialog_FileOk(object sender, CancelEventArgs e)
- {
- txtItem.Text = defineProgramDialog.FileName;
- txtItemName.Text = defineProgramDialog.SafeFileName.Replace(".exe", string.Empty);
- }
- private void DefineFileDialog_FileOk(object sender, CancelEventArgs e)
- {
- txtItem.Text = defineFileDialog.FileName;
- txtItemName.Text = defineFileDialog.SafeFileName;
- }
- private void btnBrowseIcon_Click(object sender, EventArgs e)
- {
- switch (_desktopItemType)
- {
- case DesktopItemType.Program:
- DefineProgramIconDialog.ShowDialog();
- break;
- case DesktopItemType.Folder:
- DefineFolderIconDialog.ShowDialog();
- break;
- case DesktopItemType.Link:
- DefineURLIconDialog.ShowDialog();
- break;
- case DesktopItemType.File:
- DefineFileIconDialog.ShowDialog();
- break;
- case DesktopItemType.Command:
- DefineCommandIconDialog.ShowDialog();
- break;
- }
- }
- private void DefineProgramIconDialog_FileOk(object sender, CancelEventArgs e)
- {
- txtIcon.Text = DefineProgramIconDialog.FileName;
- if (txtIcon.Text.Contains(".exe"))
- {
- string iconpath = Integrator.ExtractIconFromExecutable(txtItemName.Text, DefineProgramIconDialog.FileName);
- txtIcon.Text = iconpath;
- }
- }
- private void DefineFolderIconDialog_FileOk(object sender, CancelEventArgs e)
- {
- txtIcon.Text = DefineFolderIconDialog.FileName;
- if (txtIcon.Text.Contains(".exe"))
- {
- string iconpath = Integrator.ExtractIconFromExecutable(txtItemName.Text, DefineFolderIconDialog.FileName);
- txtIcon.Text = iconpath;
- }
- }
- private void DefineURLIconDialog_FileOk(object sender, CancelEventArgs e)
- {
- txtIcon.Text = DefineURLIconDialog.FileName;
- if (txtIcon.Text.Contains(".exe"))
- {
- string iconpath = Integrator.ExtractIconFromExecutable(txtItemName.Text, DefineURLIconDialog.FileName);
- txtIcon.Text = iconpath;
- }
- }
- private void DefineFileIconDialog_FileOk(object sender, CancelEventArgs e)
- {
- txtIcon.Text = DefineFileIconDialog.FileName;
- if (txtIcon.Text.Contains(".exe"))
- {
- string iconpath = Integrator.ExtractIconFromExecutable(txtItemName.Text, DefineFileIconDialog.FileName);
- txtIcon.Text = iconpath;
- }
- }
- private void DefineCommandIconDialog_FileOk(object sender, CancelEventArgs e)
- {
- txtIcon.Text = DefineCommandIconDialog.FileName;
- if (txtIcon.Text.Contains(".exe"))
- {
- string iconpath = Integrator.ExtractIconFromExecutable(txtItemName.Text, DefineCommandIconDialog.FileName);
- txtIcon.Text = iconpath;
- }
- }
- private void btnAddItem_Click(object sender, EventArgs e)
- {
- if (!checkDefaultIcon.Checked && (string.IsNullOrEmpty(txtItem.Text) || string.IsNullOrEmpty(txtItemName.Text) || string.IsNullOrEmpty(txtIcon.Text)))
- {
- return;
- }
- if (checkDefaultIcon.Checked && (string.IsNullOrEmpty(txtItem.Text) || string.IsNullOrEmpty(txtItemName.Text)))
- {
- return;
- }
- string icon = string.Empty;
- switch (_desktopItemType)
- {
- case DesktopItemType.Program:
- if (checkDefaultIcon.Checked)
- {
- icon = txtItem.Text;
- }
- else
- {
- icon = txtIcon.Text;
- }
- Integrator.AddItem(txtItemName.Text, txtItem.Text, icon, _desktopItemPosition, checkShift.Checked, DesktopItemType.Program);
- break;
- case DesktopItemType.Folder:
- if (checkDefaultIcon.Checked)
- {
- icon = Integrator.FolderDefaultIcon;
- }
- else
- {
- icon = txtIcon.Text;
- }
- Integrator.AddItem(txtItemName.Text, txtItem.Text, icon, _desktopItemPosition, checkShift.Checked, DesktopItemType.Folder);
- break;
- case DesktopItemType.Link:
- if (checkDefaultIcon.Checked)
- {
- icon = Integrator.DownloadFavicon(txtItem.Text, txtItemName.Text);
- }
- else
- {
- icon = txtIcon.Text;
- }
- Integrator.AddItem(txtItemName.Text, txtItem.Text, icon, _desktopItemPosition, checkShift.Checked, DesktopItemType.Link);
- break;
- case DesktopItemType.File:
- if (!checkDefaultIcon.Checked)
- {
- icon = txtIcon.Text;
- }
- Integrator.AddItem(txtItemName.Text, txtItem.Text, icon, _desktopItemPosition, checkShift.Checked, DesktopItemType.File);
- break;
- case DesktopItemType.Command:
- if (!checkDefaultIcon.Checked)
- {
- icon = txtIcon.Text;
- }
- Integrator.AddItem(txtItemName.Text, txtItem.Text, icon, _desktopItemPosition, checkShift.Checked, DesktopItemType.Command);
- break;
- }
- GetDesktopItems();
- ResetIntegratorForm();
- }
- private void radioTop_CheckedChanged(object sender, EventArgs e)
- {
- if (radioTop.Checked)
- {
- _desktopItemPosition = DesktopTypePosition.Top;
- }
- }
- private void radioMiddle_CheckedChanged(object sender, EventArgs e)
- {
- if (radioMiddle.Checked)
- {
- _desktopItemPosition = DesktopTypePosition.Middle;
- }
- }
- private void radioBottom_CheckedChanged(object sender, EventArgs e)
- {
- if (radioBottom.Checked)
- {
- _desktopItemPosition = DesktopTypePosition.Bottom;
- }
- }
- private void ResetIntegratorForm()
- {
- txtItem.Clear();
- txtIcon.Clear();
- checkDefaultIcon.Checked = true;
- txtItemName.Clear();
- if (radioLink.Checked)
- {
- txtItem.Text = "http://";
- }
- }
- private void radioOcean_CheckedChanged(object sender, EventArgs e)
- {
- Options.CurrentOptions.Color = Theme.Ocean;
- Options.ApplyTheme(this);
- }
- private void radioMagma_CheckedChanged(object sender, EventArgs e)
- {
- Options.CurrentOptions.Color = Theme.Magma;
- Options.ApplyTheme(this);
- }
- private void radioZerg_CheckedChanged(object sender, EventArgs e)
- {
- Options.CurrentOptions.Color = Theme.Zerg;
- Options.ApplyTheme(this);
- }
- private void radioMinimal_CheckedChanged(object sender, EventArgs e)
- {
- Options.CurrentOptions.Color = Theme.Minimal;
- Options.ApplyTheme(this);
- }
- private void radioCaramel_CheckedChanged(object sender, EventArgs e)
- {
- Options.CurrentOptions.Color = Theme.Caramel;
- Options.ApplyTheme(this);
- }
- private void radioLime_CheckedChanged(object sender, EventArgs e)
- {
- Options.CurrentOptions.Color = Theme.Lime;
- Options.ApplyTheme(this);
- }
- private void button64_Click(object sender, EventArgs e)
- {
- if (listStartupItems.SelectedItems.Count == 1)
- {
- _startUpItems[listStartupItems.SelectedIndices[0]].LocateKey();
- }
- }
- private void button66_Click(object sender, EventArgs e)
- {
- Integrator.TakeOwnership(false);
- }
- private void button65_Click(object sender, EventArgs e)
- {
- Integrator.TakeOwnership(true);
- }
- private void listStartupItems_ColumnClick(object sender, ColumnClickEventArgs e)
- {
- if (e.Column == _columnSorter.CurrentColumn)
- {
- if (_columnSorter.SortOrder == SortOrder.Ascending)
- {
- _columnSorter.SortOrder = SortOrder.Descending;
- }
- else
- {
- _columnSorter.SortOrder = SortOrder.Ascending;
- }
- }
- else
- {
- _columnSorter.CurrentColumn = e.Column;
- _columnSorter.SortOrder = SortOrder.Ascending;
- }
- listStartupItems.Sort();
- }
- private void chkBlock_CheckedChanged(object sender, EventArgs e)
- {
- if (chkBlock.Checked)
- {
- txtIP.Text = _blockedIP;
- txtIP.Enabled = false;
- }
- else
- {
- txtIP.Clear();
- txtIP.Enabled = true;
- }
- }
- private void button8_Click(object sender, EventArgs e)
- {
- GetCustomCommands();
- }
- private void button26_Click(object sender, EventArgs e)
- {
- if (listCustomCommands.SelectedItems.Count == 1)
- {
- Integrator.DeleteCustomCommand(listCustomCommands.SelectedItem.ToString());
- GetCustomCommands();
- }
- }
- private void button75_Click(object sender, EventArgs e)
- {
- GetModernApps(!chkOnlyRemovable.Checked);
- }
- private void button74_Click(object sender, EventArgs e)
- {
- UninstallModernApps();
- }
- private void chkSelectAllModernApps_CheckedChanged(object sender, EventArgs e)
- {
- for (int i = 0; i < listModernApps.Items.Count; i++)
- {
- listModernApps.SetItemChecked(i, chkSelectAllModernApps.Checked);
- }
- }
- private void btnResetConfig_Click(object sender, EventArgs e)
- {
- if (MessageBox.Show(_resetMessage, "Optimizer", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- Utilities.ResetConfiguration();
- }
- }
- private void toggleSwitch1_Click(object sender, EventArgs e)
- {
- if (!performanceSw.Checked)
- {
- Optimize.EnablePerformanceTweaks();
- }
- else
- {
- Optimize.DisablePerformanceTweaks();
- }
- Options.CurrentOptions.EnablePerformanceTweaks = !performanceSw.Checked;
- }
- private void toggleSwitch2_Click(object sender, EventArgs e)
- {
- if (!networkSw.Checked)
- {
- Optimize.DisableNetworkThrottling();
- }
- else
- {
- Optimize.EnableNetworkThrottling();
- }
- Options.CurrentOptions.DisableNetworkThrottling = !networkSw.Checked;
- }
- private void toggleSwitch3_Click(object sender, EventArgs e)
- {
- if (!defenderSw.Checked)
- {
- Optimize.DisableDefender();
- }
- else
- {
- Optimize.EnableDefender();
- }
- Options.CurrentOptions.DisableWindowsDefender = !defenderSw.Checked;
- }
- private void toggleSwitch4_Click(object sender, EventArgs e)
- {
- if (!systemRestoreSw.Checked)
- {
- Optimize.DisableSystemRestore();
- }
- else
- {
- Optimize.EnableSystemRestore();
- }
- Options.CurrentOptions.DisableSystemRestore = !systemRestoreSw.Checked;
- }
- private void toggleSwitch5_Click(object sender, EventArgs e)
- {
- if (!printSw.Checked)
- {
- Optimize.DisablePrintService();
- }
- else
- {
- Optimize.EnablePrintService();
- }
- Options.CurrentOptions.DisablePrintService = !printSw.Checked;
- }
- private void toggleSwitch6_Click(object sender, EventArgs e)
- {
- if (!mediaSharingSw.Checked)
- {
- Optimize.DisableMediaPlayerSharing();
- }
- else
- {
- Optimize.EnableMediaPlayerSharing();
- }
- Options.CurrentOptions.DisableMediaPlayerSharing = !mediaSharingSw.Checked;
- }
- private void toggleSwitch8_Click(object sender, EventArgs e)
- {
- if (!reportingSw.Checked)
- {
- Optimize.DisableErrorReporting();
- }
- else
- {
- Optimize.EnableErrorReporting();
- }
- Options.CurrentOptions.DisableErrorReporting = !reportingSw.Checked;
- }
- private void toggleSwitch9_Click(object sender, EventArgs e)
- {
- if (!homegroupSw.Checked)
- {
- Optimize.DisableHomeGroup();
- }
- else
- {
- Optimize.EnableHomeGroup();
- }
- Options.CurrentOptions.DisableHomeGroup = !homegroupSw.Checked;
- }
- private void toggleSwitch10_Click(object sender, EventArgs e)
- {
- if (!superfetchSw.Checked)
- {
- Optimize.DisableSuperfetch();
- }
- else
- {
- Optimize.EnableSuperfetch();
- }
- Options.CurrentOptions.DisableSuperfetch = !superfetchSw.Checked;
- }
- private void toggleSwitch11_Click(object sender, EventArgs e)
- {
- if (!telemetryTasksSw.Checked)
- {
- Optimize.DisableTelemetryTasks();
- }
- else
- {
- Optimize.EnableTelemetryTasks();
- }
- Options.CurrentOptions.DisableTelemetryTasks = !telemetryTasksSw.Checked;
- }
- private void toggleSwitch12_Click(object sender, EventArgs e)
- {
- if (!officeTelemetrySw.Checked)
- {
- Optimize.DisableOffice2016Telemetry();
- }
- else
- {
- Optimize.EnableOffice2016Telemetry();
- }
- Options.CurrentOptions.DisableOffice2016Telemetry = !officeTelemetrySw.Checked;
- }
- private void toggleSwitch13_Click(object sender, EventArgs e)
- {
- if (!oldMixerSw.Checked)
- {
- Optimize.EnableLegacyVolumeSlider();
- }
- else
- {
- Optimize.DisableLegacyVolumeSlider();
- }
- Options.CurrentOptions.EnableLegacyVolumeSlider = !oldMixerSw.Checked;
- }
- private void toggleSwitch19_Click(object sender, EventArgs e)
- {
- if (!colorBarSw.Checked)
- {
- Optimize.EnableTaskbarColor();
- }
- else
- {
- Optimize.DisableTaskbarColor();
- }
- Options.CurrentOptions.EnableTaskbarColor = !colorBarSw.Checked;
- }
- private void toggleSwitch18_Click(object sender, EventArgs e)
- {
- if (!oldExplorerSw.Checked)
- {
- Optimize.DisableQuickAccessHistory();
- }
- else
- {
- Optimize.EnableQuickAccessHistory();
- }
- Options.CurrentOptions.DisableQuickAccessHistory = !oldExplorerSw.Checked;
- }
- private void toggleSwitch26_Click(object sender, EventArgs e)
- {
- if (!adsSw.Checked)
- {
- Optimize.DisableStartMenuAds();
- }
- else
- {
- Optimize.EnableStartMenuAds();
- }
- Options.CurrentOptions.DisableStartMenuAds = !adsSw.Checked;
- }
- private void toggleSwitch27_Click(object sender, EventArgs e)
- {
- if (!darkSw.Checked)
- {
- Optimize.EnableDarkTheme();
- }
- else
- {
- Optimize.EnableLightTheme();
- }
- Options.CurrentOptions.EnableDarkTheme = !darkSw.Checked;
- }
- private void toggleSwitch14_Click(object sender, EventArgs e)
- {
- if (!uODSw.Checked)
- {
- Task t = new Task(() => Optimize.UninstallOneDrive());
- t.Start();
- }
- else
- {
- Task t = new Task(() => Optimize.InstallOneDrive());
- t.Start();
- }
- Options.CurrentOptions.UninstallOneDrive = !uODSw.Checked;
- }
- private void toggleSwitch25_Click(object sender, EventArgs e)
- {
- if (!peopleSw.Checked)
- {
- Optimize.DisableMyPeople();
- }
- else
- {
- Optimize.EnableMyPeople();
- }
- Options.CurrentOptions.DisableMyPeople = !peopleSw.Checked;
- }
- private void toggleSwitch24_Click(object sender, EventArgs e)
- {
- if (!autoUpdatesSw.Checked)
- {
- Optimize.DisableAutomaticUpdates();
- }
- else
- {
- Optimize.EnableAutomaticUpdates();
- }
- Options.CurrentOptions.DisableAutomaticUpdates = !autoUpdatesSw.Checked;
- }
- private void toggleSwitch30_Click(object sender, EventArgs e)
- {
- if (!driversSw.Checked)
- {
- Optimize.ExcludeDrivers();
- }
- else
- {
- Optimize.IncludeDrivers();
- }
- Options.CurrentOptions.ExcludeDrivers = !driversSw.Checked;
- }
- private void toggleSwitch23_Click(object sender, EventArgs e)
- {
- if (!telemetryServicesSw.Checked)
- {
- Optimize.DisableTelemetryServices();
- }
- else
- {
- Optimize.EnableTelemetryServices();
- }
- Options.CurrentOptions.DisableTelemetryServices = !telemetryServicesSw.Checked;
- }
- private void toggleSwitch21_Click(object sender, EventArgs e)
- {
- if (!privacySw.Checked)
- {
- Optimize.EnhancePrivacy();
- }
- else
- {
- Optimize.CompromisePrivacy();
- }
- Options.CurrentOptions.DisablePrivacyOptions = !privacySw.Checked;
- }
- private void toggleSwitch16_Click(object sender, EventArgs e)
- {
- if (!cortanaSw.Checked)
- {
- Optimize.DisableCortana();
- }
- else
- {
- Optimize.EnableCortana();
- }
- Options.CurrentOptions.DisableCortana = !cortanaSw.Checked;
- }
- private void toggleSwitch20_Click(object sender, EventArgs e)
- {
- if (!sensorSw.Checked)
- {
- Optimize.DisableSensorServices();
- }
- else
- {
- Optimize.EnableSensorServices();
- }
- Options.CurrentOptions.DisableSensorServices = !sensorSw.Checked;
- }
- private void toggleSwitch29_Click(object sender, EventArgs e)
- {
- if (!inkSw.Checked)
- {
- Optimize.DisableWindowsInk();
- }
- else
- {
- Optimize.EnableWindowsInk();
- }
- Options.CurrentOptions.DisableWindowsInk = !inkSw.Checked;
- }
- private void toggleSwitch28_Click(object sender, EventArgs e)
- {
- if (!spellSw.Checked)
- {
- Optimize.DisableSpellingAndTypingFeatures();
- }
- else
- {
- Optimize.EnableSpellingAndTypingFeatures();
- }
- Options.CurrentOptions.DisableSpellingTyping = !spellSw.Checked;
- }
- private void toggleSwitch17_Click(object sender, EventArgs e)
- {
- if (!xboxSw.Checked)
- {
- Optimize.DisableXboxLive();
- }
- else
- {
- Optimize.EnableXboxLive();
- }
- Options.CurrentOptions.DisableXboxLive = !xboxSw.Checked;
- }
- private void toggleSwitch15_Click(object sender, EventArgs e)
- {
- if (!gameBarSw.Checked)
- {
- Optimize.DisableGameBar();
- }
- else
- {
- Optimize.EnableGameBar();
- }
- Options.CurrentOptions.DisableGameBar = !gameBarSw.Checked;
- }
- private void toggleSwitch31_Click(object sender, EventArgs e)
- {
- if (!disableOneDriveSw.Checked)
- {
- Optimize.DisableOneDrive();
- }
- else
- {
- Optimize.EnableOneDrive();
- }
- Options.CurrentOptions.DisableOneDrive = !disableOneDriveSw.Checked;
- }
- private void toggleSwitch32_Click(object sender, EventArgs e)
- {
- if (!compatSw.Checked)
- {
- Optimize.DisableCompatibilityAssistant();
- }
- else
- {
- Optimize.EnableCompatibilityAssistant();
- }
- Options.CurrentOptions.DisableCompatibilityAssistant = !compatSw.Checked;
- }
- private void btnUpdate_Click(object sender, EventArgs e)
- {
- CheckForUpdate();
- }
- private void btnChangelog_Click(object sender, EventArgs e)
- {
- try
- {
- Process.Start(_changelogLink);
- }
- catch (Exception ex)
- {
- ErrorLogger.LogError("MainForm.btnChangelog_Click", ex.Message, ex.StackTrace);
- MessageBox.Show(ex.Message, "Optimizer", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- private void chkReadOnly_CheckedChanged(object sender, EventArgs e)
- {
- HostsHelper.ReadOnly(chkReadOnly.Checked);
- addHostB.Enabled = !chkReadOnly.Checked;
- removeAllHostsB.Enabled = !chkReadOnly.Checked;
- removeHostB.Enabled = !chkReadOnly.Checked;
- refreshHostsB.Enabled = !chkReadOnly.Checked;
- linkRestoreDefault.Enabled = !chkReadOnly.Checked;
- chkBlock.Enabled = !chkReadOnly.Checked;
- txtDomain.Enabled = !chkReadOnly.Checked;
- txtIP.Enabled = !chkReadOnly.Checked;
- adblockBasic.Enabled = !chkReadOnly.Checked;
- adblockS.Enabled = !chkReadOnly.Checked;
- adblockP.Enabled = !chkReadOnly.Checked;
- adblockUlti.Enabled = !chkReadOnly.Checked;
- txtIP.Focus();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- HostsHelper.AdblockBasic();
- GetHostsEntries();
- }
- private void button3_Click(object sender, EventArgs e)
- {
- HostsHelper.AdBlockWithPorn();
- GetHostsEntries();
- }
- private void button2_Click(object sender, EventArgs e)
- {
- HostsHelper.AdBlockWithSocial();
- GetHostsEntries();
- }
- private void button4_Click(object sender, EventArgs e)
- {
- HostsHelper.AdBlockWithSocial();
- GetHostsEntries();
- }
- private void RenderAppDownloaderBusy()
- {
- btnDownloadApps.Enabled = false;
- changeDownDirB.Enabled = false;
- txtDownloadFolder.ReadOnly = true;
- linkWarnings.Visible = false;
- }
- private void RenderAppDownloaderFree()
- {
- btnDownloadApps.Enabled = true;
- changeDownDirB.Enabled = true;
- txtDownloadFolder.ReadOnly = false;
- linkWarnings.Visible = !string.IsNullOrEmpty(downloadLog);
- txtDownloadStatus.Text = Options.TranslationList["Finished"];
- }
- string appNameTemp = string.Empty;
- int maxCount = 0;
- int count = 0;
- Process p;
- string downloadLog = string.Empty;
- private async void btnDownloadApps_Click(object sender, EventArgs e)
- {
- if (!Directory.Exists(txtDownloadFolder.Text))
- {
- MessageBox.Show(Options.TranslationList["downloadDirInvalid"].ToString(), "Optimizer", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- RenderAppDownloaderBusy();
- maxCount = 0;
- count = 0;
- downloadLog = string.Empty;
- foreach (Control c in Utilities.GetSelfAndChildrenRecursive(appsTab))
- {
- if (c.Name == "cAutoInstall") continue;
- if (c is ColoredCheckBox && ((ColoredCheckBox)c).Checked) maxCount++;
- }
- ColoredCheckBox currentCheck;
- Control[] temp;
- foreach (FeedApp x in AppsFromFeed)
- {
- if (string.IsNullOrEmpty(x.Tag)) continue;
- temp = appsTab.Controls.Find(x.Tag, true);
- if (temp.Count() == 0) continue;
- currentCheck = (ColoredCheckBox)temp[0];
- if (currentCheck == null) continue;
- if (!currentCheck.Checked) continue;
- appNameTemp = x.Title;
- if (c64.Checked)
- {
- count++;
- if (string.IsNullOrEmpty(x.Link64))
- {
- downloadLog += "• " + x.Title + ":" + Environment.NewLine + Options.TranslationList["no64Download"] + Environment.NewLine + Environment.NewLine;
- await DownloadApp(x, false);
- }
- else
- {
- await DownloadApp(x, true);
- }
- }
- else
- {
- count++;
- if (!string.IsNullOrEmpty(x.Link))
- {
- await DownloadApp(x, false);
- }
- else
- {
- downloadLog += "• " + x.Title + ":" + Environment.NewLine + Options.TranslationList["no32Download"] + Environment.NewLine + Environment.NewLine;
- }
- }
- }
- if (cAutoInstall.Checked)
- {
- count = 0;
- foreach (string a in Directory.GetFiles(txtDownloadFolder.Text, "*.*", SearchOption.TopDirectoryOnly))
- {
- using (p = new Process())
- {
- count++;
- p.StartInfo.FileName = a;
- p.EnableRaisingEvents = true;
- p.StartInfo.WorkingDirectory = txtDownloadFolder.Text;
- // APP-SPECIFIC HACKS //
- if (a.Contains("Sumatra")) p.StartInfo.Arguments = " -install";
- // *** //
- txtDownloadStatus.Text = string.Format("{0}/{1} - {2} {3} ...", count, maxCount, Options.TranslationList["installing"], Path.GetFileNameWithoutExtension(a));
- await p.RunAsync();
- };
- }
- }
- // reset all checkboxes
- foreach (Control c in Utilities.GetSelfAndChildrenRecursive(appsTab))
- {
- if (c.Name == "cAutoInstall") continue;
- if (c is ColoredCheckBox && ((ColoredCheckBox)c).Checked) ((ColoredCheckBox)c).Checked = false;
- }
- RenderAppDownloaderFree();
- }
- string fileExtension = ".exe";
- private async Task DownloadApp(FeedApp app, bool pref64)
- {
- try
- {
- using (WebClient downloader = new WebClient())
- {
- downloader.Headers.Add("User-Agent: Other");
- downloader.Encoding = Encoding.UTF8;
- downloader.DownloadProgressChanged += Downloader_DownloadProgressChanged;
- downloader.DownloadFileCompleted += Downloader_DownloadFileCompleted;
- if (pref64)
- {
- if (app.Link64.Contains(".msi"))
- {
- fileExtension = ".msi";
- }
- else
- {
- fileExtension = ".exe";
- }
- await downloader.DownloadFileTaskAsync(new Uri(app.Link64), Path.Combine(txtDownloadFolder.Text, app.Title + "-x64" + fileExtension));
- }
- else
- {
- if (app.Link.Contains(".msi"))
- {
- fileExtension = ".msi";
- }
- else
- {
- fileExtension = ".exe";
- }
- await downloader.DownloadFileTaskAsync(new Uri(app.Link), Path.Combine(txtDownloadFolder.Text, app.Title + "-x86" + fileExtension));
- }
- }
- }
- catch (Exception ex)
- {
- ErrorLogger.LogError("MainForm.DownloadApp", ex.Message, ex.StackTrace);
- downloadLog += "• " + app.Title + ":" + Environment.NewLine + Options.TranslationList["linkInvalid"] + Environment.NewLine + Environment.NewLine;
- if (pref64) try { File.Delete(Path.Combine(txtDownloadFolder.Text, app.Title + "-x64.exe")); } catch { }
- if (!pref64) try { File.Delete(Path.Combine(txtDownloadFolder.Text, app.Title + "-x86.exe")); } catch { }
- if (pref64) try { File.Delete(Path.Combine(txtDownloadFolder.Text, app.Title + "-x64.msi")); } catch { }
- if (!pref64) try { File.Delete(Path.Combine(txtDownloadFolder.Text, app.Title + "-x86.msi")); } catch { }
- }
- }
- private void Downloader_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
- {
- this.BeginInvoke((MethodInvoker)delegate
- {
- //txtDownloadStatus.Text = "Finished";
- });
- }
- int tempProgress;
- private void Downloader_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
- {
- this.BeginInvoke((MethodInvoker)delegate
- {
- double bytesIn = double.Parse(e.BytesReceived.ToString());
- double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
- double percentage = bytesIn / totalBytes * 100;
- tempProgress = int.Parse(Math.Truncate(percentage).ToString());
- // if Content-Length header is missing, just show an animation
- if (Math.Abs(tempProgress) > 100)
- {
- txtDownloadStatus.Text = string.Format("({1}/{2}) - {0} ...", appNameTemp, count, maxCount);
- progressDownloader.Style = ProgressBarStyle.Marquee;
- }
- // if not, show actual progress
- else
- {
- txtDownloadStatus.Text = string.Format("({1}/{2}) - {0} - {3} / {4}", appNameTemp, count, maxCount, ByteSize.FromBytes(e.BytesReceived).ToString("MB"), ByteSize.FromBytes(e.TotalBytesToReceive).ToString("MB"));
- progressDownloader.Style = ProgressBarStyle.Continuous;
- progressDownloader.Value = tempProgress;
- }
- });
- }
- private void button5_Click(object sender, EventArgs e)
- {
- FolderBrowserDialog d = new FolderBrowserDialog();
- if (d.ShowDialog() == DialogResult.OK)
- {
- txtDownloadFolder.Text = d.SelectedPath;
- Options.CurrentOptions.AppsFolder = d.SelectedPath;
- Options.SaveSettings();
- }
- }
- private void button6_Click(object sender, EventArgs e)
- {
- Process.Start(txtDownloadFolder.Text);
- }
- private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
- {
- InfoForm lf = new InfoForm(downloadLog);
- lf.ShowDialog(this);
- }
- private void txtDownloadFolder_TextChanged(object sender, EventArgs e)
- {
- Options.CurrentOptions.AppsFolder = txtDownloadFolder.Text;
- Options.SaveSettings();
- }
- private void chkOnlyRemovable_CheckedChanged(object sender, EventArgs e)
- {
- GetModernApps(!chkOnlyRemovable.Checked);
- }
- private void btnGetFeed_Click(object sender, EventArgs e)
- {
- GetFeed();
- }
- private void l2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
- {
- AboutForm f = new AboutForm();
- f.ShowDialog(this);
- //Process.Start("https://github.com/hellzerg/optimizer");
- }
- private void btnViewLog_Click(object sender, EventArgs e)
- {
- if (File.Exists(ErrorLogger.ErrorLogFile))
- {
- InfoForm iform = new InfoForm(File.ReadAllText(ErrorLogger.ErrorLogFile, Encoding.UTF8));
- iform.ShowDialog();
- }
- else
- {
- MessageBox.Show(Options.TranslationList["noErrorsM"].ToString(), "Optimizer", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- private void btnOpenConf_Click(object sender, EventArgs e)
- {
- Process.Start(Required.CoreFolder);
- }
- private void btnPing_Click(object sender, EventArgs e)
- {
- if (string.IsNullOrEmpty(txtPingInput.Text)) return;
- _pingResults = new List<PingReply>();
- listPingResults.Items.Clear();
- if (Utilities.PingHost(txtPingInput.Text) == null)
- {
- listPingResults.Items.Add(string.Format("{0} [{1}]", Options.TranslationList["hostNotFound"], txtPingInput.Text));
- return;
- }
- Task pinger = new Task(() =>
- {
- btnShodan.Enabled = false;
- btnPing.Enabled = false;
- listPingResults.Items.Add(string.Format("{0} [{1}]", Options.TranslationList["pinging"], txtPingInput.Text));
- listPingResults.Items.Add("");
- for (int i = 0; i < 9; i++)
- {
- // wait before each pinging
- System.Threading.Thread.Sleep(888);
- tmpReply = Utilities.PingHost(txtPingInput.Text);
- if (tmpReply.Address == null)
- {
- listPingResults.Items.Add(tmpReply.Status);
- }
- else
- {
- _pingResults.Add(tmpReply);
- _shodanIP = _pingResults[i].Address.ToString();
- listPingResults.Items.Add(string.Format("{0} - {1}: {2} ms - TTL: {3}", _pingResults[i].Status, Options.TranslationList["latency"], _pingResults[i].RoundtripTime, _pingResults[i].Options.Ttl));
- }
- }
- listPingResults.Items.Add("");
- // calculate statistics
- if (_pingResults.Count > 0)
- {
- long maxLatency = _pingResults.Max(x => x.RoundtripTime);
- long minLatency = _pingResults.Min(x => x.RoundtripTime);
- double averageLatency = _pingResults.Average(x => x.RoundtripTime);
- listPingResults.Items.Add(string.Format("{0} = {1}, {2} = {3}, {4} = {5:F2}", Options.TranslationList["min"], minLatency, Options.TranslationList["max"], maxLatency, Options.TranslationList["avg"], averageLatency));
- }
- else
- {
- listPingResults.Items.Add(Options.TranslationList["timeout"]);
- }
- btnPing.Enabled = true;
- btnShodan.Enabled = true;
- });
- pinger.Start();
- }
- private void btnCheckFootprint_Click(object sender, EventArgs e)
- {
- CleanHelper.CheckFootprint();
- }
- private void btnShodan_Click(object sender, EventArgs e)
- {
- IPAddress tryIP;
- if (IPAddress.TryParse(txtPingInput.Text, out tryIP))
- {
- Process.Start(string.Format("https://www.shodan.io/host/{0}", txtPingInput.Text));
- return;
- }
- if (!string.IsNullOrEmpty(_shodanIP))
- {
- Process.Start(string.Format("https://www.shodan.io/host/{0}", _shodanIP));
- return;
- }
- }
- private void button9_Click(object sender, EventArgs e)
- {
- try
- {
- Clipboard.SetText(_shodanIP);
- }
- catch { }
- }
- private void button7_Click(object sender, EventArgs e)
- {
- try
- {
- Clipboard.SetText(txtPingInput.Text);
- }
- catch { }
- }
- private void txtPingInput_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter) btnPing.PerformClick();
- }
- private void btnExport_Click(object sender, EventArgs e)
- {
- if (ExportDialog.ShowDialog() == DialogResult.OK)
- {
- try
- {
- File.WriteAllLines(ExportDialog.FileName, listPingResults.Items.Cast<string>());
- }
- catch (Exception ex)
- {
- ErrorLogger.LogError("btnExport.Click", ex.Message, ex.StackTrace);
- MessageBox.Show(ex.Message, "Optimizer", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- }
- private void startupItem_Click(object sender, EventArgs e)
- {
- tabCollection.SelectedTab = startupTab;
- RestoreWindow();
- }
- private void cleanerItem_Click(object sender, EventArgs e)
- {
- tabCollection.SelectedTab = cleanerTab;
- RestoreWindow();
- }
- private void pingerItem_Click(object sender, EventArgs e)
- {
- tabCollection.SelectedTab = pingerTab;
- RestoreWindow();
- txtPingInput.Focus();
- }
- private void hostsItem_Click(object sender, EventArgs e)
- {
- tabCollection.SelectedTab = hostsEditorTab;
- RestoreWindow();
- txtIP.Focus();
- }
- private void appsItem_Click(object sender, EventArgs e)
- {
- tabCollection.SelectedTab = appsTab;
- RestoreWindow();
- }
- private void exitItem_Click(object sender, EventArgs e)
- {
- _trayMenu = false;
- Options.CurrentOptions.AppsFolder = txtDownloadFolder.Text;
- Options.SaveSettings();
- Application.Exit();
- }
- private void RestoreWindow()
- {
- if (this.WindowState == FormWindowState.Minimized) this.WindowState = FormWindowState.Normal;
- this.Show();
- this.Activate();
- this.Focus();
- }
- private void launcherIcon_MouseDoubleClick(object sender, MouseEventArgs e)
- {
- if (this.Visible)
- {
- if (this.WindowState == FormWindowState.Minimized) this.WindowState = FormWindowState.Normal;
- this.Hide();
- }
- else
- {
- RestoreWindow();
- }
- }
- private void quickAccessToggle_CheckedChanged(object sender, EventArgs e)
- {
- Options.CurrentOptions.EnableTray = quickAccessToggle.Checked;
- Options.SaveSettings();
- _trayMenu = quickAccessToggle.Checked;
- launcherIcon.Visible = quickAccessToggle.Checked;
- }
- private void linkLabel5_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
- {
- Process.Start(_licenseLink);
- }
- private void linkLabel6_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
- {
- Process.Start(_openSourceLink);
- }
- private void linkUpdate_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
- {
- CheckForUpdate();
- }
- private void restartExpolorerItem_Click(object sender, EventArgs e)
- {
- Utilities.RestartExplorer();
- }
- private void button10_Click(object sender, EventArgs e)
- {
- Utilities.FlushDNSCache();
- }
- private void helpTipsToggle_CheckedChanged(object sender, EventArgs e)
- {
- Options.CurrentOptions.ShowHelp = helpTipsToggle.Checked;
- Options.SaveSettings();
- helpBox.Active = helpTipsToggle.Checked;
- }
- private void button11_Click(object sender, EventArgs e)
- {
- ShowBackupConfirm();
- }
- private void ShowBackupConfirm()
- {
- removeStartupItemB.Visible = false;
- locateFileB.Visible = false;
- findInRegB.Visible = false;
- refreshStartupB.Visible = false;
- restoreStartupB.Visible = false;
- backupStartupB.Visible = false;
- lblBackupTitle.Visible = true;
- doBackup.Visible = true;
- cancelBackup.Visible = true;
- txtBackupTitle.Visible = true;
- }
- private void HideBackupConfirm()
- {
- removeStartupItemB.Visible = true;
- locateFileB.Visible = true;
- findInRegB.Visible = true;
- refreshStartupB.Visible = true;
- restoreStartupB.Visible = true;
- backupStartupB.Visible = true;
- lblBackupTitle.Visible = false;
- doBackup.Visible = false;
- cancelBackup.Visible = false;
- txtBackupTitle.Visible = false;
- }
- private void button12_Click(object sender, EventArgs e)
- {
- StartupRestoreForm f = new StartupRestoreForm();
- f.ShowDialog(this);
- GetStartupItems();
- }
- private void button14_Click(object sender, EventArgs e)
- {
- HideBackupConfirm();
- }
- private void button13_Click(object sender, EventArgs e)
- {
- if (!string.IsNullOrEmpty(txtBackupTitle.Text.Trim()))
- {
- HideBackupConfirm();
- _backupItems.Clear();
- foreach (var x in _startUpItems)
- {
- _backupItems.Add(new StartupBackupItem(x.Name, x.FileLocation, x.RegistryLocation.ToString(), x.StartupType.ToString()));
- }
- try
- {
- File.WriteAllText(Required.StartupItemsBackupFolder + Utilities.SanitizeFileFolderName(txtBackupTitle.Text + " - [" + DateTime.Now.ToShortDateString() + "-" + DateTime.Now.ToShortTimeString()) + "].json", JsonConvert.SerializeObject(_backupItems, Formatting.Indented));
- }
- catch (Exception ex)
- {
- ErrorLogger.LogError("MainForm.BackupStartupItems", ex.Message, ex.StackTrace);
- }
- }
- }
- private void pictureBox86_Click(object sender, EventArgs e)
- {
- radioEnglish.PerformClick();
- }
- private void pictureBox87_Click(object sender, EventArgs e)
- {
- radioRussian.PerformClick();
- }
- private void radioEnglish_Click(object sender, EventArgs e)
- {
- radioEnglish.Checked = true;
- Options.CurrentOptions.LanguageCode = LanguageCode.EN;
- Options.SaveSettings();
- Options.LoadTranslation();
- Translate();
- }
- private void radioRussian_Click(object sender, EventArgs e)
- {
- radioRussian.Checked = true;
- Options.CurrentOptions.LanguageCode = LanguageCode.RU;
- Options.SaveSettings();
- Options.LoadTranslation();
- Translate();
- }
- private void pictureBox88_Click(object sender, EventArgs e)
- {
- radioHellenic.PerformClick();
- }
- private void radioHellenic_Click(object sender, EventArgs e)
- {
- radioHellenic.Checked = true;
- Options.CurrentOptions.LanguageCode = LanguageCode.EL;
- Options.SaveSettings();
- Options.LoadTranslation();
- Translate();
- }
- private void pictureBox89_Click(object sender, EventArgs e)
- {
- radioTurkish.PerformClick();
- }
- private void radioTurkish_Click(object sender, EventArgs e)
- {
- radioTurkish.Checked = true;
- Options.CurrentOptions.LanguageCode = LanguageCode.TR;
- Options.SaveSettings();
- Options.LoadTranslation();
- Translate();
- }
- private void radioGerman_Click(object sender, EventArgs e)
- {
- radioGerman.Checked = true;
- Options.CurrentOptions.LanguageCode = LanguageCode.DE;
- Options.SaveSettings();
- Options.LoadTranslation();
- Translate();
- }
- private void pictureBox2_Click(object sender, EventArgs e)
- {
- radioGerman.PerformClick();
- }
- }
- }
|