Merge pull request #1168 from lioncash/unique

CoreParameter: Use unique_ptrs over raw pointers.
This commit is contained in:
skidau 2014-09-29 13:55:00 +10:00
commit 8ae2152093
1 changed files with 13 additions and 14 deletions

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
{ {
@ -279,18 +280,16 @@ bool SCoreStartupParameter::AutoSetup(EBootBS2 _BootBS2)
// Use the TitleIDhex for name and/or unique ID if launching from nand folder // Use the TitleIDhex for name and/or unique ID if launching from nand folder
// or if it is not ascii characters (specifically sysmenu could potentially apply to other things) // or if it is not ascii characters (specifically sysmenu could potentially apply to other things)
char titleidstr[17]; std::string titleidstr = StringFromFormat("%016" PRIx64, ContentLoader.GetTitleID());
snprintf(titleidstr, 17, "%016" PRIx64, ContentLoader.GetTitleID());
if (!m_strName.length()) if (m_strName.empty())
{ {
m_strName = titleidstr; m_strName = titleidstr;
} }
if (!m_strUniqueID.length()) if (m_strUniqueID.empty())
{ {
m_strUniqueID = titleidstr; m_strUniqueID = titleidstr;
} }
} }
else else
{ {