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.

134 lines
4.9 KiB

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