Options.cs 13 KB

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