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"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "Common/FileUtil.h"
|
|
|
|
#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
|
|
|
|
|
|
|
class CISOFileReader : public IBlobReader
|
|
|
|
{
|
|
|
|
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; }
|
|
|
|
// The CISO format does not save the original file size.
|
|
|
|
// This function returns an upper bound.
|
|
|
|
u64 GetDataSize() const override;
|
2015-09-17 02:58:38 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
u64 GetRawSize() const override;
|
|
|
|
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;
|
|
|
|
static const MapType UNUSED_BLOCK_ID = -1;
|
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
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|