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.

142 lines
5.6 KiB

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