MainForm.cs 103 KB

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