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.

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