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. _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 == "/";
  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. }