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.3 KiB

5 years ago
5 years ago
  1. // BEGIN: section ignore
  2. using IPA.Logging;
  3. using IPA.Utilities;
  4. // END: section ignore
  5. using Newtonsoft.Json;
  6. namespace IPA.Config
  7. {
  8. internal class SelfConfig
  9. {
  10. // This is to allow the doc generation to parse this file and use Newtonsoft to generate a JSON schema
  11. // BEGIN: section ignore
  12. private static IConfigProvider _loaderConfig;
  13. public static IConfigProvider LoaderConfig
  14. {
  15. get => _loaderConfig;
  16. set
  17. {
  18. _loaderConfig?.RemoveLinks();
  19. value.Load();
  20. SelfConfigRef = value.MakeLink<SelfConfig>((c, v) =>
  21. {
  22. if (v.Value.Regenerate)
  23. c.Store(v.Value = new SelfConfig { Regenerate = false });
  24. StandardLogger.Configure(v.Value);
  25. });
  26. _loaderConfig = value;
  27. }
  28. }
  29. public static Ref<SelfConfig> SelfConfigRef = new SelfConfig();
  30. public static void Load()
  31. {
  32. LoaderConfig = Config.GetProviderFor(IPAName, "json");
  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.13.4";
  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 bool Regenerate = true;
  68. public class Updates_
  69. {
  70. public bool AutoUpdate = true;
  71. // LINE: ignore 2
  72. public static bool AutoUpdate_ => SelfConfigRef.Value.Updates.AutoUpdate
  73. && CommandLineValues.Updates.AutoUpdate;
  74. public bool AutoCheckUpdates = true;
  75. // LINE: ignore 2
  76. public static bool AutoCheckUpdates_ => SelfConfigRef.Value.Updates.AutoCheckUpdates
  77. && CommandLineValues.Updates.AutoCheckUpdates;
  78. }
  79. public Updates_ Updates = new Updates_();
  80. public class Debug_
  81. {
  82. public bool ShowCallSource = false;
  83. // LINE: ignore 2
  84. public static bool ShowCallSource_ => SelfConfigRef.Value.Debug.ShowCallSource
  85. || CommandLineValues.Debug.ShowCallSource;
  86. public bool ShowDebug = false;
  87. // LINE: ignore 2
  88. public static bool ShowDebug_ => SelfConfigRef.Value.Debug.ShowDebug
  89. || CommandLineValues.Debug.ShowDebug;
  90. // This option only takes effect after a full game restart, unless new logs are created again
  91. public bool CondenseModLogs = false;
  92. // LINE: ignore 2
  93. public static bool CondenseModLogs_ => SelfConfigRef?.Value.Debug.CondenseModLogs ?? false
  94. || CommandLineValues.Debug.CondenseModLogs;
  95. public bool ShowHandledErrorStackTraces = false;
  96. // LINE: ignore
  97. public static bool ShowHandledErrorStackTraces_ => SelfConfigRef.Value.Debug.ShowHandledErrorStackTraces;
  98. public bool HideMessagesForPerformance = true;
  99. // LINE: ignore
  100. public static bool HideMessagesForPerformance_ => SelfConfigRef.Value.Debug.HideMessagesForPerformance;
  101. public int HideLogThreshold = 512;
  102. // LINE: ignore
  103. public static int HideLogThreshold_ => SelfConfigRef.Value.Debug.HideLogThreshold;
  104. public bool ShowTrace = false;
  105. // LINE: ignore 2
  106. public static bool ShowTrace_ => SelfConfigRef.Value.Debug.ShowTrace
  107. || CommandLineValues.Debug.ShowTrace;
  108. }
  109. public Debug_ Debug = new Debug_();
  110. public bool YeetMods = true;
  111. // LINE: ignore 2
  112. public static bool YeetMods_ => SelfConfigRef.Value.YeetMods
  113. && CommandLineValues.YeetMods;
  114. [JsonProperty(Required = Required.Default)]
  115. public string LastGameVersion = null;
  116. // LINE: ignore
  117. public static string LastGameVersion_ => SelfConfigRef.Value.LastGameVersion;
  118. }
  119. }