CISOBlob.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2008 Dolphin Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <cstdio>
  5. #include <memory>
  6. #include <string>
  7. #include "Common/CommonTypes.h"
  8. #include "Common/IOFile.h"
  9. #include "DiscIO/Blob.h"
  10. namespace DiscIO
  11. {
  12. static constexpr u32 CISO_MAGIC = 0x4F534943; // "CISO" (byteswapped to little endian)
  13. static const u32 CISO_HEADER_SIZE = 0x8000;
  14. static const u32 CISO_MAP_SIZE = CISO_HEADER_SIZE - sizeof(u32) - sizeof(char) * 4;
  15. struct CISOHeader
  16. {
  17. // "CISO"
  18. u32 magic;
  19. // little endian
  20. u32 block_size;
  21. // 0=unused, 1=used, others=invalid
  22. u8 map[CISO_MAP_SIZE];
  23. };
  24. class CISOFileReader : public BlobReader
  25. {
  26. public:
  27. static std::unique_ptr<CISOFileReader> Create(File::IOFile file);
  28. BlobType GetBlobType() const override { return BlobType::CISO; }
  29. std::unique_ptr<BlobReader> CopyReader() const override;
  30. u64 GetRawSize() const override;
  31. u64 GetDataSize() const override;
  32. DataSizeType GetDataSizeType() const override { return DataSizeType::UpperBound; }
  33. u64 GetBlockSize() const override { return m_block_size; }
  34. bool HasFastRandomAccessInBlock() const override { return true; }
  35. std::string GetCompressionMethod() const override { return {}; }
  36. std::optional<int> GetCompressionLevel() const override { return std::nullopt; }
  37. bool Read(u64 offset, u64 nbytes, u8* out_ptr) override;
  38. private:
  39. CISOFileReader(File::IOFile file);
  40. typedef u16 MapType;
  41. static const MapType UNUSED_BLOCK_ID = UINT16_MAX;
  42. File::IOFile m_file;
  43. u64 m_size;
  44. u32 m_block_size;
  45. MapType m_ciso_map[CISO_MAP_SIZE];
  46. };
  47. } // namespace DiscIO