//! returns the base part of a filename, i.e. all except for the directory //! part. If no directory path is prefixed, the full name is returned. io::path CFileSystem::getFileBasename(const io::path& filename, bool keepExtension) const { // find last forward or backslash s32 lastSlash = filename.findLast('/'); const s32 lastBackSlash = filename.findLast('\\'); lastSlash = core::max_(lastSlash, lastBackSlash); // get number of chars after last dot s32 end = 0; if (!keepExtension) { // take care to search only after last slash to check only for // dots in the filename end = filename.findLast('.'); if (end == -1 || end < lastSlash) end=0; else end = filename.size()-end; } if ((u32)lastSlash < filename.size()) return filename.subString(lastSlash+1, filename.size()-lastSlash-1-end); else if (end != 0) return filename.subString(0, filename.size()-end); else return filename; }
//! returns the directory part of a filename, i.e. all until the first //! slash or backslash, excluding it. If no directory path is prefixed, a '.' //! is returned. io::path CFileSystem::getFileDir(const io::path& filename) const { // find last forward or backslash s32 lastSlash = filename.findLast('/'); const s32 lastBackSlash = filename.findLast('\\'); lastSlash = lastSlash > lastBackSlash ? lastSlash : lastBackSlash; if ((u32)lastSlash < filename.size()) return filename.subString(0, lastSlash); else return "."; }
io::path CFileSystem::getAbsolutePath(const io::path& filename) const { fschar_t *p=0; #if defined(_IRR_WINDOWS_CE_PLATFORM_) return filename; #elif defined(_IRR_WINDOWS_API_) #if defined(_IRR_WCHAR_FILESYSTEM ) c16 fpath[_MAX_PATH]; p = _wfullpath(fpath, filename.c_str(), _MAX_PATH); #else c8 fpath[_MAX_PATH]; p = _fullpath(fpath, filename.c_str(), _MAX_PATH); #endif #elif (defined(_IRR_POSIX_API_) || defined(_IRR_OSX_PLATFORM_)) c8 fpath[4096]; fpath[0]=0; p = realpath(filename.c_str(), fpath); if (!p) { // content in fpath is undefined at this point if (!fpath[0]) // seems like fpath wasn't altered { // at least remove a ./ prefix if ('.'==filename[0] && '/'==filename[1]) return filename.subString(2, filename.size()-2); else return filename; } else return io::path(fpath); } #endif return io::path(p); }
virtual bool isALoadableFileExtension (const io::path &filename) const { return filename.subString(filename.size()-3, filename.size()) == "png"; }