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:
Lioncash 2015-12-06 23:15:51 -05:00
parent a0ac2b8673
commit edbbf493f8
22 changed files with 204 additions and 231 deletions

View File

@ -429,14 +429,14 @@ const DiscIO::IVolume& GetVolume()
bool SetVolumeName(const std::string& disc_path) bool SetVolumeName(const std::string& disc_path)
{ {
DVDThread::WaitUntilIdle(); DVDThread::WaitUntilIdle();
s_inserted_volume = std::unique_ptr<DiscIO::IVolume>(DiscIO::CreateVolumeFromFilename(disc_path)); s_inserted_volume = DiscIO::CreateVolumeFromFilename(disc_path);
return VolumeIsValid(); return VolumeIsValid();
} }
bool SetVolumeDirectory(const std::string& full_path, bool is_wii, const std::string& apploader_path, const std::string& DOL_path) bool SetVolumeDirectory(const std::string& full_path, bool is_wii, const std::string& apploader_path, const std::string& DOL_path)
{ {
DVDThread::WaitUntilIdle(); DVDThread::WaitUntilIdle();
s_inserted_volume = std::unique_ptr<DiscIO::IVolume>(DiscIO::CreateVolumeFromDirectory(full_path, is_wii, apploader_path, DOL_path)); s_inserted_volume = DiscIO::CreateVolumeFromDirectory(full_path, is_wii, apploader_path, DOL_path);
return VolumeIsValid(); return VolumeIsValid();
} }

View File

@ -4,6 +4,7 @@
#include <cstddef> #include <cstddef>
#include <cstring> #include <cstring>
#include <memory>
#include <string> #include <string>
#include "Common/CDUtils.h" #include "Common/CDUtils.h"
@ -114,7 +115,7 @@ bool SectorReader::ReadMultipleAlignedBlocks(u64 block_num, u64 num_blocks, u8 *
return true; return true;
} }
IBlobReader* CreateBlobReader(const std::string& filename) std::unique_ptr<IBlobReader> CreateBlobReader(const std::string& filename)
{ {
if (cdio_is_cdrom(filename)) if (cdio_is_cdrom(filename))
return DriveReader::Create(filename); return DriveReader::Create(filename);

View File

@ -14,6 +14,7 @@
// detect whether the file is a compressed blob, or just a big hunk of data, or a drive, and // detect whether the file is a compressed blob, or just a big hunk of data, or a drive, and
// automatically do the right thing. // automatically do the right thing.
#include <memory>
#include <string> #include <string>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
@ -75,7 +76,7 @@ private:
}; };
// Factory function - examines the path to choose the right type of IBlobReader, and returns one. // 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); typedef bool (*CompressCB)(const std::string& text, float percent, void* arg);

View File

@ -4,6 +4,7 @@
#include <algorithm> #include <algorithm>
#include <cstdio> #include <cstdio>
#include <memory>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/FileUtil.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; 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)) if (IsCISOBlob(filename))
{ {
File::IOFile f(filename, "rb"); File::IOFile f(filename, "rb");
return new CISOFileReader(f.ReleaseHandle()); return std::unique_ptr<CISOFileReader>(new CISOFileReader(f.ReleaseHandle()));
}
else
{
return nullptr;
} }
return nullptr;
} }
u64 CISOFileReader::GetDataSize() const u64 CISOFileReader::GetDataSize() const

View File

@ -5,6 +5,7 @@
#pragma once #pragma once
#include <cstdio> #include <cstdio>
#include <memory>
#include <string> #include <string>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
@ -34,7 +35,7 @@ struct CISOHeader
class CISOFileReader : public IBlobReader class CISOFileReader : public IBlobReader
{ {
public: 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; } BlobType GetBlobType() const override { return BlobType::CISO; }

View File

@ -55,12 +55,12 @@ CompressedBlobReader::CompressedBlobReader(const std::string& filename) : m_file
memset(m_zlib_buffer, 0, m_zlib_buffer_size); 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)) if (IsGCZBlob(filename))
return new CompressedBlobReader(filename); return std::unique_ptr<CompressedBlobReader>(new CompressedBlobReader(filename));
else
return nullptr; return nullptr;
} }
CompressedBlobReader::~CompressedBlobReader() CompressedBlobReader::~CompressedBlobReader()

View File

@ -14,6 +14,7 @@
#pragma once #pragma once
#include <memory>
#include <string> #include <string>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
@ -46,7 +47,7 @@ struct CompressedBlobHeader // 32 bytes
class CompressedBlobReader : public SectorReader class CompressedBlobReader : public SectorReader
{ {
public: public:
static CompressedBlobReader* Create(const std::string& filename); static std::unique_ptr<CompressedBlobReader> Create(const std::string& filename);
~CompressedBlobReader(); ~CompressedBlobReader();
const CompressedBlobHeader &GetHeader() const { return m_header; } const CompressedBlobHeader &GetHeader() const { return m_header; }
BlobType GetBlobType() const override { return BlobType::GCZ; } BlobType GetBlobType() const override { return BlobType::GCZ; }

View File

@ -34,7 +34,7 @@ static int m_BlocksPerCluster;
static bool m_isScrubbing = false; static bool m_isScrubbing = false;
static std::string m_Filename; static std::string m_Filename;
static IVolume* m_Disc = nullptr; static std::unique_ptr<IVolume> s_disc;
struct SPartitionHeader struct SPartitionHeader
{ {
@ -94,11 +94,11 @@ bool SetupScrub(const std::string& filename, int block_size)
m_BlocksPerCluster = CLUSTER_SIZE / m_BlockSize; m_BlocksPerCluster = CLUSTER_SIZE / m_BlockSize;
m_Disc = CreateVolumeFromFilename(filename); s_disc = CreateVolumeFromFilename(filename);
if (!m_Disc) if (!s_disc)
return false; return false;
m_FileSize = m_Disc->GetSize(); m_FileSize = s_disc->GetSize();
u32 numClusters = (u32)(m_FileSize / CLUSTER_SIZE); 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 // Fill out table of free blocks
success = ParseDisc(); success = ParseDisc();
// Done with it; need it closed for the next part // Done with it; need it closed for the next part
delete m_Disc; s_disc.reset();
m_Disc = nullptr;
m_BlockCount = 0; m_BlockCount = 0;
// Let's not touch the file if we've failed up to here :p // 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 // Helper functions for reading the BE volume
void ReadFromVolume(u64 _Offset, u32& _Buffer, bool _Decrypt) 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); _Buffer = Common::swap32(_Buffer);
} }
void ReadFromVolume(u64 _Offset, u64& _Buffer, bool _Decrypt) 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 = Common::swap32((u32)_Buffer);
_Buffer <<= 2; _Buffer <<= 2;
} }
@ -259,71 +259,71 @@ bool ParseDisc()
} }
// Operations dealing with encrypted space are done here - the volume is swapped to allow this // 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 // Switch out the main volume temporarily
IVolume *OldVolume = m_Disc; std::unique_ptr<IVolume> old_volume;
s_disc.swap(old_volume);
// Ready some stuff // Ready some stuff
m_Disc = CreateVolumeFromFilename(m_Filename, _rPartition.GroupNumber, _rPartition.Number); s_disc = CreateVolumeFromFilename(m_Filename, partition.GroupNumber, partition.Number);
if (m_Disc == nullptr) if (s_disc == nullptr)
{ {
ERROR_LOG(DISCIO, "Failed to create volume from file %s", m_Filename.c_str()); ERROR_LOG(DISCIO, "Failed to create volume from file %s", m_Filename.c_str());
m_Disc = OldVolume; s_disc.swap(old_volume);
return false; return false;
} }
std::unique_ptr<IFileSystem> filesystem(CreateFileSystem(m_Disc)); std::unique_ptr<IFileSystem> filesystem(CreateFileSystem(s_disc.get()));
if (!filesystem) if (!filesystem)
{ {
ERROR_LOG(DISCIO, "Failed to create filesystem for group %d partition %u", _rPartition.GroupNumber, _rPartition.Number); ERROR_LOG(DISCIO, "Failed to create filesystem for group %d partition %u", partition.GroupNumber, partition.Number);
ParsedOK = false; parsed_ok = false;
} }
else else
{ {
// Mark things as used which are not in the filesystem // Mark things as used which are not in the filesystem
// Header, Header Information, Apploader // Header, Header Information, Apploader
ReadFromVolume(0x2440 + 0x14, _rPartition.Header.ApploaderSize, true); ReadFromVolume(0x2440 + 0x14, partition.Header.ApploaderSize, true);
ReadFromVolume(0x2440 + 0x18, _rPartition.Header.ApploaderTrailerSize, true); ReadFromVolume(0x2440 + 0x18, partition.Header.ApploaderTrailerSize, true);
MarkAsUsedE(_rPartition.Offset MarkAsUsedE(partition.Offset
+ _rPartition.Header.DataOffset + partition.Header.DataOffset
, 0 , 0
, 0x2440 , 0x2440
+ _rPartition.Header.ApploaderSize + partition.Header.ApploaderSize
+ _rPartition.Header.ApploaderTrailerSize); + partition.Header.ApploaderTrailerSize);
// DOL // DOL
ReadFromVolume(0x420, _rPartition.Header.DOLOffset, true); ReadFromVolume(0x420, partition.Header.DOLOffset, true);
_rPartition.Header.DOLSize = filesystem->GetBootDOLSize(_rPartition.Header.DOLOffset); partition.Header.DOLSize = filesystem->GetBootDOLSize(partition.Header.DOLOffset);
MarkAsUsedE(_rPartition.Offset MarkAsUsedE(partition.Offset
+ _rPartition.Header.DataOffset + partition.Header.DataOffset
, _rPartition.Header.DOLOffset , partition.Header.DOLOffset
, _rPartition.Header.DOLSize); , partition.Header.DOLSize);
// FST // FST
ReadFromVolume(0x424, _rPartition.Header.FSTOffset, true); ReadFromVolume(0x424, partition.Header.FSTOffset, true);
ReadFromVolume(0x428, _rPartition.Header.FSTSize, true); ReadFromVolume(0x428, partition.Header.FSTSize, true);
MarkAsUsedE(_rPartition.Offset MarkAsUsedE(partition.Offset
+ _rPartition.Header.DataOffset + partition.Header.DataOffset
, _rPartition.Header.FSTOffset , partition.Header.FSTOffset
, _rPartition.Header.FSTSize); , partition.Header.FSTSize);
// Go through the filesystem and mark entries as used // Go through the filesystem and mark entries as used
for (SFileInfo file : filesystem->GetFileList()) for (SFileInfo file : filesystem->GetFileList())
{ {
DEBUG_LOG(DISCIO, "%s", file.m_FullPath.empty() ? "/" : file.m_FullPath.c_str()); DEBUG_LOG(DISCIO, "%s", file.m_FullPath.empty() ? "/" : file.m_FullPath.c_str());
if ((file.m_NameOffset & 0x1000000) == 0) 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 // Swap back
delete m_Disc; s_disc.swap(old_volume);
m_Disc = OldVolume;
return ParsedOK; return parsed_ok;
} }
} // namespace DiscScrubber } // namespace DiscScrubber

View File

@ -4,6 +4,7 @@
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
#include <memory>
#include <string> #include <string>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
@ -84,15 +85,12 @@ DriveReader::~DriveReader()
#endif #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()) if (!reader->IsOK())
{ reader.reset();
delete reader;
return nullptr;
}
return reader; return reader;
} }

View File

@ -4,6 +4,7 @@
#pragma once #pragma once
#include <memory>
#include <string> #include <string>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
@ -21,7 +22,7 @@ namespace DiscIO
class DriveReader : public SectorReader class DriveReader : public SectorReader
{ {
public: public:
static DriveReader* Create(const std::string& drive); static std::unique_ptr<DriveReader> Create(const std::string& drive);
~DriveReader(); ~DriveReader();
BlobType GetBlobType() const override { return BlobType::DRIVE; } BlobType GetBlobType() const override { return BlobType::DRIVE; }
u64 GetDataSize() const override { return m_size; } u64 GetDataSize() const override { return m_size; }

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <memory>
#include <string> #include <string>
#include "DiscIO/FileBlob.h" #include "DiscIO/FileBlob.h"
@ -14,13 +15,13 @@ PlainFileReader::PlainFileReader(std::FILE* file)
m_size = m_file.GetSize(); 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"); File::IOFile f(filename, "rb");
if (f) if (f)
return new PlainFileReader(f.ReleaseHandle()); return std::unique_ptr<PlainFileReader>(new PlainFileReader(f.ReleaseHandle()));
else
return nullptr; return nullptr;
} }
bool PlainFileReader::Read(u64 offset, u64 nbytes, u8* out_ptr) bool PlainFileReader::Read(u64 offset, u64 nbytes, u8* out_ptr)

View File

@ -5,6 +5,7 @@
#pragma once #pragma once
#include <cstdio> #include <cstdio>
#include <memory>
#include <string> #include <string>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
@ -17,7 +18,7 @@ namespace DiscIO
class PlainFileReader : public IBlobReader class PlainFileReader : public IBlobReader
{ {
public: 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; } BlobType GetBlobType() const override { return BlobType::PLAIN; }
u64 GetDataSize() const override { return m_size; } u64 GetDataSize() const override { return m_size; }

View File

@ -5,6 +5,7 @@
#include <algorithm> #include <algorithm>
#include <cctype> #include <cctype>
#include <cstring> #include <cstring>
#include <memory>
#include <string> #include <string>
#include <unordered_set> #include <unordered_set>
#include <vector> #include <vector>
@ -25,8 +26,8 @@
namespace FileMon namespace FileMon
{ {
static DiscIO::IVolume *OpenISO = nullptr; static std::unique_ptr<DiscIO::IVolume> s_open_iso;
static DiscIO::IFileSystem *pFileSystem = nullptr; static std::unique_ptr<DiscIO::IFileSystem> s_filesystem;
static std::string ISOFile = "", CurrentFile = ""; static std::string ISOFile = "", CurrentFile = "";
static bool FileAccess = true; static bool FileAccess = true;
@ -61,26 +62,18 @@ bool IsSoundFile(const std::string& filename)
void ReadFileSystem(const std::string& filename) void ReadFileSystem(const std::string& filename)
{ {
// Should have an actual Shutdown procedure or something // Should have an actual Shutdown procedure or something
if (OpenISO != nullptr) s_open_iso.reset();
{ s_filesystem.reset();
delete OpenISO;
OpenISO = nullptr;
}
if (pFileSystem != nullptr)
{
delete pFileSystem;
pFileSystem = nullptr;
}
OpenISO = DiscIO::CreateVolumeFromFilename(filename); s_open_iso = DiscIO::CreateVolumeFromFilename(filename);
if (!OpenISO) if (!s_open_iso)
return; 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; return;
} }
@ -130,7 +123,7 @@ void FindFilename(u64 offset)
if (!FileAccess) if (!FileAccess)
return; return;
if (!pFileSystem || ISOFile != SConfig::GetInstance().m_LastFilename) if (!s_filesystem || ISOFile != SConfig::GetInstance().m_LastFilename)
{ {
FileAccess = false; FileAccess = false;
ReadFileSystem(SConfig::GetInstance().m_LastFilename); ReadFileSystem(SConfig::GetInstance().m_LastFilename);
@ -139,27 +132,18 @@ void FindFilename(u64 offset)
return; return;
} }
const std::string filename = pFileSystem->GetFileName(offset); const std::string filename = s_filesystem->GetFileName(offset);
if (filename.empty()) if (filename.empty())
return; return;
CheckFile(filename, pFileSystem->GetFileSize(filename)); CheckFile(filename, s_filesystem->GetFileSize(filename));
} }
void Close() void Close()
{ {
if (OpenISO != nullptr) s_open_iso.reset();
{ s_filesystem.reset();
delete OpenISO;
OpenISO = nullptr;
}
if (pFileSystem != nullptr)
{
delete pFileSystem;
pFileSystem = nullptr;
}
ISOFile = ""; ISOFile = "";
CurrentFile = ""; CurrentFile = "";

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <memory>
#include "DiscIO/Filesystem.h" #include "DiscIO/Filesystem.h"
#include "DiscIO/FileSystemGCWii.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; return nullptr;
if (!pFileSystem->IsValid()) if (!filesystem->IsValid())
{ filesystem.reset();
delete pFileSystem;
pFileSystem = nullptr;
}
return pFileSystem; return filesystem;
} }
} // namespace } // namespace

View File

@ -4,8 +4,7 @@
#pragma once #pragma once
#include <cstddef> #include <memory>
#include <cstring>
#include <string> #include <string>
#include <vector> #include <vector>
@ -57,6 +56,6 @@ protected:
const IVolume *m_rVolume; const IVolume *m_rVolume;
}; };
IFileSystem* CreateFileSystem(const IVolume *_rVolume); std::unique_ptr<IFileSystem> CreateFileSystem(const IVolume* volume);
} // namespace } // namespace

View File

@ -71,12 +71,12 @@ static const unsigned char s_master_key_korean[16] = {
0x13,0xf2,0xfe,0xfb,0xba,0x4c,0x9b,0x7e 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); 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) if (reader == nullptr)
return nullptr; return nullptr;
@ -84,30 +84,30 @@ IVolume* CreateVolumeFromFilename(const std::string& _rFilename, u32 _PartitionG
{ {
case DISC_TYPE_WII: case DISC_TYPE_WII:
case DISC_TYPE_GC: case DISC_TYPE_GC:
return new CVolumeGC(std::move(reader)); return std::make_unique<CVolumeGC>(std::move(reader));
case DISC_TYPE_WAD: case DISC_TYPE_WAD:
return new CVolumeWAD(std::move(reader)); return std::make_unique<CVolumeWAD>(std::move(reader));
case DISC_TYPE_WII_CONTAINER: 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: case DISC_TYPE_UNK:
default: default:
std::string Filename, ext; std::string name, extension;
SplitPath(_rFilename, nullptr, &Filename, &ext); SplitPath(filename, nullptr, &name, &extension);
Filename += ext; name += extension;
NOTICE_LOG(DISCIO, "%s does not have the Magic word for a gcm, wiidisc or wad file\n" 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; 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)) if (CVolumeDirectory::IsValidDirectory(directory))
return new CVolumeDirectory(_rDirectory, _bIsWii, _rApploader, _rDOL); return std::make_unique<CVolumeDirectory>(directory, is_wii, apploader, dol);
return nullptr; 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); 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); CBlobBigEndianReader big_endian_reader(*reader);
u32 numPartitions = big_endian_reader.Read32(0x40000 + (_PartitionGroup * 8)); u32 numPartitions = big_endian_reader.Read32(0x40000 + (partition_group * 8));
u64 PartitionsOffset = (u64)big_endian_reader.Read32(0x40000 + (_PartitionGroup * 8) + 4) << 2; u64 PartitionsOffset = (u64)big_endian_reader.Read32(0x40000 + (partition_group * 8) + 4) << 2;
// Check if we're looking for a valid partition // 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; return nullptr;
struct SPartition struct SPartition
{ {
u64 Offset; u64 offset;
u32 Type; u32 type;
}; };
struct SPartitionGroup struct SPartitionGroup
{ {
u32 numPartitions; u32 num_partitions;
u64 PartitionsOffset; u64 partitions_offset;
std::vector<SPartition> PartitionsVec; std::vector<SPartition> partitions;
}; };
SPartitionGroup PartitionGroup[4]; SPartitionGroup partition_groups[4];
// Read all partitions // Read all partitions
for (SPartitionGroup& group : PartitionGroup) for (SPartitionGroup& group : partition_groups)
{ {
for (u32 i = 0; i < numPartitions; i++) for (u32 i = 0; i < numPartitions; i++)
{ {
SPartition Partition; SPartition partition;
Partition.Offset = ((u64)big_endian_reader.Read32(PartitionsOffset + (i * 8) + 0)) << 2; partition.offset = ((u64)big_endian_reader.Read32(PartitionsOffset + (i * 8) + 0)) << 2;
Partition.Type = big_endian_reader.Read32(PartitionsOffset + (i * 8) + 4); partition.type = big_endian_reader.Read32(PartitionsOffset + (i * 8) + 4);
group.PartitionsVec.push_back(Partition); group.partitions.push_back(partition);
} }
} }
// Return the partition type specified or number // Return the partition type specified or number
// types: 0 = game, 1 = firmware update, 2 = channel installer // 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... // 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]; u8 volume_key[16];
VolumeKeyForPartition(*reader, rPartition.Offset, VolumeKey); VolumeKeyForPartition(*reader, partition.offset, volume_key);
return new CVolumeWiiCrypted(std::move(reader), rPartition.Offset, VolumeKey); return std::make_unique<CVolumeWiiCrypted>(std::move(reader), partition.offset, volume_key);
} }
} }

View File

@ -4,6 +4,7 @@
#pragma once #pragma once
#include <memory>
#include <string> #include <string>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
@ -14,8 +15,8 @@ namespace DiscIO
class IVolume; class IVolume;
class IBlobReader; class IBlobReader;
IVolume* CreateVolumeFromFilename(const std::string& _rFilename, u32 _PartitionGroup = 0, u32 _VolumeNum = -1); std::unique_ptr<IVolume> CreateVolumeFromFilename(const std::string& filename, u32 partition_group = 0, u32 volume_number = -1);
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 = "");
void VolumeKeyForPartition(IBlobReader& _rReader, u64 offset, u8* VolumeKey); void VolumeKeyForPartition(IBlobReader& _rReader, u64 offset, u8* VolumeKey);
} // namespace } // namespace

View File

@ -5,6 +5,7 @@
#include <algorithm> #include <algorithm>
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
#include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
@ -167,19 +168,14 @@ File::IOFile& WbfsFileReader::SeekToCluster(u64 offset, u64* available)
return m_files[0]->file; 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()) if (!reader->IsGood())
{ reader.reset();
return reader;
} return reader;
else
{
delete reader;
return nullptr;
}
} }
bool IsWbfsBlob(const std::string& filename) bool IsWbfsBlob(const std::string& filename)

View File

@ -4,6 +4,7 @@
#pragma once #pragma once
#include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
@ -17,7 +18,9 @@ namespace DiscIO
class WbfsFileReader : public IBlobReader class WbfsFileReader : public IBlobReader
{ {
public: 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; } BlobType GetBlobType() const override { return BlobType::WBFS; }
@ -31,7 +34,6 @@ public:
private: private:
WbfsFileReader(const std::string& filename); WbfsFileReader(const std::string& filename);
~WbfsFileReader();
bool OpenFiles(const std::string& filename); bool OpenFiles(const std::string& filename);
bool ReadHeader(); bool ReadHeader();

View File

@ -105,14 +105,14 @@ CISOProperties::CISOProperties(const GameListItem& game_list_item, wxWindow* par
, OpenGameListItem(game_list_item) , OpenGameListItem(game_list_item)
{ {
// Load ISO data // Load ISO data
OpenISO = DiscIO::CreateVolumeFromFilename(OpenGameListItem.GetFileName()); m_open_iso = DiscIO::CreateVolumeFromFilename(OpenGameListItem.GetFileName());
game_id = OpenISO->GetUniqueID(); game_id = m_open_iso->GetUniqueID();
// Load game INIs // Load game INIs
GameIniFileLocal = File::GetUserPath(D_GAMESETTINGS_IDX) + game_id + ".ini"; GameIniFileLocal = File::GetUserPath(D_GAMESETTINGS_IDX) + game_id + ".ini";
GameIniDefault = SConfig::LoadDefaultGameIni(game_id, OpenISO->GetRevision()); GameIniDefault = SConfig::LoadDefaultGameIni(game_id, m_open_iso->GetRevision());
GameIniLocal = SConfig::LoadLocalGameIni(game_id, OpenISO->GetRevision()); GameIniLocal = SConfig::LoadLocalGameIni(game_id, m_open_iso->GetRevision());
// Setup GUI // Setup GUI
bRefreshList = false; bRefreshList = false;
@ -123,9 +123,9 @@ CISOProperties::CISOProperties(const GameListItem& game_list_item, wxWindow* par
// Disk header and apploader // Disk header and apploader
m_InternalName->SetValue(StrToWxStr(OpenISO->GetInternalName())); m_InternalName->SetValue(StrToWxStr(m_open_iso->GetInternalName()));
m_GameID->SetValue(StrToWxStr(OpenISO->GetUniqueID())); m_GameID->SetValue(StrToWxStr(m_open_iso->GetUniqueID()));
switch (OpenISO->GetCountry()) switch (m_open_iso->GetCountry())
{ {
case DiscIO::IVolume::COUNTRY_AUSTRALIA: case DiscIO::IVolume::COUNTRY_AUSTRALIA:
m_Country->SetValue(_("Australia")); m_Country->SetValue(_("Australia"));
@ -172,14 +172,14 @@ CISOProperties::CISOProperties(const GameListItem& game_list_item, wxWindow* par
break; break;
} }
wxString temp = "0x" + StrToWxStr(OpenISO->GetMakerID()); wxString temp = "0x" + StrToWxStr(m_open_iso->GetMakerID());
m_MakerID->SetValue(temp); m_MakerID->SetValue(temp);
m_Revision->SetValue(StrToWxStr(std::to_string(OpenISO->GetRevision()))); m_Revision->SetValue(StrToWxStr(std::to_string(m_open_iso->GetRevision())));
m_Date->SetValue(StrToWxStr(OpenISO->GetApploaderDate())); m_Date->SetValue(StrToWxStr(m_open_iso->GetApploaderDate()));
m_FST->SetValue(StrToWxStr(std::to_string(OpenISO->GetFSTSize()))); m_FST->SetValue(StrToWxStr(std::to_string(m_open_iso->GetFSTSize())));
// Here we set all the info to be shown + we set the window title // Here we set all the info to be shown + we set the window title
bool wii = OpenISO->GetVolumeType() != DiscIO::IVolume::GAMECUBE_DISC; bool wii = m_open_iso->GetVolumeType() != DiscIO::IVolume::GAMECUBE_DISC;
ChangeBannerDetails(SConfig::GetInstance().GetCurrentLanguage(wii)); ChangeBannerDetails(SConfig::GetInstance().GetCurrentLanguage(wii));
m_Banner->SetBitmap(OpenGameListItem.GetBitmap()); m_Banner->SetBitmap(OpenGameListItem.GetBitmap());
@ -187,9 +187,9 @@ CISOProperties::CISOProperties(const GameListItem& game_list_item, wxWindow* par
// Filesystem browser/dumper // Filesystem browser/dumper
// TODO : Should we add a way to browse the wad file ? // TODO : Should we add a way to browse the wad file ?
if (OpenISO->GetVolumeType() != DiscIO::IVolume::WII_WAD) if (m_open_iso->GetVolumeType() != DiscIO::IVolume::WII_WAD)
{ {
if (OpenISO->GetVolumeType() == DiscIO::IVolume::WII_DISC) if (m_open_iso->GetVolumeType() == DiscIO::IVolume::WII_DISC)
{ {
int partition_count = 0; int partition_count = 0;
for (int group = 0; group < 4; group++) for (int group = 0; group < 4; group++)
@ -225,9 +225,9 @@ CISOProperties::CISOProperties(const GameListItem& game_list_item, wxWindow* par
} }
else else
{ {
pFileSystem = DiscIO::CreateFileSystem(OpenISO); m_filesystem = DiscIO::CreateFileSystem(m_open_iso.get());
if (pFileSystem) if (m_filesystem)
CreateDirectoryTree(RootId, pFileSystem->GetFileList()); CreateDirectoryTree(RootId, m_filesystem->GetFileList());
} }
m_Treectrl->Expand(RootId); m_Treectrl->Expand(RootId);
@ -236,9 +236,6 @@ CISOProperties::CISOProperties(const GameListItem& game_list_item, wxWindow* par
CISOProperties::~CISOProperties() CISOProperties::~CISOProperties()
{ {
if (OpenISO->GetVolumeType() == DiscIO::IVolume::GAMECUBE_DISC && pFileSystem)
delete pFileSystem;
delete OpenISO;
} }
size_t CISOProperties::CreateDirectoryTree(wxTreeItemId& parent, const std::vector<DiscIO::SFileInfo>& fileInfos) size_t CISOProperties::CreateDirectoryTree(wxTreeItemId& parent, const std::vector<DiscIO::SFileInfo>& fileInfos)
@ -396,7 +393,7 @@ void CISOProperties::CreateGUIControls()
sbCoreOverrides->Add(sGPUDeterminism, 0, wxEXPAND|wxALL, 5); sbCoreOverrides->Add(sGPUDeterminism, 0, wxEXPAND|wxALL, 5);
wxStaticBoxSizer * const sbWiiOverrides = new wxStaticBoxSizer(wxVERTICAL, m_GameConfig, _("Wii Console")); wxStaticBoxSizer * const sbWiiOverrides = new wxStaticBoxSizer(wxVERTICAL, m_GameConfig, _("Wii Console"));
if (OpenISO->GetVolumeType() == DiscIO::IVolume::GAMECUBE_DISC) if (m_open_iso->GetVolumeType() == DiscIO::IVolume::GAMECUBE_DISC)
{ {
sbWiiOverrides->ShowItems(false); sbWiiOverrides->ShowItems(false);
EnableWideScreen->Hide(); EnableWideScreen->Hide();
@ -484,7 +481,7 @@ void CISOProperties::CreateGUIControls()
wxStaticText* const m_LangText = new wxStaticText(m_Information, wxID_ANY, _("Show Language:")); wxStaticText* const m_LangText = new wxStaticText(m_Information, wxID_ANY, _("Show Language:"));
bool wii = OpenISO->GetVolumeType() != DiscIO::IVolume::GAMECUBE_DISC; bool wii = m_open_iso->GetVolumeType() != DiscIO::IVolume::GAMECUBE_DISC;
DiscIO::IVolume::ELanguage preferred_language = SConfig::GetInstance().GetCurrentLanguage(wii); DiscIO::IVolume::ELanguage preferred_language = SConfig::GetInstance().GetCurrentLanguage(wii);
std::vector<DiscIO::IVolume::ELanguage> languages = OpenGameListItem.GetLanguages(); std::vector<DiscIO::IVolume::ELanguage> languages = OpenGameListItem.GetLanguages();
@ -595,10 +592,10 @@ void CISOProperties::CreateGUIControls()
sInfoPage->Add(sbBannerDetails, 0, wxEXPAND|wxALL, 5); sInfoPage->Add(sbBannerDetails, 0, wxEXPAND|wxALL, 5);
m_Information->SetSizer(sInfoPage); m_Information->SetSizer(sInfoPage);
if (OpenISO->GetVolumeType() != DiscIO::IVolume::WII_WAD) if (m_open_iso->GetVolumeType() != DiscIO::IVolume::WII_WAD)
{ {
wxPanel* const m_Filesystem = new wxPanel(m_Notebook, ID_FILESYSTEM); wxPanel* const filesystem_panel = new wxPanel(m_Notebook, ID_FILESYSTEM);
m_Notebook->AddPage(m_Filesystem, _("Filesystem")); m_Notebook->AddPage(filesystem_panel, _("Filesystem"));
// Filesystem icons // Filesystem icons
wxImageList* const m_iconList = new wxImageList(16, 16); wxImageList* const m_iconList = new wxImageList(16, 16);
@ -607,13 +604,13 @@ void CISOProperties::CreateGUIControls()
m_iconList->Add(wxBitmap(file_xpm), wxNullBitmap); // 2 m_iconList->Add(wxBitmap(file_xpm), wxNullBitmap); // 2
// Filesystem tree // Filesystem tree
m_Treectrl = new wxTreeCtrl(m_Filesystem, ID_TREECTRL); m_Treectrl = new wxTreeCtrl(filesystem_panel, ID_TREECTRL);
m_Treectrl->AssignImageList(m_iconList); m_Treectrl->AssignImageList(m_iconList);
RootId = m_Treectrl->AddRoot(_("Disc"), 0, 0, nullptr); RootId = m_Treectrl->AddRoot(_("Disc"), 0, 0, nullptr);
wxBoxSizer* sTreePage = new wxBoxSizer(wxVERTICAL); wxBoxSizer* sTreePage = new wxBoxSizer(wxVERTICAL);
sTreePage->Add(m_Treectrl, 1, wxEXPAND|wxALL, 5); sTreePage->Add(m_Treectrl, 1, wxEXPAND|wxALL, 5);
m_Filesystem->SetSizer(sTreePage); filesystem_panel->SetSizer(sTreePage);
} }
wxSizer* sButtons = CreateButtonSizer(wxNO_DEFAULT); wxSizer* sButtons = CreateButtonSizer(wxNO_DEFAULT);
@ -623,7 +620,7 @@ void CISOProperties::CreateGUIControls()
// If there is no default gameini, disable the button. // If there is no default gameini, disable the button.
bool game_ini_exists = false; bool game_ini_exists = false;
for (const std::string& ini_filename : SConfig::GetGameIniFilenames(game_id, OpenISO->GetRevision())) for (const std::string& ini_filename : SConfig::GetGameIniFilenames(game_id, m_open_iso->GetRevision()))
{ {
if (File::Exists(File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP + ini_filename)) if (File::Exists(File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP + ini_filename))
{ {
@ -703,7 +700,7 @@ void CISOProperties::OnRightClickOnTree(wxTreeEvent& event)
popupMenu.Append(IDM_EXTRACTALL, _("Extract All Files...")); popupMenu.Append(IDM_EXTRACTALL, _("Extract All Files..."));
if (OpenISO->GetVolumeType() != DiscIO::IVolume::WII_DISC || if (m_open_iso->GetVolumeType() != DiscIO::IVolume::WII_DISC ||
(m_Treectrl->GetItemImage(m_Treectrl->GetSelection()) == 0 && (m_Treectrl->GetItemImage(m_Treectrl->GetSelection()) == 0 &&
m_Treectrl->GetFirstVisibleItem() != m_Treectrl->GetSelection())) m_Treectrl->GetFirstVisibleItem() != m_Treectrl->GetSelection()))
{ {
@ -746,7 +743,7 @@ void CISOProperties::OnExtractFile(wxCommandEvent& WXUNUSED (event))
m_Treectrl->SelectItem(m_Treectrl->GetItemParent(m_Treectrl->GetSelection())); m_Treectrl->SelectItem(m_Treectrl->GetItemParent(m_Treectrl->GetSelection()));
} }
if (OpenISO->GetVolumeType() == DiscIO::IVolume::WII_DISC) if (m_open_iso->GetVolumeType() == DiscIO::IVolume::WII_DISC)
{ {
const wxTreeItemId tree_selection = m_Treectrl->GetSelection(); const wxTreeItemId tree_selection = m_Treectrl->GetSelection();
WiiPartition* partition = reinterpret_cast<WiiPartition*>(m_Treectrl->GetItemData(tree_selection)); WiiPartition* partition = reinterpret_cast<WiiPartition*>(m_Treectrl->GetItemData(tree_selection));
@ -756,13 +753,13 @@ void CISOProperties::OnExtractFile(wxCommandEvent& WXUNUSED (event))
} }
else else
{ {
pFileSystem->ExportFile(WxStrToStr(File), WxStrToStr(Path)); m_filesystem->ExportFile(WxStrToStr(File), WxStrToStr(Path));
} }
} }
void CISOProperties::ExportDir(const std::string& _rFullPath, const std::string& _rExportFolder, const WiiPartition* partition) void CISOProperties::ExportDir(const std::string& _rFullPath, const std::string& _rExportFolder, const WiiPartition* partition)
{ {
DiscIO::IFileSystem* const fs = OpenISO->GetVolumeType() == DiscIO::IVolume::WII_DISC ? partition->FileSystem.get() : pFileSystem; DiscIO::IFileSystem* const fs = m_open_iso->GetVolumeType() == DiscIO::IVolume::WII_DISC ? partition->FileSystem.get() : m_filesystem.get();
const std::vector<DiscIO::SFileInfo>& fst = fs->GetFileList(); const std::vector<DiscIO::SFileInfo>& fst = fs->GetFileList();
@ -776,7 +773,7 @@ void CISOProperties::ExportDir(const std::string& _rFullPath, const std::string&
size = (u32)fst.size(); size = (u32)fst.size();
fs->ExportApploader(_rExportFolder); fs->ExportApploader(_rExportFolder);
if (OpenISO->GetVolumeType() != DiscIO::IVolume::WII_DISC) if (m_open_iso->GetVolumeType() != DiscIO::IVolume::WII_DISC)
fs->ExportDOL(_rExportFolder); fs->ExportDOL(_rExportFolder);
} }
else else
@ -861,7 +858,7 @@ void CISOProperties::OnExtractDir(wxCommandEvent& event)
if (event.GetId() == IDM_EXTRACTALL) if (event.GetId() == IDM_EXTRACTALL)
{ {
if (OpenISO->GetVolumeType() == DiscIO::IVolume::WII_DISC) if (m_open_iso->GetVolumeType() == DiscIO::IVolume::WII_DISC)
{ {
wxTreeItemIdValue cookie; wxTreeItemIdValue cookie;
wxTreeItemId root = m_Treectrl->GetRootItem(); wxTreeItemId root = m_Treectrl->GetRootItem();
@ -890,7 +887,7 @@ void CISOProperties::OnExtractDir(wxCommandEvent& event)
Directory += DIR_SEP_CHR; Directory += DIR_SEP_CHR;
if (OpenISO->GetVolumeType() == DiscIO::IVolume::WII_DISC) if (m_open_iso->GetVolumeType() == DiscIO::IVolume::WII_DISC)
{ {
const wxTreeItemId tree_selection = m_Treectrl->GetSelection(); const wxTreeItemId tree_selection = m_Treectrl->GetSelection();
WiiPartition* partition = reinterpret_cast<WiiPartition*>(m_Treectrl->GetItemData(tree_selection)); WiiPartition* partition = reinterpret_cast<WiiPartition*>(m_Treectrl->GetItemData(tree_selection));
@ -912,14 +909,14 @@ void CISOProperties::OnExtractDataFromHeader(wxCommandEvent& event)
if (Path.empty()) if (Path.empty())
return; return;
if (OpenISO->GetVolumeType() == DiscIO::IVolume::WII_DISC) if (m_open_iso->GetVolumeType() == DiscIO::IVolume::WII_DISC)
{ {
WiiPartition* partition = reinterpret_cast<WiiPartition*>(m_Treectrl->GetItemData(m_Treectrl->GetSelection())); WiiPartition* partition = reinterpret_cast<WiiPartition*>(m_Treectrl->GetItemData(m_Treectrl->GetSelection()));
FS = partition->FileSystem.get(); FS = partition->FileSystem.get();
} }
else else
{ {
FS = pFileSystem; FS = m_filesystem.get();
} }
bool ret = false; bool ret = false;
@ -958,7 +955,7 @@ void CISOProperties::CheckPartitionIntegrity(wxCommandEvent& event)
{ {
// Normally we can't enter this function if we aren't analyzing a Wii disc // Normally we can't enter this function if we aren't analyzing a Wii disc
// anyway, but let's still check to be sure. // anyway, but let's still check to be sure.
if (OpenISO->GetVolumeType() != DiscIO::IVolume::WII_DISC) if (m_open_iso->GetVolumeType() != DiscIO::IVolume::WII_DISC)
return; return;
wxProgressDialog dialog(_("Checking integrity..."), _("Working..."), 1000, this, wxProgressDialog dialog(_("Checking integrity..."), _("Working..."), 1000, this,
@ -1082,7 +1079,7 @@ void CISOProperties::LoadGameConfig()
PatchList_Load(); PatchList_Load();
ActionReplayList_Load(); ActionReplayList_Load();
m_geckocode_panel->LoadCodes(GameIniDefault, GameIniLocal, OpenISO->GetUniqueID()); m_geckocode_panel->LoadCodes(GameIniDefault, GameIniLocal, m_open_iso->GetUniqueID());
} }
void CISOProperties::SaveGameIniValueFrom3StateCheckbox(const char* section, const char* key, wxCheckBox* checkbox) void CISOProperties::SaveGameIniValueFrom3StateCheckbox(const char* section, const char* key, wxCheckBox* checkbox)
@ -1279,7 +1276,7 @@ void CISOProperties::OnComputeMD5Sum(wxCommandEvent& WXUNUSED (event))
// they will all be opened, but there is usually only one // they will all be opened, but there is usually only one
void CISOProperties::OnShowDefaultConfig(wxCommandEvent& WXUNUSED (event)) void CISOProperties::OnShowDefaultConfig(wxCommandEvent& WXUNUSED (event))
{ {
for (const std::string& filename : SConfig::GetGameIniFilenames(game_id, OpenISO->GetRevision())) for (const std::string& filename : SConfig::GetGameIniFilenames(game_id, m_open_iso->GetRevision()))
{ {
std::string path = File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP + filename; std::string path = File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP + filename;
if (File::Exists(path)) if (File::Exists(path))

View File

@ -80,8 +80,8 @@ public:
private: private:
DECLARE_EVENT_TABLE(); DECLARE_EVENT_TABLE();
DiscIO::IVolume *OpenISO; std::unique_ptr<DiscIO::IVolume> m_open_iso;
DiscIO::IFileSystem *pFileSystem; std::unique_ptr<DiscIO::IFileSystem> m_filesystem;
std::vector<PatchEngine::Patch> onFrame; std::vector<PatchEngine::Patch> onFrame;
std::vector<ActionReplay::ARCode> arCodes; std::vector<ActionReplay::ARCode> arCodes;

View File

@ -5,6 +5,7 @@
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#include <jni.h> #include <jni.h>
#include <memory>
#include <android/log.h> #include <android/log.h>
#include <android/native_window_jni.h> #include <android/native_window_jni.h>
#include <EGL/egl.h> #include <EGL/egl.h>
@ -261,11 +262,11 @@ static std::string GetDescription(std::string filename)
{ {
__android_log_print(ANDROID_LOG_WARN, DOLPHIN_TAG, "Getting Description for file: %s", filename.c_str()); __android_log_print(ANDROID_LOG_WARN, DOLPHIN_TAG, "Getting Description for file: %s", filename.c_str());
DiscIO::IVolume* pVolume = DiscIO::CreateVolumeFromFilename(filename); std::unique_ptr<DiscIO::IVolume> volume(DiscIO::CreateVolumeFromFilename(filename));
if (pVolume != nullptr) if (volume != nullptr)
{ {
std::map <DiscIO::IVolume::ELanguage, std::string> descriptions = pVolume->GetDescriptions(); std::map<DiscIO::IVolume::ELanguage, std::string> descriptions = volume->GetDescriptions();
/* /*
bool is_wii_title = pVolume->GetVolumeType() != DiscIO::IVolume::GAMECUBE_DISC; bool is_wii_title = pVolume->GetVolumeType() != DiscIO::IVolume::GAMECUBE_DISC;
@ -289,53 +290,44 @@ static std::string GetDescription(std::string filename)
return descriptions.cbegin()->second; return descriptions.cbegin()->second;
} }
return std::string (""); return std::string();
} }
static std::string GetGameId(std::string filename) static std::string GetGameId(std::string filename)
{ {
__android_log_print(ANDROID_LOG_WARN, DOLPHIN_TAG, "Getting ID for file: %s", filename.c_str()); __android_log_print(ANDROID_LOG_WARN, DOLPHIN_TAG, "Getting ID for file: %s", filename.c_str());
DiscIO::IVolume* pVolume = DiscIO::CreateVolumeFromFilename(filename); std::unique_ptr<DiscIO::IVolume> volume(DiscIO::CreateVolumeFromFilename(filename));
if (pVolume != nullptr) if (volume == nullptr)
{ return std::string();
std::string id = pVolume->GetUniqueID();
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Game ID: %s", id.c_str());
return id; std::string id = volume->GetUniqueID();
} __android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Game ID: %s", id.c_str());
return std::string (""); return id;
} }
static std::string GetCompany(std::string filename) static std::string GetCompany(std::string filename)
{ {
__android_log_print(ANDROID_LOG_WARN, DOLPHIN_TAG, "Getting Company for file: %s", filename.c_str()); __android_log_print(ANDROID_LOG_WARN, DOLPHIN_TAG, "Getting Company for file: %s", filename.c_str());
DiscIO::IVolume* pVolume = DiscIO::CreateVolumeFromFilename(filename); std::unique_ptr<DiscIO::IVolume> volume(DiscIO::CreateVolumeFromFilename(filename));
if (pVolume != nullptr) if (volume == nullptr)
{ return std::string();
std::string company = DiscIO::GetCompanyFromID(pVolume->GetMakerID());
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Company: %s", company.c_str()); std::string company = DiscIO::GetCompanyFromID(volume->GetMakerID());
return company; __android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Company: %s", company.c_str());
} return company;
return std::string ("");
} }
static u64 GetFileSize(std::string filename) static u64 GetFileSize(std::string filename)
{ {
__android_log_print(ANDROID_LOG_WARN, DOLPHIN_TAG, "Getting size of file: %s", filename.c_str()); __android_log_print(ANDROID_LOG_WARN, DOLPHIN_TAG, "Getting size of file: %s", filename.c_str());
DiscIO::IVolume* pVolume = DiscIO::CreateVolumeFromFilename(filename); std::unique_ptr<DiscIO::IVolume> volume(DiscIO::CreateVolumeFromFilename(filename));
if (pVolume != nullptr) if (volume == nullptr)
{ return -1;
u64 size = pVolume->GetSize();
// Causes a warning because size is u64, not 'long unsigned'
//__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Size: %lu", size);
return size; return volume->GetSize();
}
return -1;
} }
static std::string GetJString(JNIEnv *env, jstring jstr) static std::string GetJString(JNIEnv *env, jstring jstr)