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.

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