2015-05-23 22:55:12 -06:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2015-05-17 17:08:10 -06:00
|
|
|
// Licensed under GPLv2+
|
2013-04-17 21:09:55 -06:00
|
|
|
// Refer to the license.txt file included.
|
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"
|
2017-01-15 13:46:32 -07:00
|
|
|
#include "Common/File.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "DiscIO/Blob.h"
|
2011-01-01 14:09:56 -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
|
2011-01-01 14:09:56 -07:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
// "CISO"
|
2016-12-21 03:30:12 -07:00
|
|
|
u32 magic;
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
// little endian
|
|
|
|
u32 block_size;
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2016-06-24 02:43:46 -06: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
|
2011-01-01 14:09:56 -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
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
BlobType GetBlobType() const override { return BlobType::CISO; }
|
2020-04-04 12:56:20 -06:00
|
|
|
|
|
|
|
u64 GetRawSize() const override;
|
2016-06-24 02:43:46 -06:00
|
|
|
// The CISO format does not save the original file size.
|
|
|
|
// This function returns an upper bound.
|
|
|
|
u64 GetDataSize() const override;
|
2019-03-21 15:20:23 -06:00
|
|
|
bool IsDataSizeAccurate() const override { return false; }
|
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 {}; }
|
2020-04-04 12:56:20 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
bool Read(u64 offset, u64 nbytes, u8* out_ptr) override;
|
2011-01-01 14:09:56 -07:00
|
|
|
|
|
|
|
private:
|
2016-12-21 04:50:15 -07:00
|
|
|
CISOFileReader(File::IOFile file);
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2016-06-24 02:43:46 -06: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
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
File::IOFile m_file;
|
|
|
|
u64 m_size;
|
|
|
|
u32 m_block_size;
|
|
|
|
MapType m_ciso_map[CISO_MAP_SIZE];
|
2011-01-01 14:09:56 -07:00
|
|
|
};
|
|
|
|
|
2019-05-05 17:48:12 -06:00
|
|
|
} // namespace DiscIO
|