Paths.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using System.IO;
  2. using System.Linq;
  3. using System.Reflection;
  4. using MonoMod.Utils;
  5. namespace BepInEx
  6. {
  7. /// <summary>
  8. /// Paths used by BepInEx
  9. /// </summary>
  10. public static class Paths
  11. {
  12. public static void SetExecutablePath(string executablePath, string bepinRootPath = null)
  13. {
  14. ExecutablePath = executablePath;
  15. ProcessName = Path.GetFileNameWithoutExtension(executablePath);
  16. GameRootPath = PlatformHelper.Is(Platform.MacOS)
  17. ? Utility.ParentDirectory(executablePath, 4)
  18. : Path.GetDirectoryName(executablePath);
  19. BepInExRootPath = bepinRootPath ?? Path.Combine(GameRootPath, "BepInEx");
  20. ConfigPath = Path.Combine(BepInExRootPath, "config");
  21. BepInExConfigPath = Path.Combine(ConfigPath, "BepInEx.cfg");
  22. PluginPath = Path.Combine(BepInExRootPath, "plugins");
  23. PatcherPluginPath = Path.Combine(BepInExRootPath, "patchers");
  24. BepInExAssemblyDirectory = Path.Combine(BepInExRootPath, "core");
  25. BepInExAssemblyPath = Path.Combine(BepInExAssemblyDirectory, $"{Assembly.GetExecutingAssembly().GetName().Name}.dll");
  26. CachePath = Path.Combine(BepInExRootPath, "cache");
  27. }
  28. internal static void SetPluginPath(string pluginPath)
  29. {
  30. PluginPath = Utility.CombinePaths(BepInExRootPath, pluginPath);
  31. }
  32. public static SemVer.Version BepInExVersion { get; } = SemVer.Version.Parse(typeof(Paths).Assembly.GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false).Cast<AssemblyInformationalVersionAttribute>().First().InformationalVersion);
  33. /// <summary>
  34. /// The directory that the core BepInEx DLLs reside in.
  35. /// </summary>
  36. public static string BepInExAssemblyDirectory { get; private set; }
  37. /// <summary>
  38. /// The path to the core BepInEx DLL.
  39. /// </summary>
  40. public static string BepInExAssemblyPath { get; private set; }
  41. /// <summary>
  42. /// The path to the main BepInEx folder.
  43. /// </summary>
  44. public static string BepInExRootPath { get; private set; }
  45. /// <summary>
  46. /// The path of the currently executing program BepInEx is encapsulated in.
  47. /// </summary>
  48. public static string ExecutablePath { get; private set; }
  49. /// <summary>
  50. /// The directory that the currently executing process resides in.
  51. /// <para>On OSX however, this is the parent directory of the game.app folder.</para>
  52. /// </summary>
  53. public static string GameRootPath { get; private set; }
  54. /// <summary>
  55. /// The path to the config directory.
  56. /// </summary>
  57. public static string ConfigPath { get; private set; }
  58. /// <summary>
  59. /// The path to the global BepInEx configuration file.
  60. /// </summary>
  61. public static string BepInExConfigPath { get; private set; }
  62. /// <summary>
  63. /// The path to temporary cache files.
  64. /// </summary>
  65. public static string CachePath { get; private set; }
  66. /// <summary>
  67. /// The path to the patcher plugin folder which resides in the BepInEx folder.
  68. /// </summary>
  69. public static string PatcherPluginPath { get; private set; }
  70. /// <summary>
  71. /// The path to the plugin folder which resides in the BepInEx folder.
  72. /// <para>
  73. /// This is ONLY guaranteed to be set correctly when Chainloader has been initialized.
  74. /// </para>
  75. /// </summary>
  76. public static string PluginPath { get; private set; }
  77. /// <summary>
  78. /// The name of the currently executing process.
  79. /// </summary>
  80. public static string ProcessName { get; private set; }
  81. }
  82. }