2
0

MainForm.cs 97 KB

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