archive_romfs.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2
  3. // Refer to the license.txt file included.
  4. #include "common/common_types.h"
  5. #include "core/file_sys/archive_romfs.h"
  6. #include "core/file_sys/directory_romfs.h"
  7. #include "core/file_sys/file_romfs.h"
  8. ////////////////////////////////////////////////////////////////////////////////////////////////////
  9. // FileSys namespace
  10. namespace FileSys {
  11. Archive_RomFS::Archive_RomFS(const Loader::AppLoader& app_loader) {
  12. // Load the RomFS from the app
  13. if (Loader::ResultStatus::Success != app_loader.ReadRomFS(raw_data)) {
  14. WARN_LOG(FILESYS, "Unable to read RomFS!");
  15. }
  16. }
  17. Archive_RomFS::~Archive_RomFS() {
  18. }
  19. /**
  20. * Open a file specified by its path, using the specified mode
  21. * @param path Path relative to the archive
  22. * @param mode Mode to open the file with
  23. * @return Opened file, or nullptr
  24. */
  25. std::unique_ptr<File> Archive_RomFS::OpenFile(const Path& path, const Mode mode) const {
  26. return std::unique_ptr<File>(new File_RomFS);
  27. }
  28. /**
  29. * Create a directory specified by its path
  30. * @param path Path relative to the archive
  31. * @return Whether the directory could be created
  32. */
  33. bool Archive_RomFS::CreateDirectory(const Path& path) const {
  34. ERROR_LOG(FILESYS, "Attempted to create a directory in ROMFS.");
  35. return false;
  36. };
  37. /**
  38. * Open a directory specified by its path
  39. * @param path Path relative to the archive
  40. * @return Opened directory, or nullptr
  41. */
  42. std::unique_ptr<Directory> Archive_RomFS::OpenDirectory(const Path& path) const {
  43. return std::unique_ptr<Directory>(new Directory_RomFS);
  44. }
  45. /**
  46. * Read data from the archive
  47. * @param offset Offset in bytes to start reading data from
  48. * @param length Length in bytes of data to read from archive
  49. * @param buffer Buffer to read data into
  50. * @return Number of bytes read
  51. */
  52. size_t Archive_RomFS::Read(const u64 offset, const u32 length, u8* buffer) const {
  53. DEBUG_LOG(FILESYS, "called offset=%llu, length=%d", offset, length);
  54. memcpy(buffer, &raw_data[(u32)offset], length);
  55. return length;
  56. }
  57. /**
  58. * Write data to the archive
  59. * @param offset Offset in bytes to start writing data to
  60. * @param length Length in bytes of data to write to archive
  61. * @param buffer Buffer to write data from
  62. * @param flush The flush parameters (0 == do not flush)
  63. * @return Number of bytes written
  64. */
  65. size_t Archive_RomFS::Write(const u64 offset, const u32 length, const u32 flush, u8* buffer) {
  66. ERROR_LOG(FILESYS, "Attempted to write to ROMFS.");
  67. return 0;
  68. }
  69. /**
  70. * Get the size of the archive in bytes
  71. * @return Size of the archive in bytes
  72. */
  73. size_t Archive_RomFS::GetSize() const {
  74. return sizeof(u8) * raw_data.size();
  75. }
  76. /**
  77. * Set the size of the archive in bytes
  78. */
  79. void Archive_RomFS::SetSize(const u64 size) {
  80. ERROR_LOG(FILESYS, "Attempted to set the size of ROMFS");
  81. }
  82. } // namespace FileSys