mirror of https://github.com/PCSX2/pcsx2.git
Refactor ISO creation to avoid duplicate code.
This commit is contained in:
parent
334f648eaa
commit
5bfd4c7bf8
|
@ -20,20 +20,6 @@
|
|||
#include "GzippedFileReader.h"
|
||||
|
||||
// CompressedFileReader factory.
|
||||
|
||||
// Go through available compressed readers
|
||||
bool CompressedFileReader::DetectCompressed(AsyncFileReader* pReader) {
|
||||
const wxString& filename = pReader->GetFilename();
|
||||
if (GzippedFileReader::CanHandle(filename)) {
|
||||
return true;
|
||||
}
|
||||
if (CsoFileReader::CanHandle(filename)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Return a new reader which can handle, or any reader otherwise (which will fail on open)
|
||||
AsyncFileReader* CompressedFileReader::GetNewReader(const wxString& fileName) {
|
||||
if (GzippedFileReader::CanHandle(fileName)) {
|
||||
return new GzippedFileReader();
|
||||
|
@ -42,5 +28,5 @@ AsyncFileReader* CompressedFileReader::GetNewReader(const wxString& fileName) {
|
|||
return new CsoFileReader();
|
||||
}
|
||||
// This is the one which will fail on open.
|
||||
return new GzippedFileReader();
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -18,11 +18,8 @@
|
|||
// Factory - creates an AsyncFileReader derived instance which can read a compressed file
|
||||
class CompressedFileReader {
|
||||
public:
|
||||
// Checks if any of the available compressed file handlers can open this
|
||||
static bool DetectCompressed(AsyncFileReader* pReader);
|
||||
|
||||
// fileName is only used to choose the compressed reader.
|
||||
// If no matching handler is found then an arbitrary handlers will be returned.
|
||||
// fileName and its contents may be used to choose the compressed reader.
|
||||
// If no matching handler is found, NULL is returned.
|
||||
// The returned instance still needs ->Open(filename) before usage.
|
||||
// Open(filename) may still fail.
|
||||
static AsyncFileReader* GetNewReader(const wxString& fileName);
|
||||
|
|
|
@ -200,20 +200,34 @@ bool InputIsoFile::Open( const wxString& srcfile, bool testOnly )
|
|||
{
|
||||
Close();
|
||||
m_filename = srcfile;
|
||||
|
||||
// Allow write sharing of the iso based on the ini settings.
|
||||
// Mostly useful for romhacking, where the disc is frequently
|
||||
// changed and the emulator would block modifications
|
||||
m_reader = new FlatFileReader(EmuConfig.CdvdShareWrite);
|
||||
m_reader = NULL;
|
||||
|
||||
bool isBlockdump = false;
|
||||
bool isCompressed = false;
|
||||
|
||||
// First try using a compressed reader. If it works, go with it.
|
||||
m_reader = CompressedFileReader::GetNewReader(m_filename);
|
||||
isCompressed = m_reader != NULL;
|
||||
|
||||
// If it wasn't compressed, let's open it has a FlatFileReader.
|
||||
if (!isCompressed)
|
||||
{
|
||||
// Allow write sharing of the iso based on the ini settings.
|
||||
// Mostly useful for romhacking, where the disc is frequently
|
||||
// changed and the emulator would block modifications
|
||||
m_reader = new FlatFileReader(EmuConfig.CdvdShareWrite);
|
||||
}
|
||||
|
||||
m_reader->Open(m_filename);
|
||||
|
||||
bool isBlockdump, isCompressed = false;
|
||||
if(isBlockdump = BlockdumpFileReader::DetectBlockdump(m_reader))
|
||||
// It might actually be a blockdump file.
|
||||
// Check that before continuing with the FlatFileReader.
|
||||
isBlockdump = BlockdumpFileReader::DetectBlockdump(m_reader);
|
||||
if (isBlockdump)
|
||||
{
|
||||
delete m_reader;
|
||||
|
||||
BlockdumpFileReader *bdr = new BlockdumpFileReader();;
|
||||
|
||||
BlockdumpFileReader *bdr = new BlockdumpFileReader();
|
||||
bdr->Open(m_filename);
|
||||
|
||||
m_blockofs = bdr->GetBlockOffset();
|
||||
|
@ -221,11 +235,7 @@ bool InputIsoFile::Open( const wxString& srcfile, bool testOnly )
|
|||
|
||||
m_reader = bdr;
|
||||
|
||||
ReadUnit = 1;
|
||||
} else if (isCompressed = CompressedFileReader::DetectCompressed(m_reader)) {
|
||||
delete m_reader;
|
||||
m_reader = CompressedFileReader::GetNewReader(m_filename);
|
||||
m_reader->Open(m_filename);
|
||||
ReadUnit = 1;
|
||||
}
|
||||
|
||||
bool detected = Detect();
|
||||
|
|
Loading…
Reference in New Issue