archive_romfs.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. * Delete a file specified by its path
  30. * @param path Path relative to the archive
  31. * @return Whether the file could be deleted
  32. */
  33. bool Archive_RomFS::DeleteFile(const FileSys::Path& path) const {
  34. ERROR_LOG(FILESYS, "Attempted to delete a file from ROMFS.");
  35. return false;
  36. }
  37. /**
  38. * Delete a directory specified by its path
  39. * @param path Path relative to the archive
  40. * @return Whether the directory could be deleted
  41. */
  42. bool Archive_RomFS::DeleteDirectory(const FileSys::Path& path) const {
  43. ERROR_LOG(FILESYS, "Attempted to delete a directory from ROMFS.");
  44. return false;
  45. }
  46. /**
  47. * Create a directory specified by its path
  48. * @param path Path relative to the archive
  49. * @return Whether the directory could be created
  50. */
  51. bool Archive_RomFS::CreateDirectory(const Path& path) const {
  52. ERROR_LOG(FILESYS, "Attempted to create a directory in ROMFS.");
  53. return false;
  54. }
  55. /**
  56. * Open a directory specified by its path
  57. * @param path Path relative to the archive
  58. * @return Opened directory, or nullptr
  59. */
  60. std::unique_ptr<Directory> Archive_RomFS::OpenDirectory(const Path& path) const {
  61. return std::unique_ptr<Directory>(new Directory_RomFS);
  62. }
  63. /**
  64. * Read data from the archive
  65. * @param offset Offset in bytes to start reading data from
  66. * @param length Length in bytes of data to read from archive
  67. * @param buffer Buffer to read data into
  68. * @return Number of bytes read
  69. */
  70. size_t Archive_RomFS::Read(const u64 offset, const u32 length, u8* buffer) const {
  71. DEBUG_LOG(FILESYS, "called offset=%llu, length=%d", offset, length);
  72. memcpy(buffer, &raw_data[(u32)offset], length);
  73. return length;
  74. }
  75. /**
  76. * Write data to the archive
  77. * @param offset Offset in bytes to start writing data to
  78. * @param length Length in bytes of data to write to archive
  79. * @param buffer Buffer to write data from
  80. * @param flush The flush parameters (0 == do not flush)
  81. * @return Number of bytes written
  82. */
  83. size_t Archive_RomFS::Write(const u64 offset, const u32 length, const u32 flush, u8* buffer) {
  84. ERROR_LOG(FILESYS, "Attempted to write to ROMFS.");
  85. return 0;
  86. }
  87. /**
  88. * Get the size of the archive in bytes
  89. * @return Size of the archive in bytes
  90. */
  91. size_t Archive_RomFS::GetSize() const {
  92. return sizeof(u8) * raw_data.size();
  93. }
  94. /**
  95. * Set the size of the archive in bytes
  96. */
  97. void Archive_RomFS::SetSize(const u64 size) {
  98. ERROR_LOG(FILESYS, "Attempted to set the size of ROMFS");
  99. }
  100. } // namespace FileSys