暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

FileIOProvider.cs 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 fileName)
  10. {
  11. return File.Exists(fileName);
  12. }
  13. public string ReadAllText(string fileName)
  14. {
  15. return File.ReadAllText(fileName);
  16. }
  17. public void WriteAllText(string path, string content)
  18. {
  19. File.WriteAllText(path, content, Encoding.UTF8);
  20. LastWriteTracker.UpdateLastWriteIfNeeded(path);
  21. }
  22. public string EscapedRelativePathFor(string file, string projectDirectory)
  23. {
  24. var projectDir = Path.GetFullPath(projectDirectory);
  25. // We have to normalize the path, because the PackageManagerRemapper assumes
  26. // dir seperators will be os specific.
  27. var absolutePath = Path.GetFullPath(file.NormalizePath());
  28. var path = SkipPathPrefix(absolutePath, projectDir);
  29. return SecurityElement.Escape(path);
  30. }
  31. private static string SkipPathPrefix(string path, string prefix)
  32. {
  33. return path.StartsWith($@"{prefix}{Path.DirectorySeparatorChar}", StringComparison.Ordinal)
  34. ? path.Substring(prefix.Length + 1)
  35. : path;
  36. }
  37. }
  38. }