CoreParameter: Use unique_ptr in place of raw pointers

This commit is contained in:
Lioncash 2014-09-27 14:42:59 -04:00
parent 943383c30e
commit 2f4d3961b3

View File

@ -3,6 +3,7 @@
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <cinttypes> #include <cinttypes>
#include <memory>
#include "Common/CDUtils.h" #include "Common/CDUtils.h"
#include "Common/CommonPaths.h" #include "Common/CommonPaths.h"
@ -133,7 +134,7 @@ bool SCoreStartupParameter::AutoSetup(EBootBS2 _BootBS2)
bootDrive) bootDrive)
{ {
m_BootType = BOOT_ISO; m_BootType = BOOT_ISO;
DiscIO::IVolume* pVolume = DiscIO::CreateVolumeFromFilename(m_strFilename); std::unique_ptr<DiscIO::IVolume> pVolume(DiscIO::CreateVolumeFromFilename(m_strFilename));
if (pVolume == nullptr) if (pVolume == nullptr)
{ {
if (bootDrive) if (bootDrive)
@ -151,7 +152,7 @@ bool SCoreStartupParameter::AutoSetup(EBootBS2 _BootBS2)
m_strRevisionSpecificUniqueID = pVolume->GetRevisionSpecificUniqueID(); m_strRevisionSpecificUniqueID = pVolume->GetRevisionSpecificUniqueID();
// Check if we have a Wii disc // Check if we have a Wii disc
bWii = DiscIO::IsVolumeWiiDisc(pVolume); bWii = DiscIO::IsVolumeWiiDisc(pVolume.get());
switch (pVolume->GetCountry()) switch (pVolume->GetCountry())
{ {
case DiscIO::IVolume::COUNTRY_USA: case DiscIO::IVolume::COUNTRY_USA:
@ -182,10 +183,12 @@ bool SCoreStartupParameter::AutoSetup(EBootBS2 _BootBS2)
bNTSC = false; bNTSC = false;
Region = EUR_DIR; Region = EUR_DIR;
break; break;
}else return false; }
else
{
return false;
}
} }
delete pVolume;
} }
else if (!strcasecmp(Extension.c_str(), ".elf")) else if (!strcasecmp(Extension.c_str(), ".elf"))
{ {
@ -209,17 +212,16 @@ bool SCoreStartupParameter::AutoSetup(EBootBS2 _BootBS2)
bNTSC = true; bNTSC = true;
m_BootType = BOOT_DFF; m_BootType = BOOT_DFF;
FifoDataFile *ddfFile = FifoDataFile::Load(m_strFilename, true); std::unique_ptr<FifoDataFile> ddfFile(FifoDataFile::Load(m_strFilename, true));
if (ddfFile) if (ddfFile)
{ {
bWii = ddfFile->GetIsWii(); bWii = ddfFile->GetIsWii();
delete ddfFile;
} }
} }
else if (DiscIO::CNANDContentManager::Access().GetNANDLoader(m_strFilename).IsValid()) else if (DiscIO::CNANDContentManager::Access().GetNANDLoader(m_strFilename).IsValid())
{ {
const DiscIO::IVolume* pVolume = DiscIO::CreateVolumeFromFilename(m_strFilename); std::unique_ptr<DiscIO::IVolume> pVolume(DiscIO::CreateVolumeFromFilename(m_strFilename));
const DiscIO::INANDContentLoader& ContentLoader = DiscIO::CNANDContentManager::Access().GetNANDLoader(m_strFilename); const DiscIO::INANDContentLoader& ContentLoader = DiscIO::CNANDContentManager::Access().GetNANDLoader(m_strFilename);
if (ContentLoader.GetContentByIndex(ContentLoader.GetBootIndex()) == nullptr) if (ContentLoader.GetContentByIndex(ContentLoader.GetBootIndex()) == nullptr)
@ -267,7 +269,6 @@ bool SCoreStartupParameter::AutoSetup(EBootBS2 _BootBS2)
{ {
m_strName = pVolume->GetName(); m_strName = pVolume->GetName();
m_strUniqueID = pVolume->GetUniqueID(); m_strUniqueID = pVolume->GetUniqueID();
delete pVolume;
} }
else else
{ {
@ -290,7 +291,6 @@ bool SCoreStartupParameter::AutoSetup(EBootBS2 _BootBS2)
{ {
m_strUniqueID = titleidstr; m_strUniqueID = titleidstr;
} }
} }
else else
{ {