Assignment for RMIT Mixed Reality in 2020
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.

26 lines
647 B

  1. using System;
  2. using System.IO;
  3. public static class PathHelper
  4. {
  5. public static string MakeRelativePath(string fromPath, string toPath)
  6. {
  7. var fromUri = new Uri(Path.GetFullPath(fromPath));
  8. var toUri = new Uri(Path.GetFullPath(toPath));
  9. if (fromUri.Scheme != toUri.Scheme)
  10. {
  11. return toPath;
  12. }
  13. var relativeUri = fromUri.MakeRelativeUri(toUri);
  14. var relativePath = Uri.UnescapeDataString(relativeUri.ToString());
  15. if (toUri.Scheme.Equals("file", StringComparison.InvariantCultureIgnoreCase))
  16. {
  17. relativePath = relativePath.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
  18. }
  19. return relativePath;
  20. }
  21. }