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.

133 lines
4.9 KiB

  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;
  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 "--no-yeet":
  41. CommandLineValues.YeetMods = false;
  42. break;
  43. case "--condense-logs":
  44. CommandLineValues.Debug.CondenseModLogs = true;
  45. break;
  46. case "--debug":
  47. CommandLineValues.Debug.ShowDebug = true;
  48. CommandLineValues.Debug.ShowCallSource = true;
  49. break;
  50. case "--no-updates":
  51. CommandLineValues.Updates.AutoCheckUpdates = false;
  52. CommandLineValues.Updates.AutoUpdate = false;
  53. break;
  54. }
  55. }
  56. }
  57. internal const string IPAName = "Beat Saber IPA";
  58. internal const string IPAVersion = "3.12.25";
  59. // uses Updates.AutoUpdate, Updates.AutoCheckUpdates, YeetMods, Debug.ShowCallSource, Debug.ShowDebug,
  60. // Debug.CondenseModLogs
  61. internal static SelfConfig CommandLineValues = new SelfConfig();
  62. // END: section ignore
  63. public bool Regenerate = true;
  64. public class Updates_
  65. {
  66. public bool AutoUpdate = true;
  67. // LINE: ignore 2
  68. public static bool AutoUpdate_ => SelfConfigRef.Value.Updates.AutoUpdate
  69. && CommandLineValues.Updates.AutoUpdate;
  70. public bool AutoCheckUpdates = true;
  71. // LINE: ignore 2
  72. public static bool AutoCheckUpdates_ => SelfConfigRef.Value.Updates.AutoCheckUpdates
  73. && CommandLineValues.Updates.AutoCheckUpdates;
  74. }
  75. public Updates_ Updates = new Updates_();
  76. public class Debug_
  77. {
  78. public bool ShowCallSource = false;
  79. // LINE: ignore 2
  80. public static bool ShowCallSource_ => SelfConfigRef.Value.Debug.ShowCallSource
  81. || CommandLineValues.Debug.ShowCallSource;
  82. public bool ShowDebug = false;
  83. // LINE: ignore 2
  84. public static bool ShowDebug_ => SelfConfigRef.Value.Debug.ShowDebug
  85. || CommandLineValues.Debug.ShowDebug;
  86. // This option only takes effect after a full game restart, unless new logs are created again
  87. public bool CondenseModLogs = false;
  88. // LINE: ignore 2
  89. public static bool CondenseModLogs_ => SelfConfigRef.Value.Debug.CondenseModLogs
  90. || CommandLineValues.Debug.CondenseModLogs;
  91. public bool ShowHandledErrorStackTraces = false;
  92. // LINE: ignore
  93. public static bool ShowHandledErrorStackTraces_ => SelfConfigRef.Value.Debug.ShowHandledErrorStackTraces;
  94. public bool HideMessagesForPerformance = true;
  95. // LINE: ignore
  96. public static bool HideMessagesForPerformance_ => SelfConfigRef.Value.Debug.HideMessagesForPerformance;
  97. public int HideLogThreshold = 512;
  98. // LINE: ignore
  99. public static int HideLogThreshold_ => SelfConfigRef.Value.Debug.HideLogThreshold;
  100. }
  101. public Debug_ Debug = new Debug_();
  102. public bool YeetMods = true;
  103. // LINE: ignore 2
  104. public static bool YeetMods_ => SelfConfigRef.Value.YeetMods
  105. && CommandLineValues.YeetMods;
  106. [JsonProperty(Required = Required.Default)]
  107. public string LastGameVersion = null;
  108. // LINE: ignore
  109. public static string LastGameVersion_ => SelfConfigRef.Value.LastGameVersion;
  110. }
  111. }