Options.cs 14 KB

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