2006-07-18 12:08:40 +00:00
|
|
|
#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"
|
2019-10-17 21:09:51 -04:00
|
|
|
#include "FilesystemUtils.h"
|
2006-07-18 12:08:40 +00:00
|
|
|
|
2019-10-16 20:51:11 -04:00
|
|
|
CSave::CSave(const fs::path& basePath)
|
2018-04-30 21:01:23 +01:00
|
|
|
: m_basePath(basePath)
|
2006-07-18 12:08:40 +00:00
|
|
|
{
|
2019-10-16 20:51:11 -04:00
|
|
|
auto 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
|
|
|
|
2019-10-17 21:09:51 -04:00
|
|
|
m_nLastModificationTime = Framework::ConvertFsTimeToSystemTime(fs::last_write_time(iconSysPath));
|
2006-07-18 12:08:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2019-10-16 20:51:11 -04:00
|
|
|
fs::directory_iterator itEnd;
|
2010-10-15 02:39:56 +00:00
|
|
|
unsigned int nSize = 0;
|
2006-07-18 12:08:40 +00:00
|
|
|
|
2019-10-16 20:51:11 -04:00
|
|
|
for(fs::directory_iterator itElement(m_basePath);
|
2018-04-30 21:01:23 +01:00
|
|
|
itElement != itEnd;
|
|
|
|
itElement++)
|
2006-07-18 12:08:40 +00:00
|
|
|
{
|
2019-10-16 20:51:11 -04:00
|
|
|
if(!fs::is_directory(*itElement))
|
2006-07-18 12:08:40 +00:00
|
|
|
{
|
2019-10-16 20:51:11 -04:00
|
|
|
nSize += fs::file_size(*itElement);
|
2006-07-18 12:08:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nSize;
|
|
|
|
}
|
|
|
|
|
2019-10-16 20:51:11 -04:00
|
|
|
fs::path CSave::GetPath() const
|
2006-07-18 12:08:40 +00:00
|
|
|
{
|
2011-12-30 22:49:52 +00:00
|
|
|
return m_basePath;
|
|
|
|
}
|
|
|
|
|
2019-10-16 20:51:11 -04:00
|
|
|
fs::path CSave::GetIconPath(const ICONTYPE& iconType) const
|
2011-12-30 22:49:52 +00:00
|
|
|
{
|
2019-10-16 20:51:11 -04:00
|
|
|
fs::path iconPath;
|
2011-12-30 22:49:52 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-10-16 20:51:11 -04:00
|
|
|
fs::path CSave::GetNormalIconPath() const
|
2006-07-18 12:08:40 +00:00
|
|
|
{
|
2011-12-30 22:49:52 +00:00
|
|
|
return m_basePath / m_sNormalIconFileName;
|
2006-07-18 12:08:40 +00:00
|
|
|
}
|
|
|
|
|
2019-10-16 20:51:11 -04:00
|
|
|
fs::path CSave::GetDeletingIconPath() const
|
2006-07-22 17:41:19 +00:00
|
|
|
{
|
2011-12-30 22:49:52 +00:00
|
|
|
return m_basePath / m_sDeletingIconFileName;
|
2006-07-22 17:41:19 +00:00
|
|
|
}
|
|
|
|
|
2019-10-16 20:51:11 -04:00
|
|
|
fs::path CSave::GetCopyingIconPath() const
|
2006-07-22 17:41:19 +00:00
|
|
|
{
|
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
|
|
|
}
|