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;
|
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)
|
if (reader->ReadSwapped<u32>(0x18) == WII_DISC_MAGIC)
|
||||||
return std::make_unique<VolumeWii>(std::move(reader));
|
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;
|
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 TryCreateDisc(reader);
|
||||||
return reader ? CreateDisc(reader) : nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
// Check for WAD
|
||||||
// 0x206962 for boot2 wads
|
// 0x206962 for boot2 wads
|
||||||
const std::optional<u32> wad_magic = reader->ReadSwapped<u32>(0x02);
|
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;
|
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 TryCreateWAD(reader);
|
||||||
return reader ? CreateWAD(reader) : nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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));
|
return CreateWAD(CreateBlobReader(path));
|
||||||
if (reader == nullptr)
|
}
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
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)
|
if (disc)
|
||||||
return disc;
|
return disc;
|
||||||
|
|
||||||
std::unique_ptr<VolumeWAD> wad = CreateWAD(reader);
|
std::unique_ptr<VolumeWAD> wad = TryCreateWAD(reader);
|
||||||
if (wad)
|
if (wad)
|
||||||
return wad;
|
return wad;
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<Volume> CreateVolume(const std::string& path)
|
||||||
|
{
|
||||||
|
return CreateVolume(CreateBlobReader(path));
|
||||||
|
}
|
||||||
} // namespace DiscIO
|
} // namespace DiscIO
|
||||||
|
|
|
@ -182,8 +182,11 @@ protected:
|
||||||
static const std::vector<u8> INVALID_CERT_CHAIN;
|
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<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<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);
|
std::unique_ptr<Volume> CreateVolume(const std::string& path);
|
||||||
|
|
||||||
} // namespace DiscIO
|
} // namespace DiscIO
|
||||||
|
|
Loading…
Reference in New Issue