2008-09-17 23:25:35 +00:00
|
|
|
// Copyright (C) 2003-2008 Dolphin Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0.
|
2008-07-12 17:40:22 +00:00
|
|
|
|
2008-09-17 23:25:35 +00:00
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
2008-07-12 17:40:22 +00:00
|
|
|
|
2008-09-17 23:25:35 +00:00
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
2008-07-12 17:40:22 +00:00
|
|
|
|
2008-09-17 23:25:35 +00:00
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
2008-07-12 17:40:22 +00:00
|
|
|
|
2008-09-17 23:25:35 +00:00
|
|
|
#ifndef _BLOB_H
|
|
|
|
#define _BLOB_H
|
2008-07-12 17:40:22 +00:00
|
|
|
|
2008-09-17 23:25:35 +00:00
|
|
|
// BLOB
|
2008-07-12 17:40:22 +00:00
|
|
|
|
2008-09-17 23:25:35 +00:00
|
|
|
// 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
|
|
|
|
// detect whether the file is a compressed blob, or just a big hunk of data, and
|
|
|
|
// automatically do the right thing.
|
2008-07-12 17:40:22 +00:00
|
|
|
|
|
|
|
#include "Common.h"
|
|
|
|
|
|
|
|
namespace DiscIO
|
|
|
|
{
|
2008-09-17 23:25:35 +00:00
|
|
|
|
2008-07-12 17:40:22 +00:00
|
|
|
class IBlobReader
|
|
|
|
{
|
2008-09-17 23:25:35 +00:00
|
|
|
public:
|
|
|
|
virtual ~IBlobReader() {}
|
2008-07-12 17:40:22 +00:00
|
|
|
|
2008-09-17 23:25:35 +00:00
|
|
|
virtual u64 GetRawSize() const = 0;
|
|
|
|
virtual u64 GetDataSize() const = 0;
|
|
|
|
virtual bool Read(u64 offset, u64 size, u8* out_ptr) = 0;
|
2008-07-12 17:40:22 +00:00
|
|
|
|
2008-09-17 23:25:35 +00:00
|
|
|
protected:
|
|
|
|
IBlobReader() {}
|
|
|
|
};
|
2008-07-12 17:40:22 +00:00
|
|
|
|
|
|
|
|
2008-09-17 23:25:35 +00:00
|
|
|
// Provides caching and split-operation-to-block-operations facilities.
|
|
|
|
// Used for compressed blob reading and direct drive reading.
|
|
|
|
class SectorReader : public IBlobReader
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
virtual void GetBlock(u64 block_num, u8 *out) = 0;
|
|
|
|
enum { CACHE_SIZE = 32 };
|
|
|
|
int m_blocksize;
|
|
|
|
u8* cache[CACHE_SIZE];
|
|
|
|
u64 cache_tags[CACHE_SIZE];
|
|
|
|
int cache_age[CACHE_SIZE];
|
|
|
|
protected:
|
|
|
|
void SetSectorSize(int blocksize);
|
|
|
|
public:
|
|
|
|
~SectorReader();
|
|
|
|
const u8 *GetBlockData(u64 block_num);
|
|
|
|
bool Read(u64 offset, u64 size, u8* out_ptr);
|
2008-07-12 17:40:22 +00:00
|
|
|
};
|
|
|
|
|
2008-09-17 23:25:35 +00:00
|
|
|
// Factory function - examines the path to choose the right type of IBlobReader, and returns one.
|
2008-07-12 17:40:22 +00:00
|
|
|
IBlobReader* CreateBlobReader(const char* filename);
|
|
|
|
|
|
|
|
typedef void (*CompressCB)(const char* text, float percent, void* arg);
|
|
|
|
|
|
|
|
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-09-17 23:25:35 +00:00
|
|
|
|
|
|
|
} // namespace
|
2008-07-12 17:40:22 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|