diff --git a/code/nel/include/nel/misc/path.h b/code/nel/include/nel/misc/path.h index ff7711b06..fed90efd5 100644 --- a/code/nel/include/nel/misc/path.h +++ b/code/nel/include/nel/misc/path.h @@ -514,6 +514,12 @@ public: */ static std::string makePathAbsolute (const std::string &relativePath, const std::string &directory ); + /** Return if a path is absolute or not. + * \param path - The path + * returns true if path is absolute or false if relative. + */ + static bool isAbsolutePath (const std::string &path); + /** If File in this list is added more than one in an addSearchPath, it doesn't launch a warning. */ static void addIgnoredDoubleFile(const std::string &ignoredFile); diff --git a/code/nel/src/misc/path.cpp b/code/nel/src/misc/path.cpp index de36efa56..19403c964 100644 --- a/code/nel/src/misc/path.cpp +++ b/code/nel/src/misc/path.cpp @@ -2597,6 +2597,25 @@ std::string CPath::makePathAbsolute( const std::string &relativePath, const std: return npath; } +bool CPath::isAbsolutePath(const std::string &path) +{ + if (path.empty()) return false; + +#ifdef NL_OS_WINDOWS + // Windows root of current disk. Eg.: "\" or + // Windows network address. Eg.: \\someshare\path + if (path[0] == '\\') return true; + + // Normal Windows absolute path. Eg.: C:\something + if (path.length() > 2 && isalpha(path[0]) && (path[1] == ':' ) && ((path[2] == '\\') || (path[2] == '/' ))) return true; +#endif + + // Unix filesystem absolute path (works also under Windows) + if (path[0] == '/') return true; + + return false; +} + bool CFile::setRWAccess(const std::string &filename) { #ifdef NL_OS_WINDOWS