2006-07-18 12:08:40 +00:00
|
|
|
#include <boost/filesystem/operations.hpp>
|
|
|
|
#include <exception>
|
2010-10-15 02:39:56 +00:00
|
|
|
#include "string_cast_sjis.h"
|
2006-07-18 12:08:40 +00:00
|
|
|
#include "Save.h"
|
2011-12-30 22:49:52 +00:00
|
|
|
#include "StdStream.h"
|
|
|
|
#include "StdStreamUtils.h"
|
2006-07-18 12:08:40 +00:00
|
|
|
|
2008-12-15 02:57:21 +00:00
|
|
|
namespace filesystem = boost::filesystem;
|
2006-07-18 12:08:40 +00:00
|
|
|
|
2011-12-30 22:49:52 +00:00
|
|
|
CSave::CSave(const filesystem::path& basePath)
|
|
|
|
: m_basePath(basePath)
|
2006-07-18 12:08:40 +00:00
|
|
|
{
|
2011-12-30 22:49:52 +00:00
|
|
|
filesystem::path iconSysPath = m_basePath / "icon.sys";
|
2006-07-22 17:41:19 +00:00
|
|
|
|
2012-09-06 06:32:15 +00:00
|
|
|
auto iconStream(Framework::CreateInputStdStream(iconSysPath.native()));
|
2006-07-18 12:08:40 +00:00
|
|
|
|
2012-09-06 06:32:15 +00:00
|
|
|
uint32 nMagic = iconStream.Read32();
|
2006-07-18 12:08:40 +00:00
|
|
|
if(nMagic != 0x44325350)
|
|
|
|
{
|
2011-12-30 22:49:52 +00:00
|
|
|
throw std::runtime_error("Invalid 'icon.sys' file.");
|
2006-07-18 12:08:40 +00:00
|
|
|
}
|
|
|
|
|
2012-09-06 06:32:15 +00:00
|
|
|
iconStream.Seek(6, Framework::STREAM_SEEK_SET);
|
|
|
|
m_nSecondLineStartPosition = iconStream.Read16();
|
2006-07-18 12:08:40 +00:00
|
|
|
|
2012-09-06 06:32:15 +00:00
|
|
|
iconStream.Seek(192, Framework::STREAM_SEEK_SET);
|
|
|
|
ReadName(iconStream);
|
2006-07-18 12:08:40 +00:00
|
|
|
|
2011-12-30 22:49:52 +00:00
|
|
|
char sBuffer[64];
|
|
|
|
|
2012-09-06 06:32:15 +00:00
|
|
|
iconStream.Read(sBuffer, 64);
|
2006-07-18 12:08:40 +00:00
|
|
|
m_sNormalIconFileName = sBuffer;
|
|
|
|
|
2012-09-06 06:32:15 +00:00
|
|
|
iconStream.Read(sBuffer, 64);
|
2006-07-22 17:41:19 +00:00
|
|
|
m_sCopyingIconFileName = sBuffer;
|
|
|
|
|
2012-09-06 06:32:15 +00:00
|
|
|
iconStream.Read(sBuffer, 64);
|
2006-07-22 17:41:19 +00:00
|
|
|
m_sDeletingIconFileName = sBuffer;
|
|
|
|
|
2011-12-30 22:49:52 +00:00
|
|
|
m_sId = m_basePath.filename().string();
|
2006-07-21 18:21:51 +00:00
|
|
|
|
2011-12-30 22:49:52 +00:00
|
|
|
m_nLastModificationTime = filesystem::last_write_time(iconSysPath);
|
2006-07-18 12:08:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CSave::~CSave()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const wchar_t* CSave::GetName() const
|
|
|
|
{
|
|
|
|
return m_sName.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* CSave::GetId() const
|
|
|
|
{
|
|
|
|
return m_sId.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int CSave::GetSize() const
|
|
|
|
{
|
|
|
|
filesystem::directory_iterator itEnd;
|
2010-10-15 02:39:56 +00:00
|
|
|
unsigned int nSize = 0;
|
2006-07-18 12:08:40 +00:00
|
|
|
|
2011-12-30 22:49:52 +00:00
|
|
|
for(filesystem::directory_iterator itElement(m_basePath);
|
2006-07-18 12:08:40 +00:00
|
|
|
itElement != itEnd;
|
|
|
|
itElement++)
|
|
|
|
{
|
|
|
|
if(!filesystem::is_directory(*itElement))
|
|
|
|
{
|
|
|
|
nSize += filesystem::file_size(*itElement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
filesystem::path CSave::GetPath() const
|
|
|
|
{
|
2011-12-30 22:49:52 +00:00
|
|
|
return m_basePath;
|
|
|
|
}
|
|
|
|
|
|
|
|
filesystem::path CSave::GetIconPath(const ICONTYPE& iconType) const
|
|
|
|
{
|
|
|
|
filesystem::path iconPath;
|
|
|
|
switch(iconType)
|
|
|
|
{
|
|
|
|
case ICON_NORMAL:
|
|
|
|
iconPath = GetNormalIconPath();
|
|
|
|
break;
|
|
|
|
case ICON_DELETING:
|
|
|
|
iconPath = GetDeletingIconPath();
|
|
|
|
break;
|
|
|
|
case ICON_COPYING:
|
|
|
|
iconPath = GetCopyingIconPath();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return iconPath;
|
2006-07-18 12:08:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
filesystem::path CSave::GetNormalIconPath() const
|
|
|
|
{
|
2011-12-30 22:49:52 +00:00
|
|
|
return m_basePath / m_sNormalIconFileName;
|
2006-07-18 12:08:40 +00:00
|
|
|
}
|
|
|
|
|
2006-07-22 17:41:19 +00:00
|
|
|
filesystem::path CSave::GetDeletingIconPath() const
|
|
|
|
{
|
2011-12-30 22:49:52 +00:00
|
|
|
return m_basePath / m_sDeletingIconFileName;
|
2006-07-22 17:41:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
filesystem::path CSave::GetCopyingIconPath() const
|
|
|
|
{
|
2011-12-30 22:49:52 +00:00
|
|
|
return m_basePath / m_sCopyingIconFileName;
|
2006-07-22 17:41:19 +00:00
|
|
|
}
|
|
|
|
|
2006-07-18 12:08:40 +00:00
|
|
|
size_t CSave::GetSecondLineStartPosition() const
|
|
|
|
{
|
2011-12-30 22:49:52 +00:00
|
|
|
return std::min<size_t>(m_nSecondLineStartPosition / 2, m_sName.length());
|
2006-07-18 12:08:40 +00:00
|
|
|
}
|
|
|
|
|
2006-07-21 18:21:51 +00:00
|
|
|
time_t CSave::GetLastModificationTime() const
|
|
|
|
{
|
|
|
|
return m_nLastModificationTime;
|
|
|
|
}
|
|
|
|
|
2011-12-30 22:49:52 +00:00
|
|
|
void CSave::ReadName(Framework::CStream& inputStream)
|
2006-07-18 12:08:40 +00:00
|
|
|
{
|
|
|
|
char sNameSJIS[68];
|
2011-12-30 22:49:52 +00:00
|
|
|
inputStream.Read(sNameSJIS, 68);
|
2010-10-15 02:39:56 +00:00
|
|
|
m_sName = string_cast_sjis(sNameSJIS);
|
2006-07-18 12:08:40 +00:00
|
|
|
}
|