Options.cs 9.2 KB

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