MainForm.cs 96 KB

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