mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-24 14:49:42 -06:00
DiscIO: Add functions CreateDisc and CreateWAD
...in addition to the existing function CreateVolume (renamed from CreateVolumeFromFilename). Lets code easily add constraints such as not letting the user select a WAD file when using the disc changing functionality.
This commit is contained in:
@ -182,10 +182,10 @@ bool CompressFileToBlob(const std::string& infile_path, const std::string& outfi
|
||||
}
|
||||
|
||||
DiscScrubber disc_scrubber;
|
||||
std::unique_ptr<Volume> volume;
|
||||
std::unique_ptr<VolumeDisc> volume;
|
||||
if (sub_type == 1)
|
||||
{
|
||||
volume = CreateVolumeFromFilename(infile_path);
|
||||
volume = CreateDisc(infile_path);
|
||||
if (!volume || !disc_scrubber.SetupScrub(volume.get(), block_size))
|
||||
{
|
||||
PanicAlertT("\"%s\" failed to be scrubbed. Probably the image is corrupt.",
|
||||
|
@ -223,7 +223,7 @@ bool FileInfoGCWii::IsValid(u64 fst_size, const FileInfoGCWii& parent_directory)
|
||||
return true;
|
||||
}
|
||||
|
||||
FileSystemGCWii::FileSystemGCWii(const Volume* volume, const Partition& partition)
|
||||
FileSystemGCWii::FileSystemGCWii(const VolumeDisc* volume, const Partition& partition)
|
||||
: m_valid(false), m_root(nullptr, 0, 0, 0)
|
||||
{
|
||||
u8 offset_shift;
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
namespace DiscIO
|
||||
{
|
||||
class Volume;
|
||||
class VolumeDisc;
|
||||
struct Partition;
|
||||
|
||||
class FileInfoGCWii : public FileInfo
|
||||
@ -87,7 +87,7 @@ private:
|
||||
class FileSystemGCWii : public FileSystem
|
||||
{
|
||||
public:
|
||||
FileSystemGCWii(const Volume* volume, const Partition& partition);
|
||||
FileSystemGCWii(const VolumeDisc* volume, const Partition& partition);
|
||||
~FileSystemGCWii() override;
|
||||
|
||||
bool IsValid() const override { return m_valid; }
|
||||
|
@ -43,23 +43,13 @@ std::map<Language, std::string> Volume::ReadWiiNames(const std::vector<char16_t>
|
||||
return names;
|
||||
}
|
||||
|
||||
std::unique_ptr<Volume> CreateVolumeFromFilename(const std::string& filename)
|
||||
static std::unique_ptr<VolumeDisc> CreateDisc(std::unique_ptr<BlobReader>& reader)
|
||||
{
|
||||
std::unique_ptr<BlobReader> reader(CreateBlobReader(filename));
|
||||
if (reader == nullptr)
|
||||
return nullptr;
|
||||
|
||||
// Check for Wii
|
||||
const std::optional<u32> wii_magic = reader->ReadSwapped<u32>(0x18);
|
||||
if (wii_magic == u32(0x5D1C9EA3))
|
||||
return std::make_unique<VolumeWii>(std::move(reader));
|
||||
|
||||
// Check for WAD
|
||||
// 0x206962 for boot2 wads
|
||||
const std::optional<u32> wad_magic = reader->ReadSwapped<u32>(0x02);
|
||||
if (wad_magic == u32(0x00204973) || wad_magic == u32(0x00206962))
|
||||
return std::make_unique<VolumeWAD>(std::move(reader));
|
||||
|
||||
// Check for GC
|
||||
const std::optional<u32> gc_magic = reader->ReadSwapped<u32>(0x1C);
|
||||
if (gc_magic == u32(0xC2339F3D))
|
||||
@ -69,4 +59,45 @@ std::unique_ptr<Volume> CreateVolumeFromFilename(const std::string& filename)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<VolumeDisc> CreateDisc(const std::string& path)
|
||||
{
|
||||
std::unique_ptr<BlobReader> reader(CreateBlobReader(path));
|
||||
return reader ? CreateDisc(reader) : nullptr;
|
||||
}
|
||||
|
||||
static std::unique_ptr<VolumeWAD> CreateWAD(std::unique_ptr<BlobReader>& reader)
|
||||
{
|
||||
// Check for WAD
|
||||
// 0x206962 for boot2 wads
|
||||
const std::optional<u32> wad_magic = reader->ReadSwapped<u32>(0x02);
|
||||
if (wad_magic == u32(0x00204973) || wad_magic == u32(0x00206962))
|
||||
return std::make_unique<VolumeWAD>(std::move(reader));
|
||||
|
||||
// No known magic words found
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<VolumeWAD> CreateWAD(const std::string& path)
|
||||
{
|
||||
std::unique_ptr<BlobReader> reader(CreateBlobReader(path));
|
||||
return reader ? CreateWAD(reader) : nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<Volume> CreateVolume(const std::string& path)
|
||||
{
|
||||
std::unique_ptr<BlobReader> reader(CreateBlobReader(path));
|
||||
if (reader == nullptr)
|
||||
return nullptr;
|
||||
|
||||
std::unique_ptr<VolumeDisc> disc = CreateDisc(reader);
|
||||
if (disc)
|
||||
return disc;
|
||||
|
||||
std::unique_ptr<VolumeWAD> wad = CreateWAD(reader);
|
||||
if (wad)
|
||||
return wad;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace DiscIO
|
||||
|
@ -22,6 +22,7 @@ namespace DiscIO
|
||||
{
|
||||
enum class BlobType;
|
||||
class FileSystem;
|
||||
class VolumeWAD;
|
||||
|
||||
struct Partition final
|
||||
{
|
||||
@ -141,6 +142,12 @@ protected:
|
||||
static const std::vector<u8> INVALID_CERT_CHAIN;
|
||||
};
|
||||
|
||||
std::unique_ptr<Volume> CreateVolumeFromFilename(const std::string& filename);
|
||||
class VolumeDisc : public Volume
|
||||
{
|
||||
};
|
||||
|
||||
std::unique_ptr<VolumeDisc> CreateDisc(const std::string& path);
|
||||
std::unique_ptr<VolumeWAD> CreateWAD(const std::string& path);
|
||||
std::unique_ptr<Volume> CreateVolume(const std::string& path);
|
||||
|
||||
} // namespace DiscIO
|
||||
|
@ -25,7 +25,7 @@ enum class Language;
|
||||
enum class Region;
|
||||
enum class Platform;
|
||||
|
||||
class VolumeGC : public Volume
|
||||
class VolumeGC : public VolumeDisc
|
||||
{
|
||||
public:
|
||||
VolumeGC(std::unique_ptr<BlobReader> reader);
|
||||
|
@ -27,7 +27,7 @@ enum class Language;
|
||||
enum class Region;
|
||||
enum class Platform;
|
||||
|
||||
class VolumeWii : public Volume
|
||||
class VolumeWii : public VolumeDisc
|
||||
{
|
||||
public:
|
||||
VolumeWii(std::unique_ptr<BlobReader> reader);
|
||||
|
Reference in New Issue
Block a user