暫無描述
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.

FileIOProvider.cs 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. using System.IO;
  3. using System.Security;
  4. using System.Text;
  5. using Packages.Rider.Editor.Util;
  6. namespace Packages.Rider.Editor.ProjectGeneration {
  7. class FileIOProvider : IFileIO
  8. {
  9. public bool Exists(string path)
  10. {
  11. return File.Exists(path);
  12. }
  13. public TextReader GetReader(string path)
  14. {
  15. return new StreamReader(path);
  16. }
  17. public string ReadAllText(string path)
  18. {
  19. return File.ReadAllText(path);
  20. }
  21. public void WriteAllText(string path, string content)
  22. {
  23. File.WriteAllText(path, content, Encoding.UTF8);
  24. LastWriteTracker.UpdateLastWriteIfNeeded(path);
  25. }
  26. public string EscapedRelativePathFor(string file, string rootDirectoryFullPath)
  27. {
  28. // We have to normalize the path, because the PackageManagerRemapper assumes
  29. // dir seperators will be os specific.
  30. var absolutePath = Path.GetFullPath(file.NormalizePath());
  31. var path = SkipPathPrefix(absolutePath, rootDirectoryFullPath);
  32. return SecurityElement.Escape(path);
  33. }
  34. private static string SkipPathPrefix(string path, string prefix)
  35. {
  36. var root = prefix[prefix.Length - 1] == Path.DirectorySeparatorChar
  37. ? prefix
  38. : prefix + Path.DirectorySeparatorChar;
  39. return path.StartsWith(root, StringComparison.Ordinal)
  40. ? path.Substring(root.Length)
  41. : path;
  42. }
  43. }
  44. }