Options.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. using Newtonsoft.Json;
  2. using Newtonsoft.Json.Linq;
  3. using System;
  4. using System.Drawing;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Windows.Forms;
  8. namespace Optimizer
  9. {
  10. [Serializable]
  11. public class SettingsJson
  12. {
  13. public Theme Color { get; set; }
  14. public string AppsFolder { get; set; }
  15. public bool EnableTray { get; set; }
  16. public bool ShowHelp { get; set; }
  17. public bool EnablePerformanceTweaks { get; set; }
  18. public bool DisableNetworkThrottling { get; set; }
  19. public bool DisableWindowsDefender { get; set; }
  20. public bool DisableSystemRestore { get; set; }
  21. public bool DisablePrintService { get; set; }
  22. public bool DisableMediaPlayerSharing { get; set; }
  23. public bool DisableErrorReporting { get; set; }
  24. public bool DisableHomeGroup { get; set; }
  25. public bool DisableSuperfetch { get; set; }
  26. public bool DisableTelemetryTasks { get; set; }
  27. public bool DisableOffice2016Telemetry { get; set; }
  28. public bool DisableCompatibilityAssistant { get; set; }
  29. public bool DisableFaxService { get; set; }
  30. public bool DisableSmartScreen { get; set; }
  31. public bool DisableCloudClipboard { get; set; }
  32. public bool DisableStickyKeys { get; set; }
  33. public bool EnableLegacyVolumeSlider { get; set; }
  34. public bool EnableTaskbarColor { get; set; }
  35. public bool DisableQuickAccessHistory { get; set; }
  36. public bool DisableStartMenuAds { get; set; }
  37. public bool EnableDarkTheme { get; set; }
  38. public bool UninstallOneDrive { get; set; }
  39. public bool DisableMyPeople { get; set; }
  40. public bool DisableAutomaticUpdates { get; set; }
  41. public bool ExcludeDrivers { get; set; }
  42. public bool DisableTelemetryServices { get; set; }
  43. public bool DisablePrivacyOptions { get; set; }
  44. public bool DisableCortana { get; set; }
  45. public bool DisableSensorServices { get; set; }
  46. public bool DisableWindowsInk { get; set; }
  47. public bool DisableSpellingTyping { get; set; }
  48. public bool DisableXboxLive { get; set; }
  49. public bool DisableGameBar { get; set; }
  50. public bool DisableInsiderService { get; set; }
  51. public bool DisableFeatureUpdates { get; set; }
  52. public bool EnableLongPaths { get; set; }
  53. public bool RemoveCastToDevice { get; set; }
  54. public bool DisableActionCenter { get; set; }
  55. public bool DisableOneDrive { get; set; }
  56. }
  57. internal static class Options
  58. {
  59. internal static Color ForegroundColor = Color.MediumOrchid;
  60. internal static Color ForegroundAccentColor = Color.DarkOrchid;
  61. internal static Color BackgroundColor = Color.FromArgb(((int)(((byte)(20)))), ((int)(((byte)(20)))), ((int)(((byte)(20)))));
  62. readonly static string _themeFlag = "themeable";
  63. internal readonly static string SettingsFile = Required.CoreFolder + "\\Optimizer.json";
  64. internal static SettingsJson CurrentOptions = new SettingsJson();
  65. internal static void ApplyTheme(Form f)
  66. {
  67. switch (CurrentOptions.Color)
  68. {
  69. case Theme.Caramel:
  70. SetTheme(f, Color.DarkOrange, Color.Chocolate);
  71. ForegroundColor = Color.DarkOrange;
  72. ForegroundAccentColor = Color.Chocolate;
  73. break;
  74. case Theme.Lime:
  75. SetTheme(f, Color.LimeGreen, Color.ForestGreen);
  76. ForegroundColor = Color.LimeGreen;
  77. ForegroundAccentColor = Color.ForestGreen;
  78. break;
  79. case Theme.Magma:
  80. SetTheme(f, Color.Tomato, Color.Red);
  81. ForegroundColor = Color.Tomato;
  82. ForegroundAccentColor = Color.Red;
  83. break;
  84. case Theme.Minimal:
  85. SetTheme(f, Color.Gray, Color.DimGray);
  86. ForegroundColor = Color.Gray;
  87. ForegroundAccentColor = Color.DimGray;
  88. break;
  89. case Theme.Ocean:
  90. SetTheme(f, Color.DodgerBlue, Color.RoyalBlue);
  91. ForegroundColor = Color.DodgerBlue;
  92. ForegroundAccentColor = Color.RoyalBlue;
  93. break;
  94. case Theme.Zerg:
  95. SetTheme(f, Color.MediumOrchid, Color.DarkOrchid);
  96. ForegroundColor = Color.MediumOrchid;
  97. ForegroundAccentColor = Color.DarkOrchid;
  98. break;
  99. }
  100. }
  101. private static void SetTheme(Form f, Color c1, Color c2)
  102. {
  103. Utilities.GetSelfAndChildrenRecursive(f).OfType<Button>().ToList().ForEach(b => b.BackColor = c1);
  104. Utilities.GetSelfAndChildrenRecursive(f).OfType<Button>().ToList().ForEach(b => b.FlatAppearance.BorderColor = c1);
  105. Utilities.GetSelfAndChildrenRecursive(f).OfType<Button>().ToList().ForEach(b => b.FlatAppearance.MouseDownBackColor = c2);
  106. Utilities.GetSelfAndChildrenRecursive(f).OfType<Button>().ToList().ForEach(b => b.FlatAppearance.MouseOverBackColor = c2);
  107. foreach (ToggleSwitch tmp in Utilities.GetSelfAndChildrenRecursive(f).OfType<ToggleSwitch>().ToList())
  108. {
  109. if ((string)tmp.Tag == _themeFlag)
  110. {
  111. tmp.SetRenderer(new ToggleSwitchRenderer());
  112. }
  113. }
  114. foreach (Label tmp in Utilities.GetSelfAndChildrenRecursive(f).OfType<Label>().ToList())
  115. {
  116. if ((string)tmp.Tag == _themeFlag)
  117. {
  118. tmp.ForeColor = c1;
  119. }
  120. }
  121. foreach (LinkLabel tmp in Utilities.GetSelfAndChildrenRecursive(f).OfType<LinkLabel>().ToList())
  122. {
  123. if ((string)tmp.Tag == _themeFlag)
  124. {
  125. tmp.LinkColor = c1;
  126. tmp.VisitedLinkColor = c1;
  127. tmp.ActiveLinkColor = c2;
  128. }
  129. }
  130. foreach (CheckBox tmp in Utilities.GetSelfAndChildrenRecursive(f).OfType<CheckBox>().ToList())
  131. {
  132. if ((string)tmp.Tag == _themeFlag)
  133. {
  134. tmp.ForeColor = c1;
  135. }
  136. }
  137. foreach (RadioButton tmp in Utilities.GetSelfAndChildrenRecursive(f).OfType<RadioButton>().ToList())
  138. {
  139. if ((string)tmp.Tag == _themeFlag)
  140. {
  141. tmp.ForeColor = c1;
  142. }
  143. }
  144. }
  145. internal static void SaveSettings()
  146. {
  147. if (File.Exists(SettingsFile))
  148. {
  149. string jsonFile = File.ReadAllText(SettingsFile);
  150. string jsonMemory = JsonConvert.SerializeObject(CurrentOptions);
  151. // check to see if no changes have been made
  152. if (JToken.DeepEquals(JObject.Parse(jsonFile), JObject.Parse(jsonMemory))) return;
  153. File.Delete(SettingsFile);
  154. using (FileStream fs = File.Open(SettingsFile, FileMode.OpenOrCreate))
  155. using (StreamWriter sw = new StreamWriter(fs))
  156. using (JsonWriter jw = new JsonTextWriter(sw))
  157. {
  158. jw.Formatting = Formatting.Indented;
  159. JsonSerializer serializer = new JsonSerializer();
  160. serializer.Serialize(jw, CurrentOptions);
  161. }
  162. }
  163. }
  164. internal static void LoadSettings()
  165. {
  166. if (!File.Exists(SettingsFile))
  167. {
  168. // DEFAULT OPTIONS
  169. CurrentOptions.Color = Theme.Zerg;
  170. CurrentOptions.AppsFolder = Path.Combine(Application.StartupPath, "Optimizer Downloads");
  171. Directory.CreateDirectory(Options.CurrentOptions.AppsFolder);
  172. CurrentOptions.EnableTray = true;
  173. CurrentOptions.ShowHelp = true;
  174. CurrentOptions.EnablePerformanceTweaks = false;
  175. CurrentOptions.DisableNetworkThrottling = false;
  176. CurrentOptions.DisableWindowsDefender = false;
  177. CurrentOptions.DisableSystemRestore = false;
  178. CurrentOptions.DisablePrintService = false;
  179. CurrentOptions.DisableMediaPlayerSharing = false;
  180. CurrentOptions.DisableErrorReporting = false;
  181. CurrentOptions.DisableHomeGroup = false;
  182. CurrentOptions.DisableSuperfetch = false;
  183. CurrentOptions.DisableTelemetryTasks = false;
  184. CurrentOptions.DisableOffice2016Telemetry = false;
  185. CurrentOptions.DisableCompatibilityAssistant = false;
  186. CurrentOptions.DisableFaxService = false;
  187. CurrentOptions.DisableSmartScreen = false;
  188. CurrentOptions.DisableStickyKeys = false;
  189. CurrentOptions.EnableLegacyVolumeSlider = false;
  190. CurrentOptions.EnableTaskbarColor = false;
  191. CurrentOptions.DisableQuickAccessHistory = false;
  192. CurrentOptions.DisableStartMenuAds = false;
  193. CurrentOptions.EnableDarkTheme = false;
  194. CurrentOptions.UninstallOneDrive = false;
  195. CurrentOptions.DisableMyPeople = false;
  196. CurrentOptions.DisableAutomaticUpdates = false;
  197. CurrentOptions.ExcludeDrivers = false;
  198. CurrentOptions.DisableTelemetryServices = false;
  199. CurrentOptions.DisablePrivacyOptions = false;
  200. CurrentOptions.DisableCortana = false;
  201. CurrentOptions.DisableSensorServices = false;
  202. CurrentOptions.DisableWindowsInk = false;
  203. CurrentOptions.DisableSpellingTyping = false;
  204. CurrentOptions.DisableXboxLive = false;
  205. CurrentOptions.DisableGameBar = false;
  206. CurrentOptions.DisableInsiderService = false;
  207. CurrentOptions.DisableFeatureUpdates = false;
  208. CurrentOptions.DisableCloudClipboard = false;
  209. CurrentOptions.EnableLongPaths = false;
  210. CurrentOptions.RemoveCastToDevice = false;
  211. CurrentOptions.DisableActionCenter = false;
  212. CurrentOptions.DisableOneDrive = false;
  213. using (FileStream fs = File.Open(SettingsFile, FileMode.CreateNew))
  214. using (StreamWriter sw = new StreamWriter(fs))
  215. using (JsonWriter jw = new JsonTextWriter(sw))
  216. {
  217. jw.Formatting = Formatting.Indented;
  218. JsonSerializer serializer = new JsonSerializer();
  219. serializer.Serialize(jw, CurrentOptions);
  220. }
  221. }
  222. else
  223. {
  224. CurrentOptions = JsonConvert.DeserializeObject<SettingsJson>(File.ReadAllText(SettingsFile));
  225. }
  226. }
  227. }
  228. }