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. }