archive_romfs.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <vector>
  6. #include "common/common_types.h"
  7. #include "core/file_sys/archive_backend.h"
  8. #include "core/loader/loader.h"
  9. ////////////////////////////////////////////////////////////////////////////////////////////////////
  10. // FileSys namespace
  11. namespace FileSys {
  12. /// File system interface to the RomFS archive
  13. class Archive_RomFS final : public ArchiveBackend {
  14. public:
  15. Archive_RomFS(const Loader::AppLoader& app_loader);
  16. ~Archive_RomFS() override;
  17. std::string GetName() const override { return "RomFS"; }
  18. /**
  19. * Open a file specified by its path, using the specified mode
  20. * @param path Path relative to the archive
  21. * @param mode Mode to open the file with
  22. * @return Opened file, or nullptr
  23. */
  24. std::unique_ptr<File> OpenFile(const Path& path, const Mode mode) const override;
  25. /**
  26. * Delete a file specified by its path
  27. * @param path Path relative to the archive
  28. * @return Whether the file could be deleted
  29. */
  30. bool DeleteFile(const FileSys::Path& path) const override;
  31. /**
  32. * Rename a File specified by its path
  33. * @param src_path Source path relative to the archive
  34. * @param dest_path Destination path relative to the archive
  35. * @return Whether rename succeeded
  36. */
  37. bool RenameFile(const FileSys::Path& src_path, const FileSys::Path& dest_path) const override;
  38. /**
  39. * Delete a directory specified by its path
  40. * @param path Path relative to the archive
  41. * @return Whether the directory could be deleted
  42. */
  43. bool DeleteDirectory(const FileSys::Path& path) const override;
  44. /**
  45. * Create a directory specified by its path
  46. * @param path Path relative to the archive
  47. * @return Whether the directory could be created
  48. */
  49. bool CreateDirectory(const Path& path) const override;
  50. /**
  51. * Rename a Directory specified by its path
  52. * @param src_path Source path relative to the archive
  53. * @param dest_path Destination path relative to the archive
  54. * @return Whether rename succeeded
  55. */
  56. bool RenameDirectory(const FileSys::Path& src_path, const FileSys::Path& dest_path) const override;
  57. /**
  58. * Open a directory specified by its path
  59. * @param path Path relative to the archive
  60. * @return Opened directory, or nullptr
  61. */
  62. std::unique_ptr<Directory> OpenDirectory(const Path& path) const override;
  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 Read(const u64 offset, const u32 length, u8* buffer) const override;
  71. /**
  72. * Write data to the archive
  73. * @param offset Offset in bytes to start writing data to
  74. * @param length Length in bytes of data to write to archive
  75. * @param buffer Buffer to write data from
  76. * @param flush The flush parameters (0 == do not flush)
  77. * @return Number of bytes written
  78. */
  79. size_t Write(const u64 offset, const u32 length, const u32 flush, u8* buffer) override;
  80. /**
  81. * Get the size of the archive in bytes
  82. * @return Size of the archive in bytes
  83. */
  84. size_t GetSize() const override;
  85. /**
  86. * Set the size of the archive in bytes
  87. */
  88. void SetSize(const u64 size) override;
  89. private:
  90. std::vector<u8> raw_data;
  91. };
  92. } // namespace FileSys