You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

159 lines
6.4 KiB

4 years ago
  1. // BEGIN: section ignore
  2. using IPA.Logging;
  3. using IPA.Utilities;
  4. using IPA.Config.Stores;
  5. using IPA.Config.Stores.Attributes;
  6. using IPA.Config.Stores.Converters;
  7. // END: section ignore
  8. using Newtonsoft.Json;
  9. using System.Collections.Generic;
  10. namespace IPA.Config
  11. {
  12. internal class SelfConfig
  13. {
  14. // This is to allow the doc generation to parse this file and use Newtonsoft to generate a JSON schema
  15. // BEGIN: section ignore
  16. public static Config LoaderConfig { get; set; }
  17. public static SelfConfig Instance = new SelfConfig();
  18. public static void Load()
  19. {
  20. LoaderConfig = Config.GetConfigFor(IPAName, "json");
  21. Instance = LoaderConfig.Generated<SelfConfig>();
  22. }
  23. protected internal virtual void OnReload()
  24. {
  25. StandardLogger.Configure(this);
  26. }
  27. protected internal virtual void Changed()
  28. {
  29. Logger.log.Debug("SelfConfig Changed called");
  30. }
  31. public static void ReadCommandLine(string[] args)
  32. {
  33. foreach (var arg in args)
  34. {
  35. switch (arg)
  36. {
  37. case "--debug":
  38. case "--mono-debug":
  39. CommandLineValues.Debug.ShowDebug = true;
  40. CommandLineValues.Debug.ShowCallSource = true;
  41. break;
  42. case "--no-yeet":
  43. CommandLineValues.YeetMods = false;
  44. break;
  45. case "--condense-logs":
  46. CommandLineValues.Debug.CondenseModLogs = true;
  47. break;
  48. case "--no-updates":
  49. CommandLineValues.Updates.AutoCheckUpdates = false;
  50. CommandLineValues.Updates.AutoUpdate = false;
  51. break;
  52. case "--trace":
  53. CommandLineValues.Debug.ShowTrace = true;
  54. break;
  55. }
  56. }
  57. }
  58. internal const string IPAName = "Beat Saber IPA";
  59. internal const string IPAVersion = "3.99.99.1";
  60. // uses Updates.AutoUpdate, Updates.AutoCheckUpdates, YeetMods, Debug.ShowCallSource, Debug.ShowDebug,
  61. // Debug.CondenseModLogs
  62. internal static SelfConfig CommandLineValues = new SelfConfig();
  63. // END: section ignore
  64. public virtual bool Regenerate { get; set; } = true;
  65. public class Updates_
  66. {
  67. public virtual bool AutoUpdate { get; set; } = true;
  68. // LINE: ignore 2
  69. public static bool AutoUpdate_ => (Instance?.Updates?.AutoUpdate ?? true)
  70. && CommandLineValues.Updates.AutoUpdate;
  71. public virtual bool AutoCheckUpdates { get; set; } = true;
  72. // LINE: ignore 2
  73. public static bool AutoCheckUpdates_ => (Instance?.Updates?.AutoCheckUpdates ?? true)
  74. && CommandLineValues.Updates.AutoCheckUpdates;
  75. }
  76. // LINE: ignore
  77. [NonNullable]
  78. [JsonProperty(Required = Required.DisallowNull)] // the JsonProperty annotations are for the generated schema
  79. public virtual Updates_ Updates { get; set; } = new Updates_();
  80. public class Debug_
  81. {
  82. public virtual bool ShowCallSource { get; set; } = false;
  83. // LINE: ignore 2
  84. public static bool ShowCallSource_ => (Instance?.Debug?.ShowCallSource ?? false)
  85. || CommandLineValues.Debug.ShowCallSource;
  86. public virtual bool ShowDebug { get; set; } = false;
  87. // LINE: ignore 2
  88. public static bool ShowDebug_ => (Instance?.Debug?.ShowDebug ?? false)
  89. || CommandLineValues.Debug.ShowDebug;
  90. // This option only takes effect after a full game restart, unless new logs are created again
  91. public virtual bool CondenseModLogs { get; set; } = false;
  92. // LINE: ignore 2
  93. public static bool CondenseModLogs_ => (Instance?.Debug?.CondenseModLogs ?? false)
  94. || CommandLineValues.Debug.CondenseModLogs;
  95. public virtual bool ShowHandledErrorStackTraces { get; set; } = false;
  96. // LINE: ignore
  97. public static bool ShowHandledErrorStackTraces_ => Instance?.Debug?.ShowHandledErrorStackTraces ?? false;
  98. public virtual bool HideMessagesForPerformance { get; set; } = true;
  99. // LINE: ignore
  100. public static bool HideMessagesForPerformance_ => Instance?.Debug?.HideMessagesForPerformance ?? true;
  101. public virtual int HideLogThreshold { get; set; } = 512;
  102. // LINE: ignore
  103. public static int HideLogThreshold_ => Instance?.Debug?.HideLogThreshold ?? 512;
  104. public virtual bool ShowTrace { get; set; } = false;
  105. // LINE: ignore 2
  106. public static bool ShowTrace_ => (Instance?.Debug?.ShowTrace ?? false)
  107. || CommandLineValues.Debug.ShowTrace;
  108. }
  109. // LINE: ignore
  110. [NonNullable]
  111. [JsonProperty(Required = Required.DisallowNull)]
  112. public virtual Debug_ Debug { get; set; } = new Debug_();
  113. public virtual bool YeetMods { get; set; } = true;
  114. // LINE: ignore 2
  115. public static bool YeetMods_ => (Instance?.YeetMods ?? true)
  116. && CommandLineValues.YeetMods;
  117. // LINE: ignore
  118. [NonNullable, UseConverter(typeof(CollectionConverter<string, HashSet<string>>))]
  119. [JsonProperty(Required = Required.DisallowNull)]
  120. public virtual HashSet<string> GameAssemblies { get; set; } = new HashSet<string>
  121. {
  122. // LINE: ignore 5
  123. #if BeatSaber // provide these defaults only for Beat Saber builds
  124. "MainAssembly.dll", "HMLib.dll", "HMUI.dll", "VRUI.dll"
  125. #else // otherwise specify Assembly-CSharp.dll
  126. "Assembly-CSharp.dll"
  127. #endif
  128. };
  129. // LINE: ignore
  130. public static HashSet<string> GameAssemblies_ => Instance?.GameAssemblies ?? new HashSet<string> { "Assembly-CSharp.dll" };
  131. public virtual string LastGameVersion { get; set; } = null;
  132. // LINE: ignore
  133. public static string LastGameVersion_ => Instance?.LastGameVersion;
  134. }
  135. }