Paths.cs 3.1 KB

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