2015-05-23 22:55:12 -06:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2021-07-04 19:22:19 -06:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2011-01-01 14:09:56 -07:00
|
|
|
|
2014-02-10 11:54:46 -07:00
|
|
|
#pragma once
|
2011-01-01 14:09:56 -07:00
|
|
|
|
2014-02-20 17:47:53 -07:00
|
|
|
#include <cstdio>
|
2015-12-06 21:15:51 -07:00
|
|
|
#include <memory>
|
2014-03-12 13:33:41 -06:00
|
|
|
#include <string>
|
2014-02-20 17:47:53 -07:00
|
|
|
|
|
|
|
#include "Common/CommonTypes.h"
|
2020-09-15 04:29:41 -06:00
|
|
|
#include "Common/IOFile.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "DiscIO/Blob.h"
|
2011-01-01 14:09:56 -07:00
|
|
|
|
2010-12-29 07:42:20 -07:00
|
|
|
namespace DiscIO
|
|
|
|
{
|
2016-12-21 03:30:12 -07:00
|
|
|
static constexpr u32 CISO_MAGIC = 0x4F534943; // "CISO" (byteswapped to little endian)
|
2011-01-01 14:09:56 -07:00
|
|
|
|
2013-03-04 23:28:41 -07:00
|
|
|
static const u32 CISO_HEADER_SIZE = 0x8000;
|
|
|
|
static const u32 CISO_MAP_SIZE = CISO_HEADER_SIZE - sizeof(u32) - sizeof(char) * 4;
|
|
|
|
|
|
|
|
struct CISOHeader
|
2010-12-29 07:42:20 -07:00
|
|
|
{
|
2013-03-04 23:28:41 -07:00
|
|
|
// "CISO"
|
2016-12-21 03:30:12 -07:00
|
|
|
u32 magic;
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2013-03-04 23:28:41 -07:00
|
|
|
// little endian
|
|
|
|
u32 block_size;
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2013-03-04 23:28:41 -07:00
|
|
|
// 0=unused, 1=used, others=invalid
|
|
|
|
u8 map[CISO_MAP_SIZE];
|
2011-03-11 03:21:46 -07:00
|
|
|
};
|
2011-01-01 14:09:56 -07:00
|
|
|
|
2017-06-06 03:49:01 -06:00
|
|
|
class CISOFileReader : public BlobReader
|
2010-12-29 07:42:20 -07:00
|
|
|
{
|
|
|
|
public:
|
2016-12-21 04:50:15 -07:00
|
|
|
static std::unique_ptr<CISOFileReader> Create(File::IOFile file);
|
2015-09-17 02:58:38 -06:00
|
|
|
|
2015-09-27 06:01:12 -06:00
|
|
|
BlobType GetBlobType() const override { return BlobType::CISO; }
|
2020-04-04 12:56:20 -06:00
|
|
|
|
|
|
|
u64 GetRawSize() const override;
|
2014-03-07 17:54:44 -07:00
|
|
|
u64 GetDataSize() const override;
|
2022-08-01 03:53:30 -06:00
|
|
|
DataSizeType GetDataSizeType() const override { return DataSizeType::UpperBound; }
|
2015-09-17 02:58:38 -06:00
|
|
|
|
2020-04-04 12:56:20 -06:00
|
|
|
u64 GetBlockSize() const override { return m_block_size; }
|
2020-06-07 06:11:00 -06:00
|
|
|
bool HasFastRandomAccessInBlock() const override { return true; }
|
2020-06-21 12:41:50 -06:00
|
|
|
std::string GetCompressionMethod() const override { return {}; }
|
2022-02-24 03:51:52 -07:00
|
|
|
std::optional<int> GetCompressionLevel() const override { return std::nullopt; }
|
2020-04-04 12:56:20 -06:00
|
|
|
|
2014-03-07 17:54:44 -07:00
|
|
|
bool Read(u64 offset, u64 nbytes, u8* out_ptr) override;
|
2011-01-01 14:09:56 -07:00
|
|
|
|
2010-12-29 07:42:20 -07:00
|
|
|
private:
|
2016-12-21 04:50:15 -07:00
|
|
|
CISOFileReader(File::IOFile file);
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2013-03-04 23:28:41 -07:00
|
|
|
typedef u16 MapType;
|
2017-06-07 05:16:02 -06:00
|
|
|
static const MapType UNUSED_BLOCK_ID = UINT16_MAX;
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2013-03-04 23:28:41 -07:00
|
|
|
File::IOFile m_file;
|
|
|
|
u64 m_size;
|
|
|
|
u32 m_block_size;
|
|
|
|
MapType m_ciso_map[CISO_MAP_SIZE];
|
2010-12-29 07:42:20 -07:00
|
|
|
};
|
2011-01-01 14:09:56 -07:00
|
|
|
|
2019-05-05 17:48:12 -06:00
|
|
|
} // namespace DiscIO
|