DiscIO: Add CreateDisc/WAD/Volume() overloads that take a BlobReader directly.
This commit is contained in:
parent
e3f1de023f
commit
09fc39e2e5
|
@ -85,8 +85,11 @@ std::map<Language, std::string> Volume::ReadWiiNames(const std::vector<char16_t>
|
|||
return names;
|
||||
}
|
||||
|
||||
static std::unique_ptr<VolumeDisc> CreateDisc(std::unique_ptr<BlobReader>& reader)
|
||||
static std::unique_ptr<VolumeDisc> TryCreateDisc(std::unique_ptr<BlobReader>& reader)
|
||||
{
|
||||
if (!reader)
|
||||
return nullptr;
|
||||
|
||||
if (reader->ReadSwapped<u32>(0x18) == WII_DISC_MAGIC)
|
||||
return std::make_unique<VolumeWii>(std::move(reader));
|
||||
|
||||
|
@ -97,14 +100,21 @@ static std::unique_ptr<VolumeDisc> CreateDisc(std::unique_ptr<BlobReader>& reade
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<VolumeDisc> CreateDisc(const std::string& path)
|
||||
std::unique_ptr<VolumeDisc> CreateDisc(std::unique_ptr<BlobReader> reader)
|
||||
{
|
||||
std::unique_ptr<BlobReader> reader(CreateBlobReader(path));
|
||||
return reader ? CreateDisc(reader) : nullptr;
|
||||
return TryCreateDisc(reader);
|
||||
}
|
||||
|
||||
static std::unique_ptr<VolumeWAD> CreateWAD(std::unique_ptr<BlobReader>& reader)
|
||||
std::unique_ptr<VolumeDisc> CreateDisc(const std::string& path)
|
||||
{
|
||||
return CreateDisc(CreateBlobReader(path));
|
||||
}
|
||||
|
||||
static std::unique_ptr<VolumeWAD> TryCreateWAD(std::unique_ptr<BlobReader>& reader)
|
||||
{
|
||||
if (!reader)
|
||||
return nullptr;
|
||||
|
||||
// Check for WAD
|
||||
// 0x206962 for boot2 wads
|
||||
const std::optional<u32> wad_magic = reader->ReadSwapped<u32>(0x02);
|
||||
|
@ -115,27 +125,31 @@ static std::unique_ptr<VolumeWAD> CreateWAD(std::unique_ptr<BlobReader>& reader)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<VolumeWAD> CreateWAD(const std::string& path)
|
||||
std::unique_ptr<VolumeWAD> CreateWAD(std::unique_ptr<BlobReader> reader)
|
||||
{
|
||||
std::unique_ptr<BlobReader> reader(CreateBlobReader(path));
|
||||
return reader ? CreateWAD(reader) : nullptr;
|
||||
return TryCreateWAD(reader);
|
||||
}
|
||||
|
||||
std::unique_ptr<Volume> CreateVolume(const std::string& path)
|
||||
std::unique_ptr<VolumeWAD> CreateWAD(const std::string& path)
|
||||
{
|
||||
std::unique_ptr<BlobReader> reader(CreateBlobReader(path));
|
||||
if (reader == nullptr)
|
||||
return nullptr;
|
||||
return CreateWAD(CreateBlobReader(path));
|
||||
}
|
||||
|
||||
std::unique_ptr<VolumeDisc> disc = CreateDisc(reader);
|
||||
std::unique_ptr<Volume> CreateVolume(std::unique_ptr<BlobReader> reader)
|
||||
{
|
||||
std::unique_ptr<VolumeDisc> disc = TryCreateDisc(reader);
|
||||
if (disc)
|
||||
return disc;
|
||||
|
||||
std::unique_ptr<VolumeWAD> wad = CreateWAD(reader);
|
||||
std::unique_ptr<VolumeWAD> wad = TryCreateWAD(reader);
|
||||
if (wad)
|
||||
return wad;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<Volume> CreateVolume(const std::string& path)
|
||||
{
|
||||
return CreateVolume(CreateBlobReader(path));
|
||||
}
|
||||
} // namespace DiscIO
|
||||
|
|
|
@ -182,8 +182,11 @@ protected:
|
|||
static const std::vector<u8> INVALID_CERT_CHAIN;
|
||||
};
|
||||
|
||||
std::unique_ptr<VolumeDisc> CreateDisc(std::unique_ptr<BlobReader> reader);
|
||||
std::unique_ptr<VolumeDisc> CreateDisc(const std::string& path);
|
||||
std::unique_ptr<VolumeWAD> CreateWAD(std::unique_ptr<BlobReader> reader);
|
||||
std::unique_ptr<VolumeWAD> CreateWAD(const std::string& path);
|
||||
std::unique_ptr<Volume> CreateVolume(std::unique_ptr<BlobReader> reader);
|
||||
std::unique_ptr<Volume> CreateVolume(const std::string& path);
|
||||
|
||||
} // namespace DiscIO
|
||||
|
|
Loading…
Reference in New Issue