Options.cs 13 KB

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