Options.cs 8.0 KB

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