mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-30 01:29:42 -06:00
DiscIO: Make factory methods return unique_ptrs
Rather than rely on the developer to do the right thing, just make the default behavior safely deallocate resources. If shared semantics are ever needed in the future, the constructor that takes a unique_ptr for shared_ptr can be used.
This commit is contained in:
@ -4,6 +4,7 @@
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "Common/CDUtils.h"
|
||||
@ -114,7 +115,7 @@ bool SectorReader::ReadMultipleAlignedBlocks(u64 block_num, u64 num_blocks, u8 *
|
||||
return true;
|
||||
}
|
||||
|
||||
IBlobReader* CreateBlobReader(const std::string& filename)
|
||||
std::unique_ptr<IBlobReader> CreateBlobReader(const std::string& filename)
|
||||
{
|
||||
if (cdio_is_cdrom(filename))
|
||||
return DriveReader::Create(filename);
|
||||
|
@ -14,6 +14,7 @@
|
||||
// detect whether the file is a compressed blob, or just a big hunk of data, or a drive, and
|
||||
// automatically do the right thing.
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "Common/CommonTypes.h"
|
||||
|
||||
@ -75,7 +76,7 @@ private:
|
||||
};
|
||||
|
||||
// Factory function - examines the path to choose the right type of IBlobReader, and returns one.
|
||||
IBlobReader* CreateBlobReader(const std::string& filename);
|
||||
std::unique_ptr<IBlobReader> CreateBlobReader(const std::string& filename);
|
||||
|
||||
typedef bool (*CompressCB)(const std::string& text, float percent, void* arg);
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <memory>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/FileUtil.h"
|
||||
@ -29,17 +30,15 @@ CISOFileReader::CISOFileReader(std::FILE* file)
|
||||
m_ciso_map[idx] = (1 == header.map[idx]) ? count++ : UNUSED_BLOCK_ID;
|
||||
}
|
||||
|
||||
CISOFileReader* CISOFileReader::Create(const std::string& filename)
|
||||
std::unique_ptr<CISOFileReader> CISOFileReader::Create(const std::string& filename)
|
||||
{
|
||||
if (IsCISOBlob(filename))
|
||||
{
|
||||
File::IOFile f(filename, "rb");
|
||||
return new CISOFileReader(f.ReleaseHandle());
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
return std::unique_ptr<CISOFileReader>(new CISOFileReader(f.ReleaseHandle()));
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
u64 CISOFileReader::GetDataSize() const
|
||||
|
@ -5,6 +5,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdio>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
@ -34,7 +35,7 @@ struct CISOHeader
|
||||
class CISOFileReader : public IBlobReader
|
||||
{
|
||||
public:
|
||||
static CISOFileReader* Create(const std::string& filename);
|
||||
static std::unique_ptr<CISOFileReader> Create(const std::string& filename);
|
||||
|
||||
BlobType GetBlobType() const override { return BlobType::CISO; }
|
||||
|
||||
|
@ -55,12 +55,12 @@ CompressedBlobReader::CompressedBlobReader(const std::string& filename) : m_file
|
||||
memset(m_zlib_buffer, 0, m_zlib_buffer_size);
|
||||
}
|
||||
|
||||
CompressedBlobReader* CompressedBlobReader::Create(const std::string& filename)
|
||||
std::unique_ptr<CompressedBlobReader> CompressedBlobReader::Create(const std::string& filename)
|
||||
{
|
||||
if (IsGCZBlob(filename))
|
||||
return new CompressedBlobReader(filename);
|
||||
else
|
||||
return nullptr;
|
||||
return std::unique_ptr<CompressedBlobReader>(new CompressedBlobReader(filename));
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
CompressedBlobReader::~CompressedBlobReader()
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
@ -46,7 +47,7 @@ struct CompressedBlobHeader // 32 bytes
|
||||
class CompressedBlobReader : public SectorReader
|
||||
{
|
||||
public:
|
||||
static CompressedBlobReader* Create(const std::string& filename);
|
||||
static std::unique_ptr<CompressedBlobReader> Create(const std::string& filename);
|
||||
~CompressedBlobReader();
|
||||
const CompressedBlobHeader &GetHeader() const { return m_header; }
|
||||
BlobType GetBlobType() const override { return BlobType::GCZ; }
|
||||
|
@ -34,7 +34,7 @@ static int m_BlocksPerCluster;
|
||||
static bool m_isScrubbing = false;
|
||||
|
||||
static std::string m_Filename;
|
||||
static IVolume* m_Disc = nullptr;
|
||||
static std::unique_ptr<IVolume> s_disc;
|
||||
|
||||
struct SPartitionHeader
|
||||
{
|
||||
@ -94,11 +94,11 @@ bool SetupScrub(const std::string& filename, int block_size)
|
||||
|
||||
m_BlocksPerCluster = CLUSTER_SIZE / m_BlockSize;
|
||||
|
||||
m_Disc = CreateVolumeFromFilename(filename);
|
||||
if (!m_Disc)
|
||||
s_disc = CreateVolumeFromFilename(filename);
|
||||
if (!s_disc)
|
||||
return false;
|
||||
|
||||
m_FileSize = m_Disc->GetSize();
|
||||
m_FileSize = s_disc->GetSize();
|
||||
|
||||
u32 numClusters = (u32)(m_FileSize / CLUSTER_SIZE);
|
||||
|
||||
@ -112,9 +112,9 @@ bool SetupScrub(const std::string& filename, int block_size)
|
||||
|
||||
// Fill out table of free blocks
|
||||
success = ParseDisc();
|
||||
|
||||
// Done with it; need it closed for the next part
|
||||
delete m_Disc;
|
||||
m_Disc = nullptr;
|
||||
s_disc.reset();
|
||||
m_BlockCount = 0;
|
||||
|
||||
// Let's not touch the file if we've failed up to here :p
|
||||
@ -194,12 +194,12 @@ void MarkAsUsedE(u64 _PartitionDataOffset, u64 _Offset, u64 _Size)
|
||||
// Helper functions for reading the BE volume
|
||||
void ReadFromVolume(u64 _Offset, u32& _Buffer, bool _Decrypt)
|
||||
{
|
||||
m_Disc->Read(_Offset, sizeof(u32), (u8*)&_Buffer, _Decrypt);
|
||||
s_disc->Read(_Offset, sizeof(u32), (u8*)&_Buffer, _Decrypt);
|
||||
_Buffer = Common::swap32(_Buffer);
|
||||
}
|
||||
void ReadFromVolume(u64 _Offset, u64& _Buffer, bool _Decrypt)
|
||||
{
|
||||
m_Disc->Read(_Offset, sizeof(u32), (u8*)&_Buffer, _Decrypt);
|
||||
s_disc->Read(_Offset, sizeof(u32), (u8*)&_Buffer, _Decrypt);
|
||||
_Buffer = Common::swap32((u32)_Buffer);
|
||||
_Buffer <<= 2;
|
||||
}
|
||||
@ -259,71 +259,71 @@ bool ParseDisc()
|
||||
}
|
||||
|
||||
// Operations dealing with encrypted space are done here - the volume is swapped to allow this
|
||||
bool ParsePartitionData(SPartition& _rPartition)
|
||||
bool ParsePartitionData(SPartition& partition)
|
||||
{
|
||||
bool ParsedOK = true;
|
||||
bool parsed_ok = true;
|
||||
|
||||
// Switch out the main volume temporarily
|
||||
IVolume *OldVolume = m_Disc;
|
||||
std::unique_ptr<IVolume> old_volume;
|
||||
s_disc.swap(old_volume);
|
||||
|
||||
// Ready some stuff
|
||||
m_Disc = CreateVolumeFromFilename(m_Filename, _rPartition.GroupNumber, _rPartition.Number);
|
||||
if (m_Disc == nullptr)
|
||||
s_disc = CreateVolumeFromFilename(m_Filename, partition.GroupNumber, partition.Number);
|
||||
if (s_disc == nullptr)
|
||||
{
|
||||
ERROR_LOG(DISCIO, "Failed to create volume from file %s", m_Filename.c_str());
|
||||
m_Disc = OldVolume;
|
||||
s_disc.swap(old_volume);
|
||||
return false;
|
||||
}
|
||||
|
||||
std::unique_ptr<IFileSystem> filesystem(CreateFileSystem(m_Disc));
|
||||
std::unique_ptr<IFileSystem> filesystem(CreateFileSystem(s_disc.get()));
|
||||
if (!filesystem)
|
||||
{
|
||||
ERROR_LOG(DISCIO, "Failed to create filesystem for group %d partition %u", _rPartition.GroupNumber, _rPartition.Number);
|
||||
ParsedOK = false;
|
||||
ERROR_LOG(DISCIO, "Failed to create filesystem for group %d partition %u", partition.GroupNumber, partition.Number);
|
||||
parsed_ok = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Mark things as used which are not in the filesystem
|
||||
// Header, Header Information, Apploader
|
||||
ReadFromVolume(0x2440 + 0x14, _rPartition.Header.ApploaderSize, true);
|
||||
ReadFromVolume(0x2440 + 0x18, _rPartition.Header.ApploaderTrailerSize, true);
|
||||
MarkAsUsedE(_rPartition.Offset
|
||||
+ _rPartition.Header.DataOffset
|
||||
ReadFromVolume(0x2440 + 0x14, partition.Header.ApploaderSize, true);
|
||||
ReadFromVolume(0x2440 + 0x18, partition.Header.ApploaderTrailerSize, true);
|
||||
MarkAsUsedE(partition.Offset
|
||||
+ partition.Header.DataOffset
|
||||
, 0
|
||||
, 0x2440
|
||||
+ _rPartition.Header.ApploaderSize
|
||||
+ _rPartition.Header.ApploaderTrailerSize);
|
||||
+ partition.Header.ApploaderSize
|
||||
+ partition.Header.ApploaderTrailerSize);
|
||||
|
||||
// DOL
|
||||
ReadFromVolume(0x420, _rPartition.Header.DOLOffset, true);
|
||||
_rPartition.Header.DOLSize = filesystem->GetBootDOLSize(_rPartition.Header.DOLOffset);
|
||||
MarkAsUsedE(_rPartition.Offset
|
||||
+ _rPartition.Header.DataOffset
|
||||
, _rPartition.Header.DOLOffset
|
||||
, _rPartition.Header.DOLSize);
|
||||
ReadFromVolume(0x420, partition.Header.DOLOffset, true);
|
||||
partition.Header.DOLSize = filesystem->GetBootDOLSize(partition.Header.DOLOffset);
|
||||
MarkAsUsedE(partition.Offset
|
||||
+ partition.Header.DataOffset
|
||||
, partition.Header.DOLOffset
|
||||
, partition.Header.DOLSize);
|
||||
|
||||
// FST
|
||||
ReadFromVolume(0x424, _rPartition.Header.FSTOffset, true);
|
||||
ReadFromVolume(0x428, _rPartition.Header.FSTSize, true);
|
||||
MarkAsUsedE(_rPartition.Offset
|
||||
+ _rPartition.Header.DataOffset
|
||||
, _rPartition.Header.FSTOffset
|
||||
, _rPartition.Header.FSTSize);
|
||||
ReadFromVolume(0x424, partition.Header.FSTOffset, true);
|
||||
ReadFromVolume(0x428, partition.Header.FSTSize, true);
|
||||
MarkAsUsedE(partition.Offset
|
||||
+ partition.Header.DataOffset
|
||||
, partition.Header.FSTOffset
|
||||
, partition.Header.FSTSize);
|
||||
|
||||
// Go through the filesystem and mark entries as used
|
||||
for (SFileInfo file : filesystem->GetFileList())
|
||||
{
|
||||
DEBUG_LOG(DISCIO, "%s", file.m_FullPath.empty() ? "/" : file.m_FullPath.c_str());
|
||||
if ((file.m_NameOffset & 0x1000000) == 0)
|
||||
MarkAsUsedE(_rPartition.Offset + _rPartition.Header.DataOffset, file.m_Offset, file.m_FileSize);
|
||||
MarkAsUsedE(partition.Offset + partition.Header.DataOffset, file.m_Offset, file.m_FileSize);
|
||||
}
|
||||
}
|
||||
|
||||
// Swap back
|
||||
delete m_Disc;
|
||||
m_Disc = OldVolume;
|
||||
s_disc.swap(old_volume);
|
||||
|
||||
return ParsedOK;
|
||||
return parsed_ok;
|
||||
}
|
||||
|
||||
} // namespace DiscScrubber
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
@ -84,15 +85,12 @@ DriveReader::~DriveReader()
|
||||
#endif
|
||||
}
|
||||
|
||||
DriveReader* DriveReader::Create(const std::string& drive)
|
||||
std::unique_ptr<DriveReader> DriveReader::Create(const std::string& drive)
|
||||
{
|
||||
DriveReader* reader = new DriveReader(drive);
|
||||
auto reader = std::unique_ptr<DriveReader>(new DriveReader(drive));
|
||||
|
||||
if (!reader->IsOK())
|
||||
{
|
||||
delete reader;
|
||||
return nullptr;
|
||||
}
|
||||
reader.reset();
|
||||
|
||||
return reader;
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
@ -21,7 +22,7 @@ namespace DiscIO
|
||||
class DriveReader : public SectorReader
|
||||
{
|
||||
public:
|
||||
static DriveReader* Create(const std::string& drive);
|
||||
static std::unique_ptr<DriveReader> Create(const std::string& drive);
|
||||
~DriveReader();
|
||||
BlobType GetBlobType() const override { return BlobType::DRIVE; }
|
||||
u64 GetDataSize() const override { return m_size; }
|
||||
|
@ -2,6 +2,7 @@
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "DiscIO/FileBlob.h"
|
||||
|
||||
@ -14,13 +15,13 @@ PlainFileReader::PlainFileReader(std::FILE* file)
|
||||
m_size = m_file.GetSize();
|
||||
}
|
||||
|
||||
PlainFileReader* PlainFileReader::Create(const std::string& filename)
|
||||
std::unique_ptr<PlainFileReader> PlainFileReader::Create(const std::string& filename)
|
||||
{
|
||||
File::IOFile f(filename, "rb");
|
||||
if (f)
|
||||
return new PlainFileReader(f.ReleaseHandle());
|
||||
else
|
||||
return nullptr;
|
||||
return std::unique_ptr<PlainFileReader>(new PlainFileReader(f.ReleaseHandle()));
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool PlainFileReader::Read(u64 offset, u64 nbytes, u8* out_ptr)
|
||||
|
@ -5,6 +5,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdio>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
@ -17,7 +18,7 @@ namespace DiscIO
|
||||
class PlainFileReader : public IBlobReader
|
||||
{
|
||||
public:
|
||||
static PlainFileReader* Create(const std::string& filename);
|
||||
static std::unique_ptr<PlainFileReader> Create(const std::string& filename);
|
||||
|
||||
BlobType GetBlobType() const override { return BlobType::PLAIN; }
|
||||
u64 GetDataSize() const override { return m_size; }
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
@ -25,8 +26,8 @@
|
||||
namespace FileMon
|
||||
{
|
||||
|
||||
static DiscIO::IVolume *OpenISO = nullptr;
|
||||
static DiscIO::IFileSystem *pFileSystem = nullptr;
|
||||
static std::unique_ptr<DiscIO::IVolume> s_open_iso;
|
||||
static std::unique_ptr<DiscIO::IFileSystem> s_filesystem;
|
||||
static std::string ISOFile = "", CurrentFile = "";
|
||||
static bool FileAccess = true;
|
||||
|
||||
@ -61,26 +62,18 @@ bool IsSoundFile(const std::string& filename)
|
||||
void ReadFileSystem(const std::string& filename)
|
||||
{
|
||||
// Should have an actual Shutdown procedure or something
|
||||
if (OpenISO != nullptr)
|
||||
{
|
||||
delete OpenISO;
|
||||
OpenISO = nullptr;
|
||||
}
|
||||
if (pFileSystem != nullptr)
|
||||
{
|
||||
delete pFileSystem;
|
||||
pFileSystem = nullptr;
|
||||
}
|
||||
s_open_iso.reset();
|
||||
s_filesystem.reset();
|
||||
|
||||
OpenISO = DiscIO::CreateVolumeFromFilename(filename);
|
||||
if (!OpenISO)
|
||||
s_open_iso = DiscIO::CreateVolumeFromFilename(filename);
|
||||
if (!s_open_iso)
|
||||
return;
|
||||
|
||||
if (OpenISO->GetVolumeType() != DiscIO::IVolume::WII_WAD)
|
||||
if (s_open_iso->GetVolumeType() != DiscIO::IVolume::WII_WAD)
|
||||
{
|
||||
pFileSystem = DiscIO::CreateFileSystem(OpenISO);
|
||||
s_filesystem = DiscIO::CreateFileSystem(s_open_iso.get());
|
||||
|
||||
if (!pFileSystem)
|
||||
if (!s_filesystem)
|
||||
return;
|
||||
}
|
||||
|
||||
@ -130,7 +123,7 @@ void FindFilename(u64 offset)
|
||||
if (!FileAccess)
|
||||
return;
|
||||
|
||||
if (!pFileSystem || ISOFile != SConfig::GetInstance().m_LastFilename)
|
||||
if (!s_filesystem || ISOFile != SConfig::GetInstance().m_LastFilename)
|
||||
{
|
||||
FileAccess = false;
|
||||
ReadFileSystem(SConfig::GetInstance().m_LastFilename);
|
||||
@ -139,27 +132,18 @@ void FindFilename(u64 offset)
|
||||
return;
|
||||
}
|
||||
|
||||
const std::string filename = pFileSystem->GetFileName(offset);
|
||||
const std::string filename = s_filesystem->GetFileName(offset);
|
||||
|
||||
if (filename.empty())
|
||||
return;
|
||||
|
||||
CheckFile(filename, pFileSystem->GetFileSize(filename));
|
||||
CheckFile(filename, s_filesystem->GetFileSize(filename));
|
||||
}
|
||||
|
||||
void Close()
|
||||
{
|
||||
if (OpenISO != nullptr)
|
||||
{
|
||||
delete OpenISO;
|
||||
OpenISO = nullptr;
|
||||
}
|
||||
|
||||
if (pFileSystem != nullptr)
|
||||
{
|
||||
delete pFileSystem;
|
||||
pFileSystem = nullptr;
|
||||
}
|
||||
s_open_iso.reset();
|
||||
s_filesystem.reset();
|
||||
|
||||
ISOFile = "";
|
||||
CurrentFile = "";
|
||||
|
@ -2,6 +2,7 @@
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <memory>
|
||||
#include "DiscIO/Filesystem.h"
|
||||
#include "DiscIO/FileSystemGCWii.h"
|
||||
|
||||
@ -17,20 +18,17 @@ IFileSystem::~IFileSystem()
|
||||
{}
|
||||
|
||||
|
||||
IFileSystem* CreateFileSystem(const IVolume* _rVolume)
|
||||
std::unique_ptr<IFileSystem> CreateFileSystem(const IVolume* volume)
|
||||
{
|
||||
IFileSystem* pFileSystem = new CFileSystemGCWii(_rVolume);
|
||||
std::unique_ptr<IFileSystem> filesystem = std::make_unique<CFileSystemGCWii>(volume);
|
||||
|
||||
if (!pFileSystem)
|
||||
if (!filesystem)
|
||||
return nullptr;
|
||||
|
||||
if (!pFileSystem->IsValid())
|
||||
{
|
||||
delete pFileSystem;
|
||||
pFileSystem = nullptr;
|
||||
}
|
||||
if (!filesystem->IsValid())
|
||||
filesystem.reset();
|
||||
|
||||
return pFileSystem;
|
||||
return filesystem;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
@ -4,8 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@ -57,6 +56,6 @@ protected:
|
||||
const IVolume *m_rVolume;
|
||||
};
|
||||
|
||||
IFileSystem* CreateFileSystem(const IVolume *_rVolume);
|
||||
std::unique_ptr<IFileSystem> CreateFileSystem(const IVolume* volume);
|
||||
|
||||
} // namespace
|
||||
|
@ -71,12 +71,12 @@ static const unsigned char s_master_key_korean[16] = {
|
||||
0x13,0xf2,0xfe,0xfb,0xba,0x4c,0x9b,0x7e
|
||||
};
|
||||
|
||||
static IVolume* CreateVolumeFromCryptedWiiImage(std::unique_ptr<IBlobReader> reader, u32 _PartitionGroup, u32 _VolumeType, u32 _VolumeNum);
|
||||
static std::unique_ptr<IVolume> CreateVolumeFromCryptedWiiImage(std::unique_ptr<IBlobReader> reader, u32 partition_group, u32 volume_type, u32 volume_number);
|
||||
EDiscType GetDiscType(IBlobReader& _rReader);
|
||||
|
||||
IVolume* CreateVolumeFromFilename(const std::string& _rFilename, u32 _PartitionGroup, u32 _VolumeNum)
|
||||
std::unique_ptr<IVolume> CreateVolumeFromFilename(const std::string& filename, u32 partition_group, u32 volume_number)
|
||||
{
|
||||
std::unique_ptr<IBlobReader> reader(CreateBlobReader(_rFilename));
|
||||
std::unique_ptr<IBlobReader> reader(CreateBlobReader(filename));
|
||||
if (reader == nullptr)
|
||||
return nullptr;
|
||||
|
||||
@ -84,30 +84,30 @@ IVolume* CreateVolumeFromFilename(const std::string& _rFilename, u32 _PartitionG
|
||||
{
|
||||
case DISC_TYPE_WII:
|
||||
case DISC_TYPE_GC:
|
||||
return new CVolumeGC(std::move(reader));
|
||||
return std::make_unique<CVolumeGC>(std::move(reader));
|
||||
|
||||
case DISC_TYPE_WAD:
|
||||
return new CVolumeWAD(std::move(reader));
|
||||
return std::make_unique<CVolumeWAD>(std::move(reader));
|
||||
|
||||
case DISC_TYPE_WII_CONTAINER:
|
||||
return CreateVolumeFromCryptedWiiImage(std::move(reader), _PartitionGroup, 0, _VolumeNum);
|
||||
return CreateVolumeFromCryptedWiiImage(std::move(reader), partition_group, 0, volume_number);
|
||||
|
||||
case DISC_TYPE_UNK:
|
||||
default:
|
||||
std::string Filename, ext;
|
||||
SplitPath(_rFilename, nullptr, &Filename, &ext);
|
||||
Filename += ext;
|
||||
std::string name, extension;
|
||||
SplitPath(filename, nullptr, &name, &extension);
|
||||
name += extension;
|
||||
NOTICE_LOG(DISCIO, "%s does not have the Magic word for a gcm, wiidisc or wad file\n"
|
||||
"Set Log Verbosity to Warning and attempt to load the game again to view the values", Filename.c_str());
|
||||
"Set Log Verbosity to Warning and attempt to load the game again to view the values", name.c_str());
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
IVolume* CreateVolumeFromDirectory(const std::string& _rDirectory, bool _bIsWii, const std::string& _rApploader, const std::string& _rDOL)
|
||||
std::unique_ptr<IVolume> CreateVolumeFromDirectory(const std::string& directory, bool is_wii, const std::string& apploader, const std::string& dol)
|
||||
{
|
||||
if (CVolumeDirectory::IsValidDirectory(_rDirectory))
|
||||
return new CVolumeDirectory(_rDirectory, _bIsWii, _rApploader, _rDOL);
|
||||
if (CVolumeDirectory::IsValidDirectory(directory))
|
||||
return std::make_unique<CVolumeDirectory>(directory, is_wii, apploader, dol);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
@ -137,55 +137,55 @@ void VolumeKeyForPartition(IBlobReader& _rReader, u64 offset, u8* VolumeKey)
|
||||
mbedtls_aes_crypt_cbc(&AES_ctx, MBEDTLS_AES_DECRYPT, 16, IV, SubKey, VolumeKey);
|
||||
}
|
||||
|
||||
static IVolume* CreateVolumeFromCryptedWiiImage(std::unique_ptr<IBlobReader> reader, u32 _PartitionGroup, u32 _VolumeType, u32 _VolumeNum)
|
||||
static std::unique_ptr<IVolume> CreateVolumeFromCryptedWiiImage(std::unique_ptr<IBlobReader> reader, u32 partition_group, u32 volume_type, u32 volume_number)
|
||||
{
|
||||
CBlobBigEndianReader big_endian_reader(*reader);
|
||||
|
||||
u32 numPartitions = big_endian_reader.Read32(0x40000 + (_PartitionGroup * 8));
|
||||
u64 PartitionsOffset = (u64)big_endian_reader.Read32(0x40000 + (_PartitionGroup * 8) + 4) << 2;
|
||||
u32 numPartitions = big_endian_reader.Read32(0x40000 + (partition_group * 8));
|
||||
u64 PartitionsOffset = (u64)big_endian_reader.Read32(0x40000 + (partition_group * 8) + 4) << 2;
|
||||
|
||||
// Check if we're looking for a valid partition
|
||||
if ((int)_VolumeNum != -1 && _VolumeNum > numPartitions)
|
||||
if ((int)volume_number != -1 && volume_number > numPartitions)
|
||||
return nullptr;
|
||||
|
||||
struct SPartition
|
||||
{
|
||||
u64 Offset;
|
||||
u32 Type;
|
||||
u64 offset;
|
||||
u32 type;
|
||||
};
|
||||
|
||||
struct SPartitionGroup
|
||||
{
|
||||
u32 numPartitions;
|
||||
u64 PartitionsOffset;
|
||||
std::vector<SPartition> PartitionsVec;
|
||||
u32 num_partitions;
|
||||
u64 partitions_offset;
|
||||
std::vector<SPartition> partitions;
|
||||
};
|
||||
SPartitionGroup PartitionGroup[4];
|
||||
SPartitionGroup partition_groups[4];
|
||||
|
||||
// Read all partitions
|
||||
for (SPartitionGroup& group : PartitionGroup)
|
||||
for (SPartitionGroup& group : partition_groups)
|
||||
{
|
||||
for (u32 i = 0; i < numPartitions; i++)
|
||||
{
|
||||
SPartition Partition;
|
||||
Partition.Offset = ((u64)big_endian_reader.Read32(PartitionsOffset + (i * 8) + 0)) << 2;
|
||||
Partition.Type = big_endian_reader.Read32(PartitionsOffset + (i * 8) + 4);
|
||||
group.PartitionsVec.push_back(Partition);
|
||||
SPartition partition;
|
||||
partition.offset = ((u64)big_endian_reader.Read32(PartitionsOffset + (i * 8) + 0)) << 2;
|
||||
partition.type = big_endian_reader.Read32(PartitionsOffset + (i * 8) + 4);
|
||||
group.partitions.push_back(partition);
|
||||
}
|
||||
}
|
||||
|
||||
// Return the partition type specified or number
|
||||
// types: 0 = game, 1 = firmware update, 2 = channel installer
|
||||
// some partitions on SSBB use the ASCII title id of the demo VC game they hold...
|
||||
for (size_t i = 0; i < PartitionGroup[_PartitionGroup].PartitionsVec.size(); i++)
|
||||
for (size_t i = 0; i < partition_groups[partition_group].partitions.size(); i++)
|
||||
{
|
||||
const SPartition& rPartition = PartitionGroup[_PartitionGroup].PartitionsVec.at(i);
|
||||
const SPartition& partition = partition_groups[partition_group].partitions.at(i);
|
||||
|
||||
if ((rPartition.Type == _VolumeType && (int)_VolumeNum == -1) || i == _VolumeNum)
|
||||
if ((partition.type == volume_type && (int)volume_number == -1) || i == volume_number)
|
||||
{
|
||||
u8 VolumeKey[16];
|
||||
VolumeKeyForPartition(*reader, rPartition.Offset, VolumeKey);
|
||||
return new CVolumeWiiCrypted(std::move(reader), rPartition.Offset, VolumeKey);
|
||||
u8 volume_key[16];
|
||||
VolumeKeyForPartition(*reader, partition.offset, volume_key);
|
||||
return std::make_unique<CVolumeWiiCrypted>(std::move(reader), partition.offset, volume_key);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
@ -14,8 +15,8 @@ namespace DiscIO
|
||||
class IVolume;
|
||||
class IBlobReader;
|
||||
|
||||
IVolume* CreateVolumeFromFilename(const std::string& _rFilename, u32 _PartitionGroup = 0, u32 _VolumeNum = -1);
|
||||
IVolume* CreateVolumeFromDirectory(const std::string& _rDirectory, bool _bIsWii, const std::string& _rApploader = "", const std::string& _rDOL = "");
|
||||
std::unique_ptr<IVolume> CreateVolumeFromFilename(const std::string& filename, u32 partition_group = 0, u32 volume_number = -1);
|
||||
std::unique_ptr<IVolume> CreateVolumeFromDirectory(const std::string& directory, bool is_wii, const std::string& apploader = "", const std::string& dol = "");
|
||||
void VolumeKeyForPartition(IBlobReader& _rReader, u64 offset, u8* VolumeKey);
|
||||
|
||||
} // namespace
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@ -167,19 +168,14 @@ File::IOFile& WbfsFileReader::SeekToCluster(u64 offset, u64* available)
|
||||
return m_files[0]->file;
|
||||
}
|
||||
|
||||
WbfsFileReader* WbfsFileReader::Create(const std::string& filename)
|
||||
std::unique_ptr<WbfsFileReader> WbfsFileReader::Create(const std::string& filename)
|
||||
{
|
||||
WbfsFileReader* reader = new WbfsFileReader(filename);
|
||||
auto reader = std::unique_ptr<WbfsFileReader>(new WbfsFileReader(filename));
|
||||
|
||||
if (reader->IsGood())
|
||||
{
|
||||
return reader;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete reader;
|
||||
return nullptr;
|
||||
}
|
||||
if (!reader->IsGood())
|
||||
reader.reset();
|
||||
|
||||
return reader;
|
||||
}
|
||||
|
||||
bool IsWbfsBlob(const std::string& filename)
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@ -17,7 +18,9 @@ namespace DiscIO
|
||||
class WbfsFileReader : public IBlobReader
|
||||
{
|
||||
public:
|
||||
static WbfsFileReader* Create(const std::string& filename);
|
||||
~WbfsFileReader();
|
||||
|
||||
static std::unique_ptr<WbfsFileReader> Create(const std::string& filename);
|
||||
|
||||
BlobType GetBlobType() const override { return BlobType::WBFS; }
|
||||
|
||||
@ -31,7 +34,6 @@ public:
|
||||
|
||||
private:
|
||||
WbfsFileReader(const std::string& filename);
|
||||
~WbfsFileReader();
|
||||
|
||||
bool OpenFiles(const std::string& filename);
|
||||
bool ReadHeader();
|
||||
|
Reference in New Issue
Block a user