Options.cs 12 KB

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