mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
Only open file once when detecting blob type
This commit is contained in:
@ -177,23 +177,31 @@ std::unique_ptr<IBlobReader> CreateBlobReader(const std::string& filename)
|
||||
if (cdio_is_cdrom(filename))
|
||||
return DriveReader::Create(filename);
|
||||
|
||||
if (!File::Exists(filename))
|
||||
File::IOFile file(filename, "rb");
|
||||
u32 magic;
|
||||
if (!file.ReadArray(&magic, 1))
|
||||
return nullptr;
|
||||
|
||||
if (IsWbfsBlob(filename))
|
||||
return WbfsFileReader::Create(filename);
|
||||
// Conveniently, every supported file format (except for plain disc images) starts
|
||||
// with a 4-byte magic number that identifies the format, so we just need a simple
|
||||
// switch statement to create the right blob type. If the magic number doesn't
|
||||
// match any known magic number, we assume it's a plain disc image. If that
|
||||
// assumption is wrong, the volume code that runs later will notice the error
|
||||
// because the blob won't provide valid data when reading the GC/Wii disc header.
|
||||
|
||||
if (IsGCZBlob(filename))
|
||||
return CompressedBlobReader::Create(filename);
|
||||
|
||||
if (IsCISOBlob(filename))
|
||||
switch (magic)
|
||||
{
|
||||
case CISO_MAGIC:
|
||||
return CISOFileReader::Create(filename);
|
||||
|
||||
if (IsTGCBlob(filename))
|
||||
case GCZ_MAGIC:
|
||||
return CompressedBlobReader::Create(filename);
|
||||
case TGC_MAGIC:
|
||||
return TGCFileReader::Create(filename);
|
||||
|
||||
// Still here? Assume plain file - since we know it exists due to the File::Exists check above.
|
||||
return PlainFileReader::Create(filename);
|
||||
case WBFS_MAGIC:
|
||||
return WbfsFileReader::Create(filename);
|
||||
default:
|
||||
return PlainFileReader::Create(filename);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
Reference in New Issue
Block a user