Options.cs 8.5 KB

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