archive_romfs.cpp 3.8 KB

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