PFsProvider.cs 3.5 KB

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