2015-07-04 06:03:59 +00:00
|
|
|
#include "HECL/HECL.hpp"
|
2015-07-06 01:35:08 +00:00
|
|
|
|
|
|
|
namespace HECL
|
|
|
|
{
|
2015-08-06 19:10:12 +00:00
|
|
|
unsigned VerbosityLevel = 0;
|
2015-07-06 01:35:08 +00:00
|
|
|
LogVisor::LogModule LogModule("HECL");
|
2015-08-05 01:54:35 +00:00
|
|
|
|
|
|
|
void SanitizePath(std::string& path)
|
|
|
|
{
|
2015-11-11 03:40:13 +00:00
|
|
|
if (path.empty())
|
|
|
|
return;
|
2015-08-05 01:54:35 +00:00
|
|
|
path.erase(std::remove(path.begin(), path.end(), '\n'), path.end());
|
|
|
|
path.erase(std::remove(path.begin(), path.end(), '\r'), path.end());
|
2015-11-11 03:40:13 +00:00
|
|
|
std::string::iterator p1 = path.begin();
|
2015-11-11 04:01:36 +00:00
|
|
|
bool ic = false;
|
2015-11-11 03:40:13 +00:00
|
|
|
std::transform(path.begin(), path.end(), path.begin(), [&](const char a) -> char {
|
|
|
|
++p1;
|
2015-11-11 04:01:36 +00:00
|
|
|
if (ic)
|
|
|
|
{
|
|
|
|
ic = false;
|
|
|
|
return a;
|
|
|
|
}
|
2015-08-05 02:40:54 +00:00
|
|
|
static const std::string illegals {"<>?*\"|"};
|
|
|
|
if (illegals.find_first_of(a) != std::string::npos)
|
|
|
|
return '_';
|
2015-11-11 03:40:13 +00:00
|
|
|
if (a == '\\' && (p1 == path.end() || *p1 != '\\'))
|
2015-11-11 04:01:36 +00:00
|
|
|
{
|
|
|
|
ic = true;
|
2015-11-11 03:40:13 +00:00
|
|
|
return '/';
|
2015-11-11 04:01:36 +00:00
|
|
|
}
|
2015-08-05 02:40:54 +00:00
|
|
|
return a;
|
|
|
|
});
|
2015-08-05 01:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SanitizePath(std::wstring& path)
|
|
|
|
{
|
2015-11-11 03:40:13 +00:00
|
|
|
if (path.empty())
|
|
|
|
return;
|
2015-08-05 01:54:35 +00:00
|
|
|
path.erase(std::remove(path.begin(), path.end(), L'\n'), path.end());
|
|
|
|
path.erase(std::remove(path.begin(), path.end(), L'\r'), path.end());
|
2015-11-11 03:40:13 +00:00
|
|
|
std::wstring::iterator p1 = path.begin();
|
2015-11-11 04:01:36 +00:00
|
|
|
bool ic = false;
|
2015-11-11 03:40:13 +00:00
|
|
|
std::transform(path.begin(), path.end(), path.begin(), [&](const wchar_t a) -> wchar_t {
|
|
|
|
++p1;
|
2015-11-11 04:01:36 +00:00
|
|
|
if (ic)
|
|
|
|
{
|
|
|
|
ic = false;
|
|
|
|
return a;
|
|
|
|
}
|
2015-08-05 02:40:54 +00:00
|
|
|
static const std::wstring illegals {L"<>?*\"|"};
|
|
|
|
if (illegals.find_first_of(a) != std::wstring::npos)
|
|
|
|
return L'_';
|
2015-11-11 03:40:13 +00:00
|
|
|
if (a == L'\\' && (p1 == path.end() || *p1 != L'\\'))
|
2015-11-11 04:01:36 +00:00
|
|
|
{
|
|
|
|
ic = true;
|
2015-11-11 03:40:13 +00:00
|
|
|
return L'/';
|
2015-11-11 04:01:36 +00:00
|
|
|
}
|
2015-08-05 02:40:54 +00:00
|
|
|
return a;
|
|
|
|
});
|
2015-08-05 01:54:35 +00:00
|
|
|
}
|
|
|
|
|
2015-10-01 00:40:06 +00:00
|
|
|
bool IsPathPNG(const HECL::ProjectPath& path)
|
|
|
|
{
|
|
|
|
FILE* fp = HECL::Fopen(path.getAbsolutePath().c_str(), _S("rb"));
|
|
|
|
if (!fp)
|
|
|
|
return false;
|
|
|
|
uint32_t buf;
|
|
|
|
if (fread(&buf, 1, 4, fp) != 4)
|
|
|
|
{
|
|
|
|
fclose(fp);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
buf = HECL::SBig(buf);
|
|
|
|
if (buf == 0x89504e47)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsPathBlend(const HECL::ProjectPath& path)
|
|
|
|
{
|
2015-10-07 01:16:54 +00:00
|
|
|
const SystemChar* lastCompExt = path.getLastComponentExt();
|
|
|
|
if (!lastCompExt || HECL::StrCmp(lastCompExt, _S("blend")))
|
|
|
|
return false;
|
2015-10-01 00:40:06 +00:00
|
|
|
FILE* fp = HECL::Fopen(path.getAbsolutePath().c_str(), _S("rb"));
|
|
|
|
if (!fp)
|
|
|
|
return false;
|
|
|
|
uint32_t buf;
|
|
|
|
if (fread(&buf, 1, 4, fp) != 4)
|
|
|
|
{
|
|
|
|
fclose(fp);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
buf = HECL::SLittle(buf);
|
|
|
|
if (buf == 0x4e454c42 || buf == 0x88b1f)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsPathYAML(const HECL::ProjectPath& path)
|
|
|
|
{
|
|
|
|
const SystemChar* lastCompExt = path.getLastComponentExt();
|
|
|
|
if (!lastCompExt)
|
|
|
|
return false;
|
|
|
|
if (!HECL::StrCmp(lastCompExt, _S("yaml")) ||
|
|
|
|
!HECL::StrCmp(lastCompExt, _S("yml")))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-06 01:35:08 +00:00
|
|
|
}
|