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.

55 lines
2.1 KiB

  1. using System;
  2. using System.Linq;
  3. using OgPath = System.IO.Path;
  4. namespace Net3_Proxy
  5. {
  6. public static class Path
  7. {
  8. internal static void Validate(string path)
  9. => Validate(path, nameof(path));
  10. internal static void Validate(string path, string parameterName)
  11. {
  12. if (path == null)
  13. {
  14. throw new ArgumentNullException(parameterName);
  15. }
  16. if (Utils.IsNullOrWhiteSpace(path))
  17. {
  18. throw new ArgumentException("Path is empty");
  19. }
  20. if (path.IndexOfAny(OgPath.GetInvalidPathChars()) != -1)
  21. {
  22. throw new ArgumentException("Path contains invalid chars");
  23. }
  24. if (Environment.OSVersion.Platform < PlatformID.Unix)
  25. {
  26. int num = path.IndexOf(':');
  27. if (num >= 0 && num != 1)
  28. {
  29. throw new ArgumentException(parameterName);
  30. }
  31. }
  32. }
  33. public static string GetFullPath(string p) => OgPath.GetFullPath(p);
  34. public static string GetFileNameWithoutExtension(string p) => OgPath.GetFileNameWithoutExtension(p);
  35. public static string GetFileName(string p) => OgPath.GetFileName(p);
  36. public static string GetDirectoryName(string p) => OgPath.GetDirectoryName(p);
  37. public static string Combine(string s) => s;
  38. public static string Combine(string s, string d) => OgPath.Combine(s, d);
  39. public static string Combine(string s, string d, string f) => Combine(s, Combine(d, f));
  40. public static string Combine(string s, string d, string f, string g) => Combine(Combine(s, d), Combine(f, g));
  41. public static string Combine(params string[] parts)
  42. {
  43. if (parts.Length == 0) return "";
  44. var begin = parts[0];
  45. foreach (var p in parts.Skip(1))
  46. begin = Combine(begin, p);
  47. return begin;
  48. }
  49. public static char PathSeparator => OgPath.PathSeparator;
  50. }
  51. }