Options.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows.Forms;
  7. using System.Drawing;
  8. using System.IO;
  9. using Newtonsoft.Json;
  10. namespace Optimizer
  11. {
  12. public class SettingsJson
  13. {
  14. public Theme Color { get; set; }
  15. public bool EnablePerformanceTweaks { get; set; }
  16. public bool DisableNetworkThrottling { get; set; }
  17. public bool DisableWindowsDefender { get; set; }
  18. public bool DisableSystemRestore { get; set; }
  19. public bool DisablePrintService { get; set; }
  20. public bool DisableMediaPlayerSharing { get; set; }
  21. public bool BlockSkypeAds { get; set; }
  22. public bool DisableErrorReporting { get; set; }
  23. public bool DisableHomeGroup { get; set; }
  24. public bool DisableSuperfetch { get; set; }
  25. public bool DisableTelemetryTasks { get; set; }
  26. public bool DisableOffice2016Telemetry { get; set; }
  27. public bool DisableCompatibilityAssistant { get; set; }
  28. public bool DisableFaxService { get; set; }
  29. public bool EnableLegacyVolumeSlider { get; set; }
  30. public bool EnableTaskbarColor { get; set; }
  31. public bool DisableQuickAccessHistory { get; set; }
  32. public bool DisableStartMenuAds { get; set; }
  33. public bool EnableDarkTheme { get; set; }
  34. public bool UninstallOneDrive { get; set; }
  35. public bool DisableMyPeople { get; set; }
  36. public bool DisableAutomaticUpdates { get; set; }
  37. public bool ExcludeDrivers { get; set; }
  38. public bool DisableTelemetryServices { get; set; }
  39. public bool DisablePrivacyOptions { get; set; }
  40. public bool DisableSilentAppInstall { get; set; }
  41. public bool DisableCortana { get; set; }
  42. public bool DisableSensorServices { get; set; }
  43. public bool DisableWindowsInk { get; set; }
  44. public bool DisableSpellingTyping { get; set; }
  45. public bool DisableXboxLive { get; set; }
  46. public bool DisableGameBar { get; set; }
  47. public bool DisableInsiderService { get; set; }
  48. public bool DisableOneDrive { get; set; }
  49. }
  50. internal static class Options
  51. {
  52. readonly static string _themeFlag = "themeable";
  53. internal readonly static string SettingsFile = Required.CoreFolder + "\\Optimizer.json";
  54. internal static SettingsJson CurrentOptions = new SettingsJson();
  55. internal static void ApplyTheme(Form f)
  56. {
  57. switch (CurrentOptions.Color)
  58. {
  59. case Theme.Caramel:
  60. SetTheme(f, Color.DarkOrange, Color.Chocolate);
  61. break;
  62. case Theme.Lime:
  63. SetTheme(f, Color.LimeGreen, Color.ForestGreen);
  64. break;
  65. case Theme.Magma:
  66. SetTheme(f, Color.Tomato, Color.Red);
  67. break;
  68. case Theme.Minimal:
  69. SetTheme(f, Color.Gray, Color.DimGray);
  70. break;
  71. case Theme.Ocean:
  72. SetTheme(f, Color.DodgerBlue, Color.RoyalBlue);
  73. break;
  74. case Theme.Zerg:
  75. SetTheme(f, Color.MediumOrchid, Color.DarkOrchid);
  76. break;
  77. }
  78. }
  79. private static void SetTheme(Form f, Color c1, Color c2)
  80. {
  81. Utilities.GetSelfAndChildrenRecursive(f).OfType<Button>().ToList().ForEach(b => b.BackColor = c1);
  82. Utilities.GetSelfAndChildrenRecursive(f).OfType<Button>().ToList().ForEach(b => b.FlatAppearance.BorderColor = c1);
  83. Utilities.GetSelfAndChildrenRecursive(f).OfType<Button>().ToList().ForEach(b => b.FlatAppearance.MouseDownBackColor = c2);
  84. Utilities.GetSelfAndChildrenRecursive(f).OfType<Button>().ToList().ForEach(b => b.FlatAppearance.MouseOverBackColor = c2);
  85. foreach (ToggleSwitch tmp in Utilities.GetSelfAndChildrenRecursive(f).OfType<ToggleSwitch>().ToList())
  86. {
  87. if ((string)tmp.Tag == _themeFlag)
  88. {
  89. tmp.SetRenderer(new ToggleSwitchRenderer());
  90. }
  91. }
  92. foreach (Label tmp in Utilities.GetSelfAndChildrenRecursive(f).OfType<Label>().ToList())
  93. {
  94. if ((string)tmp.Tag == _themeFlag)
  95. {
  96. tmp.ForeColor = c1;
  97. }
  98. }
  99. foreach (LinkLabel tmp in Utilities.GetSelfAndChildrenRecursive(f).OfType<LinkLabel>().ToList())
  100. {
  101. if ((string)tmp.Tag == _themeFlag)
  102. {
  103. tmp.LinkColor = c1;
  104. tmp.VisitedLinkColor = c1;
  105. tmp.ActiveLinkColor = c2;
  106. }
  107. }
  108. foreach (CheckBox tmp in Utilities.GetSelfAndChildrenRecursive(f).OfType<CheckBox>().ToList())
  109. {
  110. if ((string)tmp.Tag == _themeFlag)
  111. {
  112. tmp.ForeColor = c1;
  113. }
  114. }
  115. }
  116. internal static void SaveSettings()
  117. {
  118. if (File.Exists(SettingsFile))
  119. {
  120. File.Delete(SettingsFile);
  121. using (FileStream fs = File.Open(SettingsFile, FileMode.OpenOrCreate))
  122. using (StreamWriter sw = new StreamWriter(fs))
  123. using (JsonWriter jw = new JsonTextWriter(sw))
  124. {
  125. jw.Formatting = Formatting.Indented;
  126. JsonSerializer serializer = new JsonSerializer();
  127. serializer.Serialize(jw, CurrentOptions);
  128. }
  129. }
  130. }
  131. internal static void LoadSettings()
  132. {
  133. if (!File.Exists(SettingsFile))
  134. {
  135. CurrentOptions.Color = Theme.Zerg;
  136. CurrentOptions.EnablePerformanceTweaks = false;
  137. CurrentOptions.DisableNetworkThrottling = false;
  138. CurrentOptions.DisableWindowsDefender = false;
  139. CurrentOptions.DisableSystemRestore = false;
  140. CurrentOptions.DisablePrintService = false;
  141. CurrentOptions.DisableMediaPlayerSharing = false;
  142. CurrentOptions.BlockSkypeAds = false;
  143. CurrentOptions.DisableErrorReporting = false;
  144. CurrentOptions.DisableHomeGroup = false;
  145. CurrentOptions.DisableSuperfetch = false;
  146. CurrentOptions.DisableTelemetryTasks = false;
  147. CurrentOptions.DisableOffice2016Telemetry = false;
  148. CurrentOptions.DisableCompatibilityAssistant = false;
  149. CurrentOptions.DisableFaxService = false;
  150. CurrentOptions.EnableLegacyVolumeSlider = false;
  151. CurrentOptions.EnableTaskbarColor = false;
  152. CurrentOptions.DisableQuickAccessHistory = false;
  153. CurrentOptions.DisableStartMenuAds = false;
  154. CurrentOptions.EnableDarkTheme = false;
  155. CurrentOptions.UninstallOneDrive = false;
  156. CurrentOptions.DisableMyPeople = false;
  157. CurrentOptions.DisableAutomaticUpdates = false;
  158. CurrentOptions.ExcludeDrivers = false;
  159. CurrentOptions.DisableTelemetryServices = false;
  160. CurrentOptions.DisablePrivacyOptions = false;
  161. CurrentOptions.DisableSilentAppInstall = false;
  162. CurrentOptions.DisableCortana = false;
  163. CurrentOptions.DisableSensorServices = false;
  164. CurrentOptions.DisableWindowsInk = false;
  165. CurrentOptions.DisableSpellingTyping = false;
  166. CurrentOptions.DisableXboxLive = false;
  167. CurrentOptions.DisableGameBar = false;
  168. CurrentOptions.DisableInsiderService = false;
  169. CurrentOptions.DisableOneDrive = false;
  170. using (FileStream fs = File.Open(SettingsFile, FileMode.CreateNew))
  171. using (StreamWriter sw = new StreamWriter(fs))
  172. using (JsonWriter jw = new JsonTextWriter(sw))
  173. {
  174. jw.Formatting = Formatting.Indented;
  175. JsonSerializer serializer = new JsonSerializer();
  176. serializer.Serialize(jw, CurrentOptions);
  177. }
  178. }
  179. else
  180. {
  181. CurrentOptions = JsonConvert.DeserializeObject<SettingsJson>(File.ReadAllText(SettingsFile));
  182. }
  183. }
  184. }
  185. }