WiiWad: Allow using WiiWad with more than just files

This adds a WiiWad constructor that takes a BlobReader, so that the
class can be used with more than just files from the host filesystem.

Required for using WiiWad with WADs from update partitions.
This commit is contained in:
Léo Lam 2017-07-04 15:37:41 +02:00
parent 5976d3934d
commit ca0438e26d
2 changed files with 11 additions and 13 deletions

View File

@ -44,21 +44,18 @@ bool IsWiiWAD(BlobReader& reader)
} }
} // Anonymous namespace } // Anonymous namespace
WiiWAD::WiiWAD(const std::string& name) : m_reader(CreateBlobReader(name)) WiiWAD::WiiWAD(const std::string& name) : WiiWAD(CreateBlobReader(name))
{
if (m_reader == nullptr)
{
m_valid = false;
return;
}
m_valid = ParseWAD();
}
WiiWAD::~WiiWAD()
{ {
} }
WiiWAD::WiiWAD(std::unique_ptr<BlobReader> blob_reader) : m_reader(std::move(blob_reader))
{
if (m_reader)
m_valid = ParseWAD();
}
WiiWAD::~WiiWAD() = default;
bool WiiWAD::ParseWAD() bool WiiWAD::ParseWAD()
{ {
if (!IsWiiWAD(*m_reader)) if (!IsWiiWAD(*m_reader))

View File

@ -19,6 +19,7 @@ class WiiWAD
{ {
public: public:
explicit WiiWAD(const std::string& name); explicit WiiWAD(const std::string& name);
explicit WiiWAD(std::unique_ptr<BlobReader> blob_reader);
~WiiWAD(); ~WiiWAD();
bool IsValid() const { return m_valid; } bool IsValid() const { return m_valid; }
@ -32,7 +33,7 @@ public:
private: private:
bool ParseWAD(); bool ParseWAD();
bool m_valid; bool m_valid = false;
std::unique_ptr<BlobReader> m_reader; std::unique_ptr<BlobReader> m_reader;