summaryrefslogtreecommitdiff
path: root/Source/Core/DiscIO/Blob.cpp
diff options
context:
space:
mode:
authorMat M <mathew1800@gmail.com>2017-01-11 08:30:16 -0500
committerGitHub <noreply@github.com>2017-01-11 08:30:16 -0500
commit55b82e323cbcf123b0ba78af6089968b66c44481 (patch)
tree7665ced91286df40215dfb43e05774c2dbf96ace /Source/Core/DiscIO/Blob.cpp
parenta3bef102b7f2fd4f41e753509f74355ea7096a33 (diff)
parentb1873264d7c78ea02de16691d26881eb2c4a47e1 (diff)
Merge pull request #4537 from JosJuice/blob-open-less-files
Open less files when detecting/opening blobs
Diffstat (limited to 'Source/Core/DiscIO/Blob.cpp')
-rw-r--r--Source/Core/DiscIO/Blob.cpp37
1 files changed, 23 insertions, 14 deletions
diff --git a/Source/Core/DiscIO/Blob.cpp b/Source/Core/DiscIO/Blob.cpp
index d7aad9332a..7d30cfe212 100644
--- a/Source/Core/DiscIO/Blob.cpp
+++ b/Source/Core/DiscIO/Blob.cpp
@@ -7,6 +7,7 @@
#include <limits>
#include <memory>
#include <string>
+#include <utility>
#include "Common/CDUtils.h"
#include "Common/CommonTypes.h"
@@ -177,23 +178,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))
- return CISOFileReader::Create(filename);
-
- if (IsTGCBlob(filename))
- 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);
+ switch (magic)
+ {
+ case CISO_MAGIC:
+ return CISOFileReader::Create(std::move(file));
+ case GCZ_MAGIC:
+ return CompressedBlobReader::Create(std::move(file), filename);
+ case TGC_MAGIC:
+ return TGCFileReader::Create(std::move(file));
+ case WBFS_MAGIC:
+ return WbfsFileReader::Create(std::move(file), filename);
+ default:
+ return PlainFileReader::Create(std::move(file));
+ }
}
} // namespace