ivfc_archive.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <cstddef>
  6. #include <memory>
  7. #include <string>
  8. #include <vector>
  9. #include "common/common_types.h"
  10. #include "common/file_util.h"
  11. #include "core/file_sys/archive_backend.h"
  12. #include "core/file_sys/directory_backend.h"
  13. #include "core/file_sys/file_backend.h"
  14. #include "core/hle/result.h"
  15. ////////////////////////////////////////////////////////////////////////////////////////////////////
  16. // FileSys namespace
  17. namespace FileSys {
  18. /**
  19. * Helper which implements an interface to deal with IVFC images used in some archives
  20. * This should be subclassed by concrete archive types, which will provide the
  21. * input data (load the raw IVFC archive) and override any required methods
  22. */
  23. class IVFCArchive : public ArchiveBackend {
  24. public:
  25. IVFCArchive(std::shared_ptr<FileUtil::IOFile> file, u64 offset, u64 size)
  26. : romfs_file(file), data_offset(offset), data_size(size) {}
  27. std::string GetName() const override;
  28. std::unique_ptr<FileBackend> OpenFile(const Path& path, const Mode mode) const override;
  29. bool DeleteFile(const Path& path) const override;
  30. bool RenameFile(const Path& src_path, const Path& dest_path) const override;
  31. bool DeleteDirectory(const Path& path) const override;
  32. ResultCode CreateFile(const Path& path, u32 size) const override;
  33. bool CreateDirectory(const Path& path) const override;
  34. bool RenameDirectory(const Path& src_path, const Path& dest_path) const override;
  35. std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const override;
  36. protected:
  37. std::shared_ptr<FileUtil::IOFile> romfs_file;
  38. u64 data_offset;
  39. u64 data_size;
  40. };
  41. class IVFCFile : public FileBackend {
  42. public:
  43. IVFCFile(std::shared_ptr<FileUtil::IOFile> file, u64 offset, u64 size)
  44. : romfs_file(file), data_offset(offset), data_size(size) {}
  45. bool Open() override { return true; }
  46. size_t Read(const u64 offset, const u32 length, u8* buffer) const override;
  47. size_t Write(const u64 offset, const u32 length, const u32 flush, const u8* buffer) const override;
  48. size_t GetSize() const override;
  49. bool SetSize(const u64 size) const override;
  50. bool Close() const override { return false; }
  51. void Flush() const override { }
  52. private:
  53. std::shared_ptr<FileUtil::IOFile> romfs_file;
  54. u64 data_offset;
  55. u64 data_size;
  56. };
  57. class IVFCDirectory : public DirectoryBackend {
  58. public:
  59. bool Open() override { return false; }
  60. u32 Read(const u32 count, Entry* entries) override { return 0; }
  61. bool Close() const override { return false; }
  62. };
  63. } // namespace FileSys