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.

164 lines
6.8 KiB

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