2006-07-18 12:08:40 +00:00
|
|
|
#include <boost/filesystem/operations.hpp>
|
|
|
|
#include "MemoryCard.h"
|
|
|
|
|
|
|
|
using namespace std;
|
2008-12-15 02:57:21 +00:00
|
|
|
namespace filesystem = boost::filesystem;
|
2006-07-18 12:08:40 +00:00
|
|
|
|
|
|
|
CMemoryCard::CMemoryCard(filesystem::path& BasePath) :
|
|
|
|
m_BasePath(BasePath)
|
|
|
|
{
|
|
|
|
ScanSaves();
|
|
|
|
}
|
|
|
|
|
|
|
|
CMemoryCard::~CMemoryCard()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-07-19 19:56:16 +00:00
|
|
|
size_t CMemoryCard::GetSaveCount() const
|
2006-07-18 12:08:40 +00:00
|
|
|
{
|
2006-07-19 19:56:16 +00:00
|
|
|
return m_Saves.size();
|
2006-07-18 12:08:40 +00:00
|
|
|
}
|
|
|
|
|
2006-07-19 19:56:16 +00:00
|
|
|
const CSave* CMemoryCard::GetSaveByIndex(size_t nIndex) const
|
2006-07-18 12:08:40 +00:00
|
|
|
{
|
2006-07-19 19:56:16 +00:00
|
|
|
return &m_Saves[nIndex];
|
2006-07-18 12:08:40 +00:00
|
|
|
}
|
|
|
|
|
2011-12-22 05:59:15 +00:00
|
|
|
filesystem::path CMemoryCard::GetBasePath() const
|
2006-07-18 12:08:40 +00:00
|
|
|
{
|
2011-12-22 05:59:15 +00:00
|
|
|
return m_BasePath;
|
2006-07-18 12:08:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMemoryCard::RefreshContents()
|
|
|
|
{
|
|
|
|
m_Saves.clear();
|
|
|
|
ScanSaves();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMemoryCard::ScanSaves()
|
|
|
|
{
|
|
|
|
filesystem::directory_iterator itEnd;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
for(filesystem::directory_iterator itElement(m_BasePath);
|
|
|
|
itElement != itEnd;
|
|
|
|
itElement++)
|
|
|
|
{
|
2007-07-20 14:49:36 +00:00
|
|
|
filesystem::path Element(*itElement);
|
|
|
|
|
|
|
|
if(filesystem::is_directory(Element))
|
2006-07-18 12:08:40 +00:00
|
|
|
{
|
|
|
|
filesystem::path IconSysPath;
|
2007-07-20 14:49:36 +00:00
|
|
|
IconSysPath = Element / "icon.sys";
|
2006-07-18 12:08:40 +00:00
|
|
|
|
|
|
|
//Check if 'icon.sys' exists in this directory
|
|
|
|
if(filesystem::exists(IconSysPath))
|
|
|
|
{
|
|
|
|
//Create new Save
|
2007-07-20 14:49:36 +00:00
|
|
|
m_Saves.push_back(new CSave(Element));
|
2006-07-18 12:08:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(const exception& Exception)
|
|
|
|
{
|
|
|
|
printf("Exception caught in CMemoryCard::ScanSaves: %s\r\n", Exception.what());
|
|
|
|
}
|
|
|
|
}
|