mirror of https://github.com/AxioDL/metaforce.git
Merge branch 'master' of https://github.com/RetroView/hecl
This commit is contained in:
commit
b8391c7a5f
|
@ -122,6 +122,9 @@ inline std::string operator+(const char* lhs, const SystemStringView& rhs) {retu
|
||||||
typedef struct stat Sstat;
|
typedef struct stat Sstat;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void SanitizePath(std::string& path);
|
||||||
|
void SanitizePath(std::wstring& path);
|
||||||
|
|
||||||
static inline void Unlink(const SystemChar* file)
|
static inline void Unlink(const SystemChar* file)
|
||||||
{
|
{
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
|
@ -395,8 +398,12 @@ protected:
|
||||||
std::string m_utf8RelPath;
|
std::string m_utf8RelPath;
|
||||||
#endif
|
#endif
|
||||||
ProjectPath(const SystemString& projRoot)
|
ProjectPath(const SystemString& projRoot)
|
||||||
: m_projRoot(projRoot), m_absPath(projRoot), m_relPath(_S(".")), m_hash(m_relPath)
|
: m_projRoot(projRoot), m_absPath(projRoot), m_relPath(_S("."))
|
||||||
{
|
{
|
||||||
|
SanitizePath(m_projRoot);
|
||||||
|
SanitizePath(m_relPath);
|
||||||
|
SanitizePath(m_absPath);
|
||||||
|
m_hash = Hash(m_relPath);
|
||||||
#if HECL_UCS2
|
#if HECL_UCS2
|
||||||
m_utf8AbsPath = WideToUTF8(m_absPath);
|
m_utf8AbsPath = WideToUTF8(m_absPath);
|
||||||
m_utf8RelPath = ".";
|
m_utf8RelPath = ".";
|
||||||
|
@ -420,10 +427,10 @@ public:
|
||||||
* @param parentPath previously constructed ProjectPath which ultimately connects to a ProjectRootPath
|
* @param parentPath previously constructed ProjectPath which ultimately connects to a ProjectRootPath
|
||||||
* @param path valid filesystem-path (relative or absolute) to subpath
|
* @param path valid filesystem-path (relative or absolute) to subpath
|
||||||
*/
|
*/
|
||||||
ProjectPath(const ProjectPath& parentPath, const SystemString& path) {assign(parentPath, path);}
|
/* ProjectPath(const ProjectPath& parentPath, const SystemString& path) {assign(parentPath, path);}
|
||||||
void assign(const ProjectPath& parentPath, const SystemString& path);
|
void assign(const ProjectPath& parentPath, const SystemString& path);*/
|
||||||
|
|
||||||
#if HECL_UCS2
|
#ifndef HECL_UCS2
|
||||||
ProjectPath(const ProjectPath& parentPath, const std::string& path) {assign(parentPath, path);}
|
ProjectPath(const ProjectPath& parentPath, const std::string& path) {assign(parentPath, path);}
|
||||||
void assign(const ProjectPath& parentPath, const std::string& path);
|
void assign(const ProjectPath& parentPath, const std::string& path);
|
||||||
#endif
|
#endif
|
||||||
|
@ -541,7 +548,6 @@ public:
|
||||||
relTarget += target.m_relPath;
|
relTarget += target.m_relPath;
|
||||||
MakeLink(relTarget.c_str(), m_absPath.c_str());
|
MakeLink(relTarget.c_str(), m_absPath.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief HECL-specific blowfish hash
|
* @brief HECL-specific blowfish hash
|
||||||
* @return unique hash value
|
* @return unique hash value
|
||||||
|
|
|
@ -3,4 +3,29 @@
|
||||||
namespace HECL
|
namespace HECL
|
||||||
{
|
{
|
||||||
LogVisor::LogModule LogModule("HECL");
|
LogVisor::LogModule LogModule("HECL");
|
||||||
|
|
||||||
|
void SanitizePath(std::string& path)
|
||||||
|
{
|
||||||
|
path.erase(std::remove(path.begin(), path.end(), '\n'), path.end());
|
||||||
|
path.erase(std::remove(path.begin(), path.end(), '\r'), path.end());
|
||||||
|
std::transform(path.begin(), path.end(), path.begin(), [](const char a) -> char {
|
||||||
|
static const std::string illegals {"<>?*\"|"};
|
||||||
|
if (illegals.find_first_of(a) != std::string::npos)
|
||||||
|
return '_';
|
||||||
|
return a;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void SanitizePath(std::wstring& path)
|
||||||
|
{
|
||||||
|
path.erase(std::remove(path.begin(), path.end(), L'\n'), path.end());
|
||||||
|
path.erase(std::remove(path.begin(), path.end(), L'\r'), path.end());
|
||||||
|
std::transform(path.begin(), path.end(), path.begin(), [](const wchar_t a) -> wchar_t {
|
||||||
|
static const std::wstring illegals {L"<>?*\"|"};
|
||||||
|
if (illegals.find_first_of(a) != std::wstring::npos)
|
||||||
|
return L'_';
|
||||||
|
return a;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
namespace HECL
|
namespace HECL
|
||||||
{
|
{
|
||||||
|
|
||||||
static const SystemRegex regGLOB(_S("\\*"), SystemRegex::ECMAScript|SystemRegex::optimize);
|
static const SystemRegex regGLOB(_S("\\*"), SystemRegex::ECMAScript|SystemRegex::optimize);
|
||||||
static const SystemRegex regPATHCOMP(_S("[/\\\\]*([^/\\\\]+)"), SystemRegex::ECMAScript|SystemRegex::optimize);
|
static const SystemRegex regPATHCOMP(_S("[/\\\\]*([^/\\\\]+)"), SystemRegex::ECMAScript|SystemRegex::optimize);
|
||||||
static const SystemRegex regDRIVELETTER(_S("^([^/]*)/"), SystemRegex::ECMAScript|SystemRegex::optimize);
|
static const SystemRegex regDRIVELETTER(_S("^([^/]*)/"), SystemRegex::ECMAScript|SystemRegex::optimize);
|
||||||
|
@ -21,6 +20,7 @@ static SystemString canonRelPath(const SystemString& path)
|
||||||
std::vector<SystemString> comps;
|
std::vector<SystemString> comps;
|
||||||
HECL::SystemRegexMatch matches;
|
HECL::SystemRegexMatch matches;
|
||||||
SystemString in = path;
|
SystemString in = path;
|
||||||
|
SanitizePath(in);
|
||||||
for (; std::regex_search(in, matches, regPATHCOMP) ; in = matches.suffix())
|
for (; std::regex_search(in, matches, regPATHCOMP) ; in = matches.suffix())
|
||||||
{
|
{
|
||||||
const SystemString& match = matches[1];
|
const SystemString& match = matches[1];
|
||||||
|
@ -57,10 +57,15 @@ static SystemString canonRelPath(const SystemString& path)
|
||||||
|
|
||||||
void ProjectPath::assign(const ProjectPath& parentPath, const SystemString& path)
|
void ProjectPath::assign(const ProjectPath& parentPath, const SystemString& path)
|
||||||
{
|
{
|
||||||
|
SystemString in = path;
|
||||||
m_projRoot = parentPath.m_projRoot;
|
m_projRoot = parentPath.m_projRoot;
|
||||||
m_relPath = canonRelPath(parentPath.m_relPath + _S('/') + path);
|
m_relPath = canonRelPath(parentPath.m_relPath + _S('/') + in);
|
||||||
m_absPath = parentPath.m_projRoot + _S('/') + m_relPath;
|
m_absPath = parentPath.m_projRoot + _S('/') + m_relPath;
|
||||||
|
SanitizePath(m_projRoot);
|
||||||
|
SanitizePath(m_relPath);
|
||||||
|
SanitizePath(m_absPath);
|
||||||
m_hash = Hash(m_relPath);
|
m_hash = Hash(m_relPath);
|
||||||
|
|
||||||
#if HECL_UCS2
|
#if HECL_UCS2
|
||||||
m_utf8AbsPath = WideToUTF8(m_absPath);
|
m_utf8AbsPath = WideToUTF8(m_absPath);
|
||||||
m_utf8RelPath = WideToUTF8(m_relPath);
|
m_utf8RelPath = WideToUTF8(m_relPath);
|
||||||
|
@ -70,10 +75,14 @@ void ProjectPath::assign(const ProjectPath& parentPath, const SystemString& path
|
||||||
#if HECL_UCS2
|
#if HECL_UCS2
|
||||||
void ProjectPath::assign(const ProjectPath& parentPath, const std::string& path)
|
void ProjectPath::assign(const ProjectPath& parentPath, const std::string& path)
|
||||||
{
|
{
|
||||||
|
std::string in = path;
|
||||||
m_projRoot = parentPath.m_projRoot;
|
m_projRoot = parentPath.m_projRoot;
|
||||||
std::wstring wpath = UTF8ToWide(path);
|
std::wstring wpath = UTF8ToWide(in);
|
||||||
m_relPath = canonRelPath(parentPath.m_relPath + _S('/') + wpath);
|
m_relPath = canonRelPath(parentPath.m_relPath + _S('/') + wpath);
|
||||||
m_absPath = parentPath.m_projRoot + _S('/') + m_relPath;
|
m_absPath = parentPath.m_projRoot + _S('/') + m_relPath;
|
||||||
|
SanitizePath(m_projRoot);
|
||||||
|
SanitizePath(m_relPath);
|
||||||
|
SanitizePath(m_absPath);
|
||||||
m_hash = Hash(m_relPath);
|
m_hash = Hash(m_relPath);
|
||||||
m_utf8AbsPath = WideToUTF8(m_absPath);
|
m_utf8AbsPath = WideToUTF8(m_absPath);
|
||||||
m_utf8RelPath = WideToUTF8(m_relPath);
|
m_utf8RelPath = WideToUTF8(m_relPath);
|
||||||
|
|
Loading…
Reference in New Issue