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.

160 lines
6.6 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
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 virtual void CopyFrom(SelfConfig cfg) { }
  24. protected internal virtual void OnReload()
  25. {
  26. if (Regenerate)
  27. CopyFrom(new SelfConfig { Regenerate = false });
  28. StandardLogger.Configure();
  29. }
  30. protected internal virtual void Changed()
  31. {
  32. Logger.log.Debug("SelfConfig Changed called");
  33. }
  34. public static void ReadCommandLine(string[] args)
  35. {
  36. foreach (var arg in args)
  37. {
  38. switch (arg)
  39. {
  40. case "--debug":
  41. case "--mono-debug":
  42. CommandLineValues.Debug.ShowDebug = true;
  43. CommandLineValues.Debug.ShowCallSource = true;
  44. break;
  45. case "--no-yeet":
  46. CommandLineValues.YeetMods = false;
  47. break;
  48. case "--condense-logs":
  49. CommandLineValues.Debug.CondenseModLogs = true;
  50. break;
  51. case "--no-updates":
  52. CommandLineValues.Updates.AutoCheckUpdates = false;
  53. CommandLineValues.Updates.AutoUpdate = false;
  54. break;
  55. case "--trace":
  56. CommandLineValues.Debug.ShowTrace = true;
  57. break;
  58. }
  59. }
  60. }
  61. internal const string IPAName = "Beat Saber IPA";
  62. internal const string IPAVersion = "3.99.99.7";
  63. // uses Updates.AutoUpdate, Updates.AutoCheckUpdates, YeetMods, Debug.ShowCallSource, Debug.ShowDebug,
  64. // Debug.CondenseModLogs
  65. internal static SelfConfig CommandLineValues = new SelfConfig();
  66. // END: section ignore
  67. public virtual bool Regenerate { get; set; } = true;
  68. public class Updates_
  69. {
  70. public virtual bool AutoUpdate { get; set; } = true;
  71. // LINE: ignore 2
  72. public static bool AutoUpdate_ => (Instance?.Updates?.AutoUpdate ?? true)
  73. && CommandLineValues.Updates.AutoUpdate;
  74. public virtual bool AutoCheckUpdates { get; set; } = true;
  75. // LINE: ignore 2
  76. public static bool AutoCheckUpdates_ => (Instance?.Updates?.AutoCheckUpdates ?? true)
  77. && CommandLineValues.Updates.AutoCheckUpdates;
  78. }
  79. // LINE: ignore
  80. [NonNullable]
  81. public virtual Updates_ Updates { get; set; } = new Updates_();
  82. public class Debug_
  83. {
  84. public virtual bool ShowCallSource { get; set; } = false;
  85. // LINE: ignore 2
  86. public static bool ShowCallSource_ => (Instance?.Debug?.ShowCallSource ?? false)
  87. || CommandLineValues.Debug.ShowCallSource;
  88. public virtual bool ShowDebug { get; set; } = false;
  89. // LINE: ignore 2
  90. public static bool ShowDebug_ => (Instance?.Debug?.ShowDebug ?? false)
  91. || CommandLineValues.Debug.ShowDebug;
  92. // This option only takes effect after a full game restart, unless new logs are created again
  93. public virtual bool CondenseModLogs { get; set; } = false;
  94. // LINE: ignore 2
  95. public static bool CondenseModLogs_ => (Instance?.Debug?.CondenseModLogs ?? false)
  96. || CommandLineValues.Debug.CondenseModLogs;
  97. public virtual bool ShowHandledErrorStackTraces { get; set; } = false;
  98. // LINE: ignore
  99. public static bool ShowHandledErrorStackTraces_ => Instance?.Debug?.ShowHandledErrorStackTraces ?? false;
  100. public virtual bool HideMessagesForPerformance { get; set; } = true;
  101. // LINE: ignore
  102. public static bool HideMessagesForPerformance_ => Instance?.Debug?.HideMessagesForPerformance ?? true;
  103. public virtual int HideLogThreshold { get; set; } = 512;
  104. // LINE: ignore
  105. public static int HideLogThreshold_ => Instance?.Debug?.HideLogThreshold ?? 512;
  106. public virtual bool ShowTrace { get; set; } = false;
  107. // LINE: ignore 2
  108. public static bool ShowTrace_ => (Instance?.Debug?.ShowTrace ?? false)
  109. || CommandLineValues.Debug.ShowTrace;
  110. }
  111. // LINE: ignore
  112. [NonNullable]
  113. public virtual Debug_ Debug { get; set; } = new Debug_();
  114. public virtual bool YeetMods { get; set; } = true;
  115. // LINE: ignore 2
  116. public static bool YeetMods_ => (Instance?.YeetMods ?? true)
  117. && CommandLineValues.YeetMods;
  118. // LINE: ignore
  119. [NonNullable, UseConverter(typeof(CollectionConverter<string, HashSet<string>>))]
  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. "Main.dll", "HMLib.dll", "HMUI.dll", "HMRendering.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. [JsonProperty(Required = Required.DisallowNull)] // Used for documentation schema generation
  132. public virtual string LastGameVersion { get; set; } = null;
  133. // LINE: ignore
  134. public static string LastGameVersion_ => Instance?.LastGameVersion;
  135. }
  136. }