Options.cs 8.2 KB

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