Options.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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.FromArgb(153, 102, 204);
  71. internal static Color ForegroundAccentColor = Color.FromArgb(134, 89, 179);
  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.Amber:
  83. SetTheme(f, Color.FromArgb(195, 146, 0), Color.FromArgb(171, 128, 0));
  84. break;
  85. case Theme.Jade:
  86. SetTheme(f, Color.FromArgb(70, 175, 105), Color.FromArgb(61, 153, 92));
  87. break;
  88. case Theme.Ruby:
  89. SetTheme(f, Color.FromArgb(205, 22, 39), Color.FromArgb(155, 17, 30));
  90. break;
  91. case Theme.Silver:
  92. SetTheme(f, Color.Gray, Color.DimGray);
  93. break;
  94. case Theme.Azurite:
  95. SetTheme(f, Color.FromArgb(0, 127, 255), Color.FromArgb(0, 111, 223));
  96. break;
  97. case Theme.Amethyst:
  98. SetTheme(f, Color.FromArgb(153, 102, 204), Color.FromArgb(134, 89, 179));
  99. break;
  100. }
  101. }
  102. private static void SetTheme(Form f, Color c1, Color c2)
  103. {
  104. dynamic c;
  105. ForegroundColor = c1;
  106. ForegroundAccentColor = c2;
  107. Utilities.GetSelfAndChildrenRecursive(f).ToList().ForEach(x =>
  108. {
  109. c = x;
  110. if (x is Button)
  111. {
  112. c.BackColor = c1;
  113. c.FlatAppearance.BorderColor = c1;
  114. c.FlatAppearance.MouseDownBackColor = c2;
  115. c.FlatAppearance.MouseOverBackColor = c2;
  116. c.FlatAppearance.BorderSize = 0;
  117. }
  118. if (x is LinkLabel)
  119. {
  120. if ((string)c.Tag == _themeFlag)
  121. {
  122. c.LinkColor = c1;
  123. c.VisitedLinkColor = c1;
  124. c.ActiveLinkColor = c2;
  125. }
  126. }
  127. if (x is CheckBox || x is RadioButton || x is Label)
  128. {
  129. if ((string)c.Tag == _themeFlag)
  130. {
  131. c.ForeColor = c1;
  132. }
  133. }
  134. c.Invalidate();
  135. });
  136. }
  137. internal static void LegacyCheck()
  138. {
  139. if (File.Exists(SettingsFile))
  140. {
  141. if (File.ReadAllText(SettingsFile).Contains("FirstRun"))
  142. {
  143. File.Delete(SettingsFile);
  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.Amethyst;
  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.DisableQuickAccessHistory = false;
  194. CurrentOptions.DisableStartMenuAds = false;
  195. CurrentOptions.UninstallOneDrive = false;
  196. CurrentOptions.DisableMyPeople = false;
  197. CurrentOptions.DisableAutomaticUpdates = false;
  198. CurrentOptions.ExcludeDrivers = false;
  199. CurrentOptions.DisableTelemetryServices = false;
  200. CurrentOptions.DisablePrivacyOptions = false;
  201. CurrentOptions.DisableCortana = false;
  202. CurrentOptions.DisableSensorServices = false;
  203. CurrentOptions.DisableWindowsInk = false;
  204. CurrentOptions.DisableSpellingTyping = false;
  205. CurrentOptions.DisableXboxLive = false;
  206. CurrentOptions.DisableGameBar = false;
  207. CurrentOptions.DisableInsiderService = false;
  208. CurrentOptions.DisableFeatureUpdates = false;
  209. CurrentOptions.DisableCloudClipboard = false;
  210. CurrentOptions.EnableLongPaths = false;
  211. CurrentOptions.RemoveCastToDevice = false;
  212. CurrentOptions.DisableActionCenter = false;
  213. CurrentOptions.DisableOneDrive = false;
  214. CurrentOptions.TaskbarToLeft = false;
  215. CurrentOptions.DisableSnapAssist = false;
  216. CurrentOptions.DisableWidgets = false;
  217. CurrentOptions.DisableChat = false;
  218. CurrentOptions.TaskbarSmaller = false;
  219. CurrentOptions.ClassicRibbon = false;
  220. CurrentOptions.ClassicMenu = false;
  221. CurrentOptions.DisableTPMCheck = false;
  222. using (FileStream fs = File.Open(SettingsFile, FileMode.CreateNew))
  223. using (StreamWriter sw = new StreamWriter(fs))
  224. using (JsonWriter jw = new JsonTextWriter(sw))
  225. {
  226. jw.Formatting = Formatting.Indented;
  227. JsonSerializer serializer = new JsonSerializer();
  228. serializer.Serialize(jw, CurrentOptions);
  229. }
  230. }
  231. else
  232. {
  233. CurrentOptions = JsonConvert.DeserializeObject<SettingsJson>(File.ReadAllText(SettingsFile));
  234. }
  235. LoadTranslation();
  236. }
  237. internal static void LoadTranslation()
  238. {
  239. // load proper translation list
  240. if (CurrentOptions.LanguageCode == LanguageCode.EN) TranslationList = JObject.Parse(Properties.Resources.EN);
  241. if (CurrentOptions.LanguageCode == LanguageCode.RU) TranslationList = JObject.Parse(Properties.Resources.RU);
  242. if (CurrentOptions.LanguageCode == LanguageCode.EL) TranslationList = JObject.Parse(Properties.Resources.EL);
  243. if (CurrentOptions.LanguageCode == LanguageCode.TR) TranslationList = JObject.Parse(Properties.Resources.TR);
  244. if (CurrentOptions.LanguageCode == LanguageCode.DE) TranslationList = JObject.Parse(Properties.Resources.DE);
  245. if (CurrentOptions.LanguageCode == LanguageCode.ES) TranslationList = JObject.Parse(Properties.Resources.ES);
  246. if (CurrentOptions.LanguageCode == LanguageCode.PT) TranslationList = JObject.Parse(Properties.Resources.PT);
  247. if (CurrentOptions.LanguageCode == LanguageCode.FR) TranslationList = JObject.Parse(Properties.Resources.FR);
  248. if (CurrentOptions.LanguageCode == LanguageCode.IT) TranslationList = JObject.Parse(Properties.Resources.IT);
  249. if (CurrentOptions.LanguageCode == LanguageCode.CN) TranslationList = JObject.Parse(Properties.Resources.CN);
  250. }
  251. }
  252. }