RomFsProvider.cs 4.2 KB

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