2016-01-12 19:08:41 +00:00
|
|
|
extern "C"
|
|
|
|
|
{
|
|
|
|
|
#include "../platform/platform.h"
|
|
|
|
|
#include "../localisation/localisation.h"
|
|
|
|
|
#include "../util/util.h"
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-29 00:06:02 +00:00
|
|
|
#include "Math.hpp"
|
2016-01-12 19:08:41 +00:00
|
|
|
#include "Memory.hpp"
|
|
|
|
|
#include "Path.hpp"
|
|
|
|
|
#include "String.hpp"
|
|
|
|
|
#include "Util.hpp"
|
|
|
|
|
|
|
|
|
|
namespace Path
|
|
|
|
|
{
|
|
|
|
|
utf8 * Append(utf8 * buffer, size_t bufferSize, const utf8 * src)
|
|
|
|
|
{
|
|
|
|
|
return safe_strcat_path(buffer, src, bufferSize);
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-29 00:06:02 +00:00
|
|
|
utf8 * GetFileNameWithoutExtension(utf8 * buffer, size_t bufferSize, const utf8 * path)
|
|
|
|
|
{
|
|
|
|
|
const utf8 * lastDot = nullptr;
|
|
|
|
|
const utf8 * ch = path;
|
|
|
|
|
for (; ch != '\0'; ch++)
|
|
|
|
|
{
|
|
|
|
|
if (*ch == '.')
|
|
|
|
|
{
|
|
|
|
|
lastDot = ch;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (lastDot == nullptr)
|
|
|
|
|
{
|
|
|
|
|
return String::Set(buffer, bufferSize, path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t truncatedLength = Math::Min<size_t>(bufferSize - 1, lastDot - path);
|
|
|
|
|
Memory::Copy(buffer, path, truncatedLength);
|
|
|
|
|
buffer[truncatedLength] = '\0';
|
|
|
|
|
return buffer;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-12 19:08:41 +00:00
|
|
|
utf8 * GetAbsolute(utf8 *buffer, size_t bufferSize, const utf8 * relativePath)
|
|
|
|
|
{
|
2016-01-13 22:37:13 +00:00
|
|
|
#if __WINDOWS__
|
2016-01-12 19:08:41 +00:00
|
|
|
wchar_t * relativePathW = utf8_to_widechar(relativePath);
|
|
|
|
|
wchar_t absolutePathW[MAX_PATH];
|
|
|
|
|
DWORD length = GetFullPathNameW(relativePathW, Util::CountOf(absolutePathW), absolutePathW, NULL);
|
|
|
|
|
Memory::Free(relativePathW);
|
|
|
|
|
if (length == 0)
|
|
|
|
|
{
|
|
|
|
|
return String::Set(buffer, bufferSize, relativePath);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
utf8 * absolutePath = widechar_to_utf8(absolutePathW);
|
|
|
|
|
String::Set(buffer, bufferSize, absolutePath);
|
|
|
|
|
Memory::Free(absolutePath);
|
|
|
|
|
return buffer;
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
utf8 * absolutePath = realpath(relativePath, NULL);
|
|
|
|
|
if (absolutePath == nullptr)
|
|
|
|
|
{
|
|
|
|
|
return String::Set(buffer, bufferSize, relativePath);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
String::Set(buffer, bufferSize, absolutePath);
|
|
|
|
|
Memory::Free(absolutePath);
|
|
|
|
|
return buffer;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2016-01-29 19:39:31 +00:00
|
|
|
|
|
|
|
|
bool Equals(const utf8 * a, const utf8 * b)
|
|
|
|
|
{
|
|
|
|
|
bool ignoreCase = false;
|
|
|
|
|
#if __WINDOWS__
|
|
|
|
|
ignoreCase = true;
|
|
|
|
|
#endif
|
|
|
|
|
return String::Equals(a, b, ignoreCase);
|
|
|
|
|
}
|
2016-01-12 19:08:41 +00:00
|
|
|
}
|