Commit 14627c95 authored by Ivan Dokunov's avatar Ivan Dokunov

Added implementation for resolvePath in CFileSystem

parent 69fc57ed
......@@ -25,6 +25,19 @@ HANDLE CFileSystem::getFileHandle(const char *szPath)
NULL);
}
bool CFileSystem::isAbsolutePath(const char *szPath)
{
while (szPath != 0)
{
if (*szPath == ':' && *(szPath + 1) == '/')
{
return true;
}
++szPath;
}
return false;
}
UINT CFileSystem::addRoot(const char *szPath, int iPriority)
{
m_filePaths.push_back(String(szPath));
......@@ -53,7 +66,34 @@ void CFileSystem::setWritableRoot(UINT id)
bool CFileSystem::resolvePath(const char *szPath, char *szOut, int iOutMax)
{
assert(!"No Implementation");
int len = 0;
if (isAbsolutePath(szPath))
{
len = strlen(szPath) + 1;
CHECK_SIZE(len, iOutMax);
memcpy(szOut, szPath, len);
return true;
}
String buff;
for (UINT i = 0, l = m_filePaths.size(); i < l; ++i)
{
buff = (m_filePaths[0] + '/' + szPath);
if (fileExists(buff.c_str()) && isFile(buff.c_str()))
{
CHECK_SIZE(len, iOutMax);
len = buff.length() + 1;
memcpy(szOut, buff.c_str(), len);
return true;
}
}
return false;
}
......
......@@ -10,6 +10,15 @@
handle = nullptr; \
}
//! Сравнение длинны массива и буфера записи
#define CHECK_SIZE(len, buffSize) \
{ \
if (len > buffSize) \
{ \
return false; \
} \
}
//! Проверка существования пути с таким ID
#define FILEID_CHECKED(size) if (size - 1 < id) \
{\
......@@ -24,6 +33,8 @@ private:
HANDLE getFileHandle(const char *szPath);
bool isAbsolutePath(const char* szPath);
//корневые пути и приоритет
Array<String> m_filePaths;
Array<int> m_priority;
......@@ -40,7 +51,6 @@ public:
void setWritableRoot(UINT id) override;
//! No implementation
bool resolvePath(const char *szPath, char *szOut, int iOutMax) override;
bool fileExists(const char *szPath) override;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment