Options.cs 14 KB

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