Options.cs 10 KB

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