RomFsProvider.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 RomFsProvider : IFileSystemProvider
  13. {
  14. private Romfs _romFs;
  15. public RomFsProvider(LibHac.IO.IStorage storage)
  16. {
  17. _romFs = new Romfs(storage);
  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. List<DirectoryEntry> directories = new List<DirectoryEntry>();
  38. foreach(RomfsDir directory in _romFs.Directories)
  39. {
  40. DirectoryEntry directoryEntry = new DirectoryEntry(directory.Name, DirectoryEntryType.Directory);
  41. directories.Add(directoryEntry);
  42. }
  43. return directories.ToArray();
  44. }
  45. public DirectoryEntry[] GetEntries(string path)
  46. {
  47. List<DirectoryEntry> entries = new List<DirectoryEntry>();
  48. foreach (RomfsDir directory in _romFs.Directories)
  49. {
  50. DirectoryEntry directoryEntry = new DirectoryEntry(directory.Name, DirectoryEntryType.Directory);
  51. entries.Add(directoryEntry);
  52. }
  53. foreach (RomfsFile file in _romFs.Files)
  54. {
  55. DirectoryEntry directoryEntry = new DirectoryEntry(file.Name, DirectoryEntryType.File, file.DataLength);
  56. entries.Add(directoryEntry);
  57. }
  58. return entries.ToArray();
  59. }
  60. public DirectoryEntry[] GetFiles(string path)
  61. {
  62. List<DirectoryEntry> files = new List<DirectoryEntry>();
  63. foreach (RomfsFile file in _romFs.Files)
  64. {
  65. DirectoryEntry directoryEntry = new DirectoryEntry(file.Name, DirectoryEntryType.File, file.DataLength);
  66. files.Add(directoryEntry);
  67. }
  68. return files.ToArray();
  69. }
  70. public long GetFreeSpace(ServiceCtx context)
  71. {
  72. return 0;
  73. }
  74. public string GetFullPath(string name)
  75. {
  76. return name;
  77. }
  78. public long GetTotalSpace(ServiceCtx context)
  79. {
  80. return _romFs.Files.Sum(x => x.DataLength);
  81. }
  82. public bool DirectoryExists(string name)
  83. {
  84. return _romFs.Directories.Exists(x=>x.Name == name);
  85. }
  86. public bool FileExists(string name)
  87. {
  88. return _romFs.FileExists(name);
  89. }
  90. public long OpenDirectory(string name, int filterFlags, out IDirectory directoryInterface)
  91. {
  92. RomfsDir directory = _romFs.Directories.Find(x => x.Name == name);
  93. if (directory != null)
  94. {
  95. directoryInterface = new IDirectory(name, filterFlags, this);
  96. return 0;
  97. }
  98. directoryInterface = null;
  99. return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
  100. }
  101. public long OpenFile(string name, out IFile fileInterface)
  102. {
  103. if (_romFs.FileExists(name))
  104. {
  105. Stream stream = _romFs.OpenFile(name).AsStream();
  106. fileInterface = new IFile(stream, name);
  107. return 0;
  108. }
  109. fileInterface = null;
  110. return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
  111. }
  112. public long RenameDirectory(string oldName, string newName)
  113. {
  114. throw new NotSupportedException();
  115. }
  116. public long RenameFile(string oldName, string newName)
  117. {
  118. throw new NotSupportedException();
  119. }
  120. public void CheckIfOutsideBasePath(string path)
  121. {
  122. throw new NotSupportedException();
  123. }
  124. public FileTimestamp GetFileTimeStampRaw(string name)
  125. {
  126. throw new NotImplementedException();
  127. }
  128. }
  129. }