Options.cs 9.1 KB

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