2013-04-18 03:09:55 +00:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2014-02-10 18:54:46 +00:00
|
|
|
#pragma once
|
2008-12-08 04:46:09 +00:00
|
|
|
|
|
|
|
// BLOB
|
|
|
|
|
|
|
|
// Blobs in Dolphin are read only Binary Large OBjects. For example, a typical DVD image.
|
|
|
|
// Often, you may want to store these things in a highly compressed format, but still
|
|
|
|
// allow random access. Or you may store them on an odd device, like raw on a DVD.
|
|
|
|
|
|
|
|
// Always read your BLOBs using an interface returned by CreateBlobReader(). It will
|
2009-02-22 16:48:54 +00:00
|
|
|
// detect whether the file is a compressed blob, or just a big hunk of data, or a drive, and
|
2008-12-08 04:46:09 +00:00
|
|
|
// automatically do the right thing.
|
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2008-12-08 04:46:09 +00:00
|
|
|
|
|
|
|
namespace DiscIO
|
|
|
|
{
|
|
|
|
|
|
|
|
class IBlobReader
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~IBlobReader() {}
|
|
|
|
|
|
|
|
virtual u64 GetRawSize() const = 0;
|
|
|
|
virtual u64 GetDataSize() const = 0;
|
2010-01-11 23:27:02 +00:00
|
|
|
// NOT thread-safe - can't call this from multiple threads.
|
2008-12-08 04:46:09 +00:00
|
|
|
virtual bool Read(u64 offset, u64 size, u8* out_ptr) = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
IBlobReader() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Provides caching and split-operation-to-block-operations facilities.
|
|
|
|
// Used for compressed blob reading and direct drive reading.
|
2009-02-22 16:48:54 +00:00
|
|
|
// Currently only uses a single entry cache.
|
|
|
|
// Multi-block reads are not cached.
|
2008-12-08 04:46:09 +00:00
|
|
|
class SectorReader : public IBlobReader
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
enum { CACHE_SIZE = 32 };
|
|
|
|
int m_blocksize;
|
|
|
|
u8* cache[CACHE_SIZE];
|
|
|
|
u64 cache_tags[CACHE_SIZE];
|
|
|
|
int cache_age[CACHE_SIZE];
|
2009-02-22 16:48:54 +00:00
|
|
|
|
2008-12-08 04:46:09 +00:00
|
|
|
protected:
|
|
|
|
void SetSectorSize(int blocksize);
|
2009-02-22 16:48:54 +00:00
|
|
|
virtual void GetBlock(u64 block_num, u8 *out) = 0;
|
|
|
|
// This one is uncached. The default implementation is to simply call GetBlockData multiple times and memcpy.
|
|
|
|
virtual bool ReadMultipleAlignedBlocks(u64 block_num, u64 num_blocks, u8 *out_ptr);
|
|
|
|
|
2008-12-08 04:46:09 +00:00
|
|
|
public:
|
2009-02-22 16:48:54 +00:00
|
|
|
virtual ~SectorReader();
|
|
|
|
|
|
|
|
// A pointer returned by GetBlockData is invalidated as soon as GetBlockData, Read, or ReadMultipleAlignedBlocks is called again.
|
2008-12-08 04:46:09 +00:00
|
|
|
const u8 *GetBlockData(u64 block_num);
|
2014-03-08 00:54:44 +00:00
|
|
|
virtual bool Read(u64 offset, u64 size, u8 *out_ptr) override;
|
2009-02-22 07:52:02 +00:00
|
|
|
friend class DriveReader;
|
2008-12-08 04:46:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Factory function - examines the path to choose the right type of IBlobReader, and returns one.
|
2009-02-22 16:48:54 +00:00
|
|
|
IBlobReader* CreateBlobReader(const char *filename);
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2009-02-22 16:48:54 +00:00
|
|
|
typedef void (*CompressCB)(const char *text, float percent, void* arg);
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2009-02-22 16:48:54 +00:00
|
|
|
bool CompressFileToBlob(const char *infile, const char *outfile, u32 sub_type = 0, int sector_size = 16384,
|
|
|
|
CompressCB callback = 0, void *arg = 0);
|
|
|
|
bool DecompressBlobToFile(const char *infile, const char *outfile,
|
|
|
|
CompressCB callback = 0, void *arg = 0);
|
2008-12-08 04:46:09 +00:00
|
|
|
|
|
|
|
} // namespace
|