MainForm.cs 92 KB

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