2012-07-22 18:02:13 +03:00
|
|
|
#include "StdInc.h"
|
|
|
|
#include "CFileInfo.h"
|
|
|
|
|
|
|
|
CFileInfo::CFileInfo() : name("")
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-08-08 11:25:27 +03:00
|
|
|
CFileInfo::CFileInfo(std::string name)
|
|
|
|
: name(std::move(name))
|
2012-07-22 18:02:13 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CFileInfo::exists() const
|
|
|
|
{
|
|
|
|
return boost::filesystem::exists(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CFileInfo::isDirectory() const
|
|
|
|
{
|
|
|
|
return boost::filesystem::is_directory(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CFileInfo::setName(const std::string & name)
|
|
|
|
{
|
|
|
|
this->name = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CFileInfo::getName() const
|
|
|
|
{
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CFileInfo::getPath() const
|
|
|
|
{
|
|
|
|
size_t found = name.find_last_of("/\\");
|
|
|
|
return name.substr(0, found);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CFileInfo::getExtension() const
|
|
|
|
{
|
|
|
|
// Get position of file extension dot
|
2014-08-21 23:26:28 +03:00
|
|
|
size_t dotPos = name.find_last_of('.');
|
2012-07-22 18:02:13 +03:00
|
|
|
|
2014-08-21 23:26:28 +03:00
|
|
|
if(dotPos != std::string::npos)
|
2012-07-22 18:02:13 +03:00
|
|
|
return name.substr(dotPos);
|
2014-08-21 23:26:28 +03:00
|
|
|
|
|
|
|
return "";
|
2012-07-22 18:02:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string CFileInfo::getFilename() const
|
|
|
|
{
|
2014-08-21 23:26:28 +03:00
|
|
|
const size_t found = name.find_last_of("/\\");
|
2012-07-22 18:02:13 +03:00
|
|
|
return name.substr(found + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CFileInfo::getStem() const
|
|
|
|
{
|
|
|
|
std::string rslt = name;
|
|
|
|
|
|
|
|
// Remove file extension
|
2014-08-21 23:26:28 +03:00
|
|
|
const size_t dotPos = name.find_last_of('.');
|
2012-07-22 18:02:13 +03:00
|
|
|
|
2014-08-21 23:26:28 +03:00
|
|
|
if(dotPos != std::string::npos)
|
2012-07-22 18:02:13 +03:00
|
|
|
rslt.erase(dotPos);
|
|
|
|
|
2012-08-01 15:02:54 +03:00
|
|
|
return rslt;
|
2012-07-22 18:02:13 +03:00
|
|
|
}
|
|
|
|
|
2012-08-01 15:02:54 +03:00
|
|
|
std::string CFileInfo::getBaseName() const
|
|
|
|
{
|
2014-08-21 23:26:28 +03:00
|
|
|
size_t begin = name.find_last_of("/\\");
|
|
|
|
size_t end = name.find_last_of(".");
|
2012-08-01 15:02:54 +03:00
|
|
|
|
|
|
|
if(begin == std::string::npos)
|
|
|
|
begin = 0;
|
2012-08-07 14:28:52 +03:00
|
|
|
else
|
2014-08-21 23:26:28 +03:00
|
|
|
++begin;
|
|
|
|
|
|
|
|
if (end < begin)
|
|
|
|
end = std::string::npos;
|
2012-08-01 15:02:54 +03:00
|
|
|
|
2014-08-21 23:26:28 +03:00
|
|
|
size_t len = (end == std::string::npos ? std::string::npos : end - begin);
|
|
|
|
return name.substr(begin, len);
|
2012-08-01 15:02:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
EResType::Type CFileInfo::getType() const
|
2012-07-22 18:02:13 +03:00
|
|
|
{
|
|
|
|
return EResTypeHelper::getTypeFromExtension(getExtension());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::time_t CFileInfo::getDate() const
|
|
|
|
{
|
|
|
|
return boost::filesystem::last_write_time(name);
|
|
|
|
}
|