Options.cs 13 KB

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