PFsProvider.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. using LibHac;
  2. using Ryujinx.HLE.HOS;
  3. using Ryujinx.HLE.HOS.Services.FspSrv;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.IO;
  7. using System.Linq;
  8. using static Ryujinx.HLE.HOS.ErrorCode;
  9. namespace Ryujinx.HLE.FileSystem
  10. {
  11. class PFsProvider : IFileSystemProvider
  12. {
  13. private Pfs Pfs;
  14. public PFsProvider(Pfs Pfs)
  15. {
  16. this.Pfs = Pfs;
  17. }
  18. public long CreateDirectory(string Name)
  19. {
  20. throw new NotSupportedException();
  21. }
  22. public long CreateFile(string Name, long Size)
  23. {
  24. throw new NotSupportedException();
  25. }
  26. public long DeleteDirectory(string Name, bool Recursive)
  27. {
  28. throw new NotSupportedException();
  29. }
  30. public long DeleteFile(string Name)
  31. {
  32. throw new NotSupportedException();
  33. }
  34. public DirectoryEntry[] GetDirectories(string Path)
  35. {
  36. return new DirectoryEntry[0];
  37. }
  38. public DirectoryEntry[] GetEntries(string Path)
  39. {
  40. List<DirectoryEntry> Entries = new List<DirectoryEntry>();
  41. foreach (PfsFileEntry File in Pfs.Files)
  42. {
  43. DirectoryEntry DirectoryEntry = new DirectoryEntry(File.Name, DirectoryEntryType.File, File.Size);
  44. Entries.Add(DirectoryEntry);
  45. }
  46. return Entries.ToArray();
  47. }
  48. public DirectoryEntry[] GetFiles(string Path)
  49. {
  50. List<DirectoryEntry> Entries = new List<DirectoryEntry>();
  51. foreach (PfsFileEntry File in Pfs.Files)
  52. {
  53. DirectoryEntry DirectoryEntry = new DirectoryEntry(File.Name, DirectoryEntryType.File, File.Size);
  54. Entries.Add(DirectoryEntry);
  55. }
  56. return Entries.ToArray();
  57. }
  58. public long GetFreeSpace(ServiceCtx Context)
  59. {
  60. return 0;
  61. }
  62. public string GetFullPath(string Name)
  63. {
  64. return Name;
  65. }
  66. public long GetTotalSpace(ServiceCtx Context)
  67. {
  68. return Pfs.Files.Sum(x => x.Size);
  69. }
  70. public bool DirectoryExists(string Name)
  71. {
  72. return Name == "/" ? true : false;
  73. }
  74. public bool FileExists(string Name)
  75. {
  76. Name = Name.TrimStart('/');
  77. return Pfs.FileExists(Name);
  78. }
  79. public long OpenDirectory(string Name, int FilterFlags, out IDirectory DirectoryInterface)
  80. {
  81. if (Name == "/")
  82. {
  83. DirectoryInterface = new IDirectory(Name, FilterFlags, this);
  84. return 0;
  85. }
  86. throw new NotSupportedException();
  87. }
  88. public long OpenFile(string Name, out IFile FileInterface)
  89. {
  90. Name = Name.TrimStart('/');
  91. if (Pfs.FileExists(Name))
  92. {
  93. Stream Stream = Pfs.OpenFile(Name);
  94. FileInterface = new IFile(Stream, Name);
  95. return 0;
  96. }
  97. FileInterface = null;
  98. return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
  99. }
  100. public long RenameDirectory(string OldName, string NewName)
  101. {
  102. throw new NotSupportedException();
  103. }
  104. public long RenameFile(string OldName, string NewName)
  105. {
  106. throw new NotSupportedException();
  107. }
  108. public void CheckIfOutsideBasePath(string Path)
  109. {
  110. throw new NotSupportedException();
  111. }
  112. }
  113. }