Play-/Source/saves/MemoryCard.cpp

64 lines
1.2 KiB
C++
Raw Permalink Normal View History

#include "MemoryCard.h"
2019-10-16 20:51:11 -04:00
CMemoryCard::CMemoryCard(const fs::path& basePath)
2018-04-30 21:01:23 +01:00
: m_basePath(basePath)
{
ScanSaves();
}
size_t CMemoryCard::GetSaveCount() const
{
return m_saves.size();
}
const CSave* CMemoryCard::GetSaveByIndex(size_t index) const
{
return m_saves[index].get();
}
2019-10-16 20:51:11 -04:00
fs::path CMemoryCard::GetBasePath() const
{
return m_basePath;
}
void CMemoryCard::RefreshContents()
{
m_saves.clear();
ScanSaves();
}
void CMemoryCard::ScanSaves()
{
try
{
2019-10-16 20:51:11 -04:00
fs::directory_iterator endIterator;
for(fs::directory_iterator elementIterator(m_basePath);
2018-04-30 21:01:23 +01:00
elementIterator != endIterator; elementIterator++)
{
2019-10-16 20:51:11 -04:00
fs::path element(*elementIterator);
2019-10-16 20:51:11 -04:00
if(fs::is_directory(element))
{
2019-10-16 20:51:11 -04:00
fs::path iconSysPath = element / "icon.sys";
//Check if 'icon.sys' exists in this directory
2019-10-16 20:51:11 -04:00
if(fs::exists(iconSysPath))
{
try
{
m_saves.push_back(std::make_shared<CSave>(element));
}
catch(const std::exception& exception)
{
printf("Failed to create save: %s\r\n", exception.what());
}
}
}
}
}
catch(const std::exception& exception)
{
printf("Exception caught in CMemoryCard::ScanSaves: %s\r\n", exception.what());
}
}