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.

157 lines
6.4 KiB

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 internal virtual void OnReload()
  24. {
  25. StandardLogger.Configure();
  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.3";
  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. public virtual Updates_ Updates { get; set; } = new Updates_();
  79. public class Debug_
  80. {
  81. public virtual bool ShowCallSource { get; set; } = false;
  82. // LINE: ignore 2
  83. public static bool ShowCallSource_ => (Instance?.Debug?.ShowCallSource ?? false)
  84. || CommandLineValues.Debug.ShowCallSource;
  85. public virtual bool ShowDebug { get; set; } = false;
  86. // LINE: ignore 2
  87. public static bool ShowDebug_ => (Instance?.Debug?.ShowDebug ?? false)
  88. || CommandLineValues.Debug.ShowDebug;
  89. // This option only takes effect after a full game restart, unless new logs are created again
  90. public virtual bool CondenseModLogs { get; set; } = false;
  91. // LINE: ignore 2
  92. public static bool CondenseModLogs_ => (Instance?.Debug?.CondenseModLogs ?? false)
  93. || CommandLineValues.Debug.CondenseModLogs;
  94. public virtual bool ShowHandledErrorStackTraces { get; set; } = false;
  95. // LINE: ignore
  96. public static bool ShowHandledErrorStackTraces_ => Instance?.Debug?.ShowHandledErrorStackTraces ?? false;
  97. public virtual bool HideMessagesForPerformance { get; set; } = true;
  98. // LINE: ignore
  99. public static bool HideMessagesForPerformance_ => Instance?.Debug?.HideMessagesForPerformance ?? true;
  100. public virtual int HideLogThreshold { get; set; } = 512;
  101. // LINE: ignore
  102. public static int HideLogThreshold_ => Instance?.Debug?.HideLogThreshold ?? 512;
  103. public virtual bool ShowTrace { get; set; } = false;
  104. // LINE: ignore 2
  105. public static bool ShowTrace_ => (Instance?.Debug?.ShowTrace ?? false)
  106. || CommandLineValues.Debug.ShowTrace;
  107. }
  108. // LINE: ignore
  109. [NonNullable]
  110. public virtual Debug_ Debug { get; set; } = new Debug_();
  111. public virtual bool YeetMods { get; set; } = true;
  112. // LINE: ignore 2
  113. public static bool YeetMods_ => (Instance?.YeetMods ?? true)
  114. && CommandLineValues.YeetMods;
  115. // LINE: ignore
  116. [NonNullable, UseConverter(typeof(CollectionConverter<string, HashSet<string>>))]
  117. public virtual HashSet<string> GameAssemblies { get; set; } = new HashSet<string>
  118. {
  119. // LINE: ignore 5
  120. #if BeatSaber // provide these defaults only for Beat Saber builds
  121. "MainAssembly.dll", "HMLib.dll", "HMUI.dll", "VRUI.dll"
  122. #else // otherwise specify Assembly-CSharp.dll
  123. "Assembly-CSharp.dll"
  124. #endif
  125. };
  126. // LINE: ignore
  127. public static HashSet<string> GameAssemblies_ => Instance?.GameAssemblies ?? new HashSet<string> { "Assembly-CSharp.dll" };
  128. [JsonProperty(Required = Required.DisallowNull)] // Used for documentation schema generation
  129. public virtual string LastGameVersion { get; set; } = null;
  130. // LINE: ignore
  131. public static string LastGameVersion_ => Instance?.LastGameVersion;
  132. }
  133. }