Utility.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. namespace BepInEx.Common
  5. {
  6. /// <summary>
  7. /// Generic helper properties and methods.
  8. /// </summary>
  9. public static class Utility
  10. {
  11. /// <summary>
  12. /// The directory that the Koikatsu .exe is being run from.
  13. /// </summary>
  14. public static string ExecutingDirectory => Path.GetDirectoryName(Environment.CommandLine);
  15. /// <summary>
  16. /// The path that the plugins folder is located.
  17. /// </summary>
  18. public static string PluginsDirectory => Path.Combine(ExecutingDirectory, "BepInEx");
  19. /// <summary>
  20. /// Combines multiple paths together, as the specfic method is not availble in .NET 3.5.
  21. /// </summary>
  22. /// <param name="parts">The multiple paths to combine together.</param>
  23. /// <returns>A combined path.</returns>
  24. public static string CombinePaths(params string[] parts) => parts.Aggregate(Path.Combine);
  25. /// <summary>
  26. /// Converts a file path into a UnityEngine.WWW format.
  27. /// </summary>
  28. /// <param name="path">The file path to convert.</param>
  29. /// <returns>A converted file path.</returns>
  30. public static string ConvertToWWWFormat(string path)
  31. {
  32. return $"file://{path.Replace('\\', '/')}";
  33. }
  34. /// <summary>
  35. /// Indicates whether a specified string is null, empty, or consists only of white-space characters.
  36. /// </summary>
  37. /// <param name="self">The string to test.</param>
  38. /// <returns>True if the value parameter is null or empty, or if value consists exclusively of white-space characters.</returns>
  39. public static bool IsNullOrWhiteSpace(this string self)
  40. {
  41. return self == null || self.Trim().Length == 0;
  42. }
  43. }
  44. }