Options.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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.ForestGreen, Color.FromArgb(39, 159, 39));
  89. ForegroundColor = Color.ForestGreen;
  90. ForegroundAccentColor = Color.FromArgb(39, 159, 39);
  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 LinkLabel)
  128. {
  129. if ((string)c.Tag == _themeFlag)
  130. {
  131. c.LinkColor = c1;
  132. c.VisitedLinkColor = c1;
  133. c.ActiveLinkColor = c2;
  134. }
  135. }
  136. if (x is CheckBox || x is RadioButton || x is Label)
  137. {
  138. if ((string)c.Tag == _themeFlag)
  139. {
  140. c.ForeColor = c1;
  141. }
  142. }
  143. c.Invalidate();
  144. });
  145. }
  146. internal static void LegacyCheck()
  147. {
  148. if (File.Exists(SettingsFile))
  149. {
  150. if (File.ReadAllText(SettingsFile).Contains("FirstRun"))
  151. {
  152. File.Delete(SettingsFile);
  153. }
  154. }
  155. }
  156. internal static void SaveSettings()
  157. {
  158. if (File.Exists(SettingsFile))
  159. {
  160. string jsonFile = File.ReadAllText(SettingsFile);
  161. string jsonMemory = JsonConvert.SerializeObject(CurrentOptions);
  162. // check to see if no changes have been made
  163. if (JToken.DeepEquals(JObject.Parse(jsonFile), JObject.Parse(jsonMemory))) return;
  164. File.Delete(SettingsFile);
  165. using (FileStream fs = File.Open(SettingsFile, FileMode.OpenOrCreate))
  166. using (StreamWriter sw = new StreamWriter(fs))
  167. using (JsonWriter jw = new JsonTextWriter(sw))
  168. {
  169. jw.Formatting = Formatting.Indented;
  170. JsonSerializer serializer = new JsonSerializer();
  171. serializer.Serialize(jw, CurrentOptions);
  172. }
  173. }
  174. }
  175. internal static void LoadSettings()
  176. {
  177. if (!File.Exists(SettingsFile))
  178. {
  179. // DEFAULT OPTIONS
  180. CurrentOptions.Color = Theme.Zerg;
  181. CurrentOptions.AppsFolder = Path.Combine(Application.StartupPath, "Optimizer Downloads");
  182. Directory.CreateDirectory(Options.CurrentOptions.AppsFolder);
  183. CurrentOptions.EnableTray = false;
  184. CurrentOptions.ShowHelp = true;
  185. CurrentOptions.LanguageCode = LanguageCode.EN;
  186. CurrentOptions.EnablePerformanceTweaks = false;
  187. CurrentOptions.DisableNetworkThrottling = false;
  188. CurrentOptions.DisableWindowsDefender = false;
  189. CurrentOptions.DisableSystemRestore = false;
  190. CurrentOptions.DisablePrintService = false;
  191. CurrentOptions.DisableMediaPlayerSharing = false;
  192. CurrentOptions.DisableErrorReporting = false;
  193. CurrentOptions.DisableHomeGroup = false;
  194. CurrentOptions.DisableSuperfetch = false;
  195. CurrentOptions.DisableTelemetryTasks = false;
  196. CurrentOptions.DisableOffice2016Telemetry = false;
  197. CurrentOptions.DisableCompatibilityAssistant = false;
  198. CurrentOptions.DisableFaxService = false;
  199. CurrentOptions.DisableSmartScreen = false;
  200. CurrentOptions.DisableStickyKeys = false;
  201. CurrentOptions.EnableLegacyVolumeSlider = false;
  202. CurrentOptions.DisableQuickAccessHistory = false;
  203. CurrentOptions.DisableStartMenuAds = false;
  204. CurrentOptions.UninstallOneDrive = false;
  205. CurrentOptions.DisableMyPeople = false;
  206. CurrentOptions.DisableAutomaticUpdates = false;
  207. CurrentOptions.ExcludeDrivers = false;
  208. CurrentOptions.DisableTelemetryServices = false;
  209. CurrentOptions.DisablePrivacyOptions = false;
  210. CurrentOptions.DisableCortana = false;
  211. CurrentOptions.DisableSensorServices = false;
  212. CurrentOptions.DisableWindowsInk = false;
  213. CurrentOptions.DisableSpellingTyping = false;
  214. CurrentOptions.DisableXboxLive = false;
  215. CurrentOptions.DisableGameBar = false;
  216. CurrentOptions.DisableInsiderService = false;
  217. CurrentOptions.DisableFeatureUpdates = false;
  218. CurrentOptions.DisableCloudClipboard = false;
  219. CurrentOptions.EnableLongPaths = false;
  220. CurrentOptions.RemoveCastToDevice = false;
  221. CurrentOptions.DisableActionCenter = false;
  222. CurrentOptions.DisableOneDrive = false;
  223. CurrentOptions.TaskbarToLeft = false;
  224. CurrentOptions.DisableSnapAssist = false;
  225. CurrentOptions.DisableWidgets = false;
  226. CurrentOptions.DisableChat = false;
  227. CurrentOptions.TaskbarSmaller = false;
  228. CurrentOptions.ClassicRibbon = false;
  229. CurrentOptions.ClassicMenu = false;
  230. CurrentOptions.DisableTPMCheck = false;
  231. using (FileStream fs = File.Open(SettingsFile, FileMode.CreateNew))
  232. using (StreamWriter sw = new StreamWriter(fs))
  233. using (JsonWriter jw = new JsonTextWriter(sw))
  234. {
  235. jw.Formatting = Formatting.Indented;
  236. JsonSerializer serializer = new JsonSerializer();
  237. serializer.Serialize(jw, CurrentOptions);
  238. }
  239. }
  240. else
  241. {
  242. CurrentOptions = JsonConvert.DeserializeObject<SettingsJson>(File.ReadAllText(SettingsFile));
  243. }
  244. LoadTranslation();
  245. }
  246. internal static void LoadTranslation()
  247. {
  248. // load proper translation list
  249. if (CurrentOptions.LanguageCode == LanguageCode.EN) TranslationList = JObject.Parse(Properties.Resources.EN);
  250. if (CurrentOptions.LanguageCode == LanguageCode.RU) TranslationList = JObject.Parse(Properties.Resources.RU);
  251. if (CurrentOptions.LanguageCode == LanguageCode.EL) TranslationList = JObject.Parse(Properties.Resources.EL);
  252. if (CurrentOptions.LanguageCode == LanguageCode.TR) TranslationList = JObject.Parse(Properties.Resources.TR);
  253. if (CurrentOptions.LanguageCode == LanguageCode.DE) TranslationList = JObject.Parse(Properties.Resources.DE);
  254. if (CurrentOptions.LanguageCode == LanguageCode.ES) TranslationList = JObject.Parse(Properties.Resources.ES);
  255. if (CurrentOptions.LanguageCode == LanguageCode.PT) TranslationList = JObject.Parse(Properties.Resources.PT);
  256. if (CurrentOptions.LanguageCode == LanguageCode.FR) TranslationList = JObject.Parse(Properties.Resources.FR);
  257. if (CurrentOptions.LanguageCode == LanguageCode.IT) TranslationList = JObject.Parse(Properties.Resources.IT);
  258. if (CurrentOptions.LanguageCode == LanguageCode.CN) TranslationList = JObject.Parse(Properties.Resources.CN);
  259. }
  260. }
  261. }