31 #include <osg/Version> 33 #include <osgDB/Archive> 34 #include <osgDB/FileNameUtils> 35 #include <osgDB/FileUtils> 36 #include <osgDB/ReadFile> 38 #include <sys/types.h> 54 #define stat64 _stati64 55 #define mkdir(x,y) _mkdir((x)) 57 #if defined(_MT) || defined(_DLL) 58 _CRTIMP
extern int * __cdecl _errno(
void);
59 #define errno (*_errno()) 60 #else // ndef _MT && ndef _DLL 61 _CRTIMP
extern int errno;
66 #include <sys/param.h> 81 #define S_ISREG(x) (((x) & S_IFMT) == S_IFREG) 85 #define S_ISDIR(x) (((x) & S_IFMT) == S_IFDIR) 105 const char FileUtils::PATH_SEPARATOR =
'/';
112 if (path.empty())
return "";
113 if (path[0] ==
'/')
return "/";
115 if (path.length()<2)
return "";
116 if (path[1] ==
':')
return path.substr(0, 2);
125 osg::notify(osg::DEBUG_INFO) <<
"osgDB::makeDirectory(): cannot create an empty directory" << std::endl;
130 if (
stat64(path.c_str(), &stbuf) == 0)
138 osg::notify(osg::DEBUG_INFO) <<
"osgDB::makeDirectory(): " <<
139 path <<
" already exists and is not a directory!" << std::endl;
144 std::string dir = path;
145 std::stack<std::string> paths;
153 if (
stat64(dir.c_str(), &stbuf) < 0)
163 osg::notify(osg::DEBUG_INFO) <<
"osgDB::makeDirectory(): " << strerror(errno) << std::endl;
171 dir = osgDB::getFilePath(std::string(dir));
174 while (!paths.empty())
176 std::string dir2 = paths.top();
178 if (mkdir(dir2.c_str(), 0755) < 0)
180 osg::notify(osg::DEBUG_INFO) <<
"osgDB::makeDirectory(): " << strerror(errno) << std::endl;
198 std::string result =
"";
200 #ifdef TR_WIN // If we are in windows 201 std::shared_ptr<FILE> pipe(_popen(cmd,
"r"), _pclose);
203 #ifdef TR_LINUX // If we are in Linux 204 std::shared_ptr<FILE> pipe(popen(cmd,
"r"), pclose);
207 if (!pipe)
throw std::runtime_error(
"popen() failed!");
208 while (!feof(pipe.get()))
210 if (fgets(buffer, 128, pipe.get()) != NULL)
228 FILE* pSrcFile =
nullptr;
238 std::string(
"Source file does not exist: \"") + strSrc +
"\"", __FILE__, __LINE__);
242 pSrcFile = fopen(strSrc.c_str(),
"rb");
243 if (pSrcFile ==
nullptr)
246 std::string(
"Unable to open source file for reading: \"") + strSrc +
"\"", __FILE__, __LINE__);
255 std::string destFile = strDest;
271 destFile = strDest + FileUtils::PATH_SEPARATOR + osgDB::getSimpleFileName(strSrc);
275 destFile = strDest + osgDB::getSimpleFileName(strSrc);
289 std::string(
"Destination file exists, but overwriting is turned off: \"") + destFile +
"\"", __FILE__, __LINE__);
292 pDestFile = fopen(destFile.c_str(),
"wb");
294 if (pDestFile ==
nullptr)
298 std::string(
"Unable to open destination for writing: \"") + destFile +
"\"", __FILE__, __LINE__);
308 stat(strSrc.c_str(), &tagStat);
311 while (i < tagStat.st_size)
313 size_t readCount = fread(buffer, 1, 4096, pSrcFile);
316 size_t numWritten = fwrite(buffer, 1, readCount, pDestFile);
317 if (numWritten < readCount)
320 std::string(
"Unable to write to destinate file: \"") + destFile +
"\"", __FILE__, __LINE__);
353 std::string(
"Source file was not found or is a Directory: \"") + strSrc +
"\"", __FILE__, __LINE__);
358 std::string destFile = strDest;
371 destFile = strDest + FileUtils::PATH_SEPARATOR + osgDB::getSimpleFileName(strSrc);
375 destFile = strDest + osgDB::getSimpleFileName(strSrc);
391 std::string(
"Destination file exists and the call was not set to overwrite: \"") + strDest +
"\"", __FILE__, __LINE__);
395 if (rename(strSrc.c_str(), destFile.c_str()) == 0)
406 FileCopy(strSrc, strDest, bOverwrite);
409 if (unlink(strSrc.c_str()) != 0)
412 std::string(
"Unable to delete \"") + strSrc +
"\" but file copied to new location.", __FILE__, __LINE__);
430 std::string(
"File \"") + strFile +
"\" is a directory.", __FILE__, __LINE__);
433 if (unlink(strFile.c_str()) != 0)
436 std::string(
"Unable to delete \"") + strFile +
"\".", __FILE__, __LINE__);
445 if (!strFile.empty())
447 std::string filename = strFile;
485 std::vector<std::string> tokens;
489 std::vector<std::string>::iterator iter = tokens.begin();
490 std::vector<std::string>::iterator iterEnd = tokens.end();
491 for (; iter != iterEnd; ++iter)
493 std::string& curToken = *iter;
499 else if (curToken ==
"..")
501 size_t lastSlash = absDir.find_last_of(
'/');
502 if (lastSlash != std::string::npos)
504 absDir = absDir.substr(0, lastSlash);
511 absDir.append(curToken);
524 std::string archiveName;
525 std::string fileInArchive;
531 const osgDB::ArchiveExtended* a =
FindArchive(archiveName);
545 std::string choppedStr = strFile;
546 if (strFile.size() > 0 && (strFile[strFile.size() - 1] ==
'\\' ||
547 strFile[strFile.size() - 1] ==
'/'))
549 choppedStr = strFile.substr(0, strFile.length() - 1);
554 choppedStr = osgDB::findFileInDirectory(choppedStr,
"", osgDB::CASE_INSENSITIVE);
557 if (stat(choppedStr.c_str(), &tagStat) != 0)
565 info.
path = osgDB::getFilePath(choppedStr);
566 info.
baseName = osgDB::getSimpleFileName(choppedStr);
567 info.
extension = osgDB::getFileExtension(choppedStr);
568 if (info.
path.empty())
577 info.
size = tagStat.st_size;
584 else if (!archiveName.empty())
603 if (strFileOrDir.empty())
609 for (
unsigned int i = 0; i < strFileOrDir.length(); ++i)
611 if (strFileOrDir[i] ==
'/' || strFileOrDir[i] ==
'\\')
613 if (i > 0 && (strFileOrDir[i - 1] ==
'/' || strFileOrDir[i - 1] ==
'\\'))
615 strFileOrDir.erase(strFileOrDir.begin() + i);
625 strFileOrDir.erase(strFileOrDir.end() - 1);
636 if (strFileOrDir.length() > 0 && strFileOrDir[0] ==
'/')
642 else if (strFileOrDir.length() > 1 && strFileOrDir[1] ==
':')
665 auto buffer =
new char[strDir.length() + 1];
666 strcpy(buffer, strDir.c_str());
667 char* tok = strtok(buffer,
"/");
670 if (strDir[0] ==
'/')
694 tok = strtok(
nullptr,
"/");
697 if (dir[dir.length() - 1] !=
'/') { dir +=
'/'; }
711 std::string filename = path;
742 std::string archiveName;
743 std::string fileInArchive;
747 if (inArchive || !archiveName.empty())
749 osgDB::ArchiveExtended* a =
FindArchive(archiveName);
777 if (chdir(path.c_str()) == -1)
782 char* bufAddress = getcwd(buf, 512);
783 if (buf != bufAddress)
793 std::string message(
"Changed directory to \"");
805 std::string message(
"Pushing Directory \"");
844 throw trUtil::FileUtilIOException(std::string(
"Unable to get the absolute path to a file in an archive. ") + relativePath, __FILE__, __LINE__);
847 std::string dir = relativePath;
870 throw trUtil::FileUtilIOException(std::string(
"Cannot get absolute path for file. Cannot enter directory: ") + relativePath, __FILE__, __LINE__);
878 #if defined(OSG_VERSION_MAJOR) && defined(OSG_VERSION_MINOR) && OSG_VERSION_MAJOR <= 2 && OSG_VERSION_MINOR <= 6 880 std::string::size_type dot = fileName.find_last_of(
'.');
881 if (dot == std::string::npos)
return std::string(
"");
882 return std::string(fileName.begin() + dot, fileName.end());
894 char operator() (
char& elem)
const 896 return tolower(elem);
910 std::string(
"Path not Found: \"") + path +
"\".", __FILE__, __LINE__);
915 std::string(
"Path does not specify a directory: \"") + path +
"\".", __FILE__, __LINE__);
919 std::string archiveName;
920 std::string fileInArchiveName;
921 std::string absoluteFilename = path;
929 const osgDB::ArchiveExtended* a =
FindArchive(archiveName);
937 std::string(
"Archive must be opened to search into: \"") + path +
"\".", __FILE__, __LINE__);
942 dirContents = osgDB::getDirectoryContents(path);
945 if (extensions.empty())
952 DirectoryContents::iterator dirItr = dirContents.begin();
953 while (dirItr != dirContents.end())
955 FileExtensionList::const_iterator extItr = extensions.begin();
956 while (extItr != extensions.end())
959 std::string validExt = (*extItr);
963 filteredContents.push_back((*dirItr));
973 return filteredContents;
983 for (DirectoryContents::const_iterator i = dirCont.begin(); i != dirCont.end(); ++i)
996 const std::string& destPath,
bool bOverwrite)
const 1004 std::string(
"The destination path must be a directory: \"") + destPath +
"\"", __FILE__, __LINE__);
1013 for (DirectoryContents::iterator i = contents.begin(); i != contents.end(); ++i)
1015 if (*i ==
"." || *i ==
"..")
1024 if (destPath.size() >= newSrcPath.size() &&
1025 destPath.substr(0, newSrcPath.size()) == newSrcPath &&
1026 (destPath.size() == newSrcPath.size() || destPath[newSrcPath.size()] ==
PATH_SEPARATOR))
1040 FileCopy(newSrcPath, newDestPath, bOverwrite);
1047 const std::string& destPath,
bool bOverwrite,
bool copyContentsOnly)
const 1052 std::string(
"Source directory does not exist: \"") + srcPath +
"\"", __FILE__, __LINE__);
1060 std::string(
"The destination path must be a directory: \"") + destPath +
"\"", __FILE__, __LINE__);
1072 std::string fullDestPath;
1081 fullDestPath.c_str());
1090 fullDestPath.c_str());
1093 if ((copyContentsOnly && fullSrcPath == fullDestPath)
1094 || (!copyContentsOnly && osgDB::getFilePath(fullSrcPath) == fullDestPath))
1097 std::string(
"The source equals the destination: \"") + srcPath +
"\"", __FILE__, __LINE__);
1100 if (!copyContentsOnly)
1102 const std::string& srcName = osgDB::getSimpleFileName(fullSrcPath);
1105 if (
DirExists(fullDestPath) && !bOverwrite)
1108 std::string(
"Cannot overwrite directory (overwrite flag is false): \"") + srcPath +
"\"",
1109 __FILE__, __LINE__);
1120 "Destination directory \"%s\" created - copyContentsOnly is false.",
1121 fullDestPath.c_str());
1129 "Destination directory \"%s\" exists - copyContentsOnly is true.",
1130 fullDestPath.c_str());
1146 "Attempting to recursively delete %s.", strDir.c_str());
1172 "Directory %s doesn't exist to delete. Ignoring.", strDir.c_str());
1188 "Attempting to delete %s, but not recursively.", strDir.c_str());
1193 if (rmdir(strDir.c_str()) != 0)
1195 if (!bRecursive && errno == ENOTEMPTY)
1199 else if (errno == ENOENT)
1204 "Directory %s doesn't exist to delete. Ignoring.", strDir.c_str());
1211 std::string(
"Unable to delete directory \"") + strDir +
"\":" + strerror(errno), __FILE__, __LINE__);
1227 + strDir +
" is an existing non-directory file.", __FILE__, __LINE__);
1234 if (!
DirExists(osgDB::getFilePath(strDir)))
1237 + strDir +
". Parent directory doesn't exist.", __FILE__, __LINE__);
1260 std::string relativePath;
1262 if (file.empty() || absolutePath.empty())
1269 std::string root1, root2;
1278 std::vector<std::string> absPathVec, filePathVec;
1284 size_t pointOfDivergence = 0;
1286 for (
size_t i = 0; i < filePathVec.size() && i < absPathVec.size(); ++i)
1288 if (filePathVec[i] != absPathVec[i])
1292 ++pointOfDivergence;
1296 for (
size_t i = pointOfDivergence; i < absPathVec.size(); ++i)
1298 relativePath.append(
"../");
1302 for (
size_t i = pointOfDivergence; i < filePathVec.size(); ++i)
1304 relativePath.append(filePathVec[i]);
1306 if (i < filePathVec.size() - 1)
1308 relativePath.append(
"/");
1314 return relativePath;
1320 bool result =
false;
1327 std::string tmp1 = file1;
1328 std::string tmp2 = file2;
1332 if (!fileInfo1.
path.empty())
1336 if (!fileInfo2.
path.empty())
1351 std::string file1ArchiveName = file1;
1352 std::string file2ArchiveName = file2;
1353 std::string file1InArchive, file2InArchive;
1371 result = (file1InArchive == file2InArchive);
1386 memset(&stat1, 0,
sizeof(
struct stat));
1387 memset(&stat2, 0,
sizeof(
struct stat));
1389 if (stat(file1.c_str(), &stat1) != 0)
1394 if (stat(file2.c_str(), &stat2) != 0)
1401 if (stat1.st_ino == stat2.st_ino)
1405 #else // WIN32 -- No inodes in Windows -- we'll have to imitate an inode's functionality. 1406 if (stat1.st_atime == stat2.st_atime &&
1407 stat1.st_ctime == stat2.st_ctime &&
1408 stat1.st_mtime == stat2.st_mtime &&
1409 stat1.st_gid == stat2.st_gid &&
1410 stat1.st_uid == stat2.st_uid &&
1411 stat1.st_mode == stat2.st_mode &&
1412 stat1.st_size == stat2.st_size)
1415 std::string file1Name = file1.substr(file1.find_last_of(
"\\/"));
1417 std::transform(file1Name.begin(), file1Name.end(), file1Name.begin(), tolower);
1418 std::string file2Name = file2.substr(file2.find_last_of(
"\\/"));
1419 std::transform(file2Name.begin(), file2Name.end(), file2Name.begin(), tolower);
1421 if (file1Name == file2Name)
1438 for (DirectoryContents::const_iterator i = dirCont.begin(); i != dirCont.end(); ++i)
1445 if (unlink(i->c_str()) < 0)
1448 std::string(
"Unable to delete directory \"") + *i +
"\":" + strerror(errno), __FILE__, __LINE__);
1451 else if ((*i !=
".") && (*i !=
"..") && ft ==
DIRECTORY && bRecursive)
1459 if (rmdir(i->c_str()) != 0)
1461 if (errno == ENOENT)
1487 #if defined(OPENSCENEGRAPH_MAJOR_VERSION) && OPENSCENEGRAPH_MAJOR_VERSION <= 2 && defined(OPENSCENEGRAPH_MINOR_VERSION) && OPENSCENEGRAPH_MINOR_VERSION <= 8 && defined(OPENSCENEGRAPH_PATCH_VERSION) && OPENSCENEGRAPH_PATCH_VERSION < 3 1494 return osgDB::concatPaths(left, right);
1505 osgDB::Registry::instance()->addArchiveExtension(
"zip");
1516 std::string filename = fullFilename;
1521 #if defined(OPENSCENEGRAPH_MAJOR_VERSION) && OPENSCENEGRAPH_MAJOR_VERSION >= 3 1523 osgDB::Registry* reg = osgDB::Registry::instance();
1524 const osgDB::Registry::ArchiveExtensionList& extensions = reg->getArchiveExtensions();
1526 osgDB::Registry::ArchiveExtensionList::const_iterator iter = extensions.begin();
1527 osgDB::Registry::ArchiveExtensionList::const_iterator iterEnd = extensions.end();
1528 for (; iter != iterEnd; ++iter)
1530 const std::string& archiveExtension = *iter;
1532 std::string archiveExtension =
".zip";
1536 std::string::size_type positionArchive = filename.find(archiveExtension +
'/');
1537 if (positionArchive == std::string::npos) positionArchive = filename.find(archiveExtension +
'\\');
1538 if (positionArchive != std::string::npos)
1540 std::string::size_type endArchive = positionArchive + archiveExtension.length();
1542 std::string filenameCopy = filename;
1543 archiveFilename = filenameCopy.substr(0, endArchive);
1544 fileInArchive = filenameCopy.substr(endArchive + 1, std::string::npos);
1549 std::string::size_type positionArchive2 = filename.find(archiveExtension);
1550 if (positionArchive2 != std::string::npos)
1552 archiveFilename = filename;
1572 std::string archiveName;
1573 std::string fileInArchive;
1577 result = a.getDirectoryContents(fileInArchive);
1586 std::string choppedStr = strFile;
1587 if (strFile.size() > 0 && (strFile[strFile.size() - 1] ==
'\\' ||
1588 strFile[strFile.size() - 1] ==
'/'))
1590 choppedStr = strFile.substr(0, strFile.length() - 1);
1599 info.
baseName = osgDB::getSimpleFileName(choppedStr);
1601 info.
path = osgDB::getFilePath(choppedStr);
1602 info.
extension = osgDB::getFileExtension(choppedStr);
1616 osg::ref_ptr<osgDB::Archive> archiveResult =
nullptr;
1621 osgDB::Registry* reg = osgDB::Registry::instance();
1623 std::string archiveFilename;
1624 std::string strippedFilename;
1625 std::string absoluteFilename = filename;
1634 archiveResult = reg->getFromArchiveCache(archiveFilename);
1635 if (archiveResult ==
nullptr)
1638 osg::ref_ptr<osgDB::ReaderWriter::Options> options = reg->getOptions() ?
1639 static_cast<osgDB::ReaderWriter::Options*
>(reg->getOptions()->clone(osg::CopyOp::SHALLOW_COPY)) :
1640 new osgDB::ReaderWriter::Options;
1642 osgDB::ReaderWriter::ReadResult readResult = reg->openArchive(archiveFilename, osgDB::ReaderWriter::READ, 4096, options.get());
1643 if (readResult.success())
1645 archiveResult = readResult.getArchive();
1651 if (archiveResult.valid())
1653 return dynamic_cast<osgDB::ArchiveExtended*
>(archiveResult.get());
1684 #if defined(OPENSCENEGRAPH_MAJOR_VERSION) && OPENSCENEGRAPH_MAJOR_VERSION >= 3 1685 osgDB::Registry* reg = osgDB::Registry::instance();
1687 const osgDB::Registry::ArchiveExtensionList& extensions = reg->getArchiveExtensions();
1689 osgDB::Registry::ArchiveExtensionList::const_iterator iter = extensions.begin();
1690 osgDB::Registry::ArchiveExtensionList::const_iterator iterEnd = extensions.end();
1691 for (; iter != iterEnd; ++iter)
1693 const std::string& archiveExtension = *iter;
1695 std::string archiveExtension =
".zip";
1699 std::string::size_type positionArchive = path.find(archiveExtension);
1700 if (positionArchive != std::string::npos)
1713 osgDB::Registry* reg = osgDB::Registry::instance();
1715 osg::Object* result =
nullptr;
1719 std::string archiveFilename;
1720 std::string strippedFilename;
1721 std::string absoluteFilename = filename;
1730 osg::Object* obj = reg->getFromObjectCache(strippedFilename);
1737 osgDB::Archive* arch =
FindArchive(archiveFilename);
1738 if (arch !=
nullptr)
1740 osgDB::ReaderWriter::ReadResult readResult = arch->readObject(strippedFilename, options);
1741 if (readResult.validObject())
1743 result = readResult.takeObject();
1744 if (result !=
nullptr && options !=
nullptr && (options->getObjectCacheHint() & osgDB::ReaderWriter::Options::CACHE_OBJECTS))
1746 reg->addEntryToObjectCache(strippedFilename, result);
1754 result = osgDB::readObjectFile(filename, options);
1764 osgDB::Registry* reg = osgDB::Registry::instance();
1766 osg::Node* result =
nullptr;
1770 std::string archiveFilename;
1771 std::string strippedFilename;
1772 std::string absoluteFilename = filename;
1781 osg::Object* obj = reg->getFromObjectCache(strippedFilename);
1784 result =
dynamic_cast<osg::Node*
>(obj);
1788 osgDB::Archive* arch =
FindArchive(archiveFilename);
1789 if (arch !=
nullptr)
1791 osgDB::ReaderWriter::ReadResult readResult = arch->readNode(strippedFilename, options);
1792 if (readResult.validNode())
1794 result = readResult.takeNode();
1796 if (result !=
nullptr && options !=
nullptr && (options->getObjectCacheHint() & osgDB::ReaderWriter::Options::CACHE_NODES))
1798 reg->addEntryToObjectCache(strippedFilename, result);
1806 result = osgDB::readNodeFile(filename, options);
std::string mCurrentDirectory
std::string ToString() const
Converts this exception to a string.
osgDB::ArchiveExtended * FindArchive(const std::string &archiveFileName) const
Used to search for archives by filename.
void LogMessage(const std::string &cppFile, const std::string &method, int line, const std::string &msg, LogLevel logLevel) const
Logs a time-stamped message.
trUtil::Logging::Log * mLogger
void FileDelete(const std::string &strFile) const
Deletes the given file.
static osg::ref_ptr< FileUtils > mInstance
FileNotFoundException(const std::string &message, const std::string &filename, unsigned int linenum)
virtual ~FileUtils()
Destructor.
Exception for signaling file utility i/o errors.
bool FileExists(const std::string &strFile, bool caseInsensitive=false) const
Queries if a given file exists.
A unary function created to have a compatibility to the old std::unary_function while still using c++...
This is the exception class used throughout the engine.
FileUtils()
Default constructor.
osg::Node * ReadNode(const std::string &filename, osgDB::ReaderWriter::Options *options=NULL)
Reads a node.
bool IsLevelEnabled(LogLevel logLevel) const
Queries if a level is enabled.
osg::Object * ReadObject(const std::string &filename, osgDB::ReaderWriter::Options *options=NULL)
Reads an object.
FileType GetFileTypeForFileInArchive(const osgDB::ArchiveExtended &a, const std::string &path) const
Gets file type for file in archive.
Singleton class implementing basic file operations.
std::string RunCommand(const char *cmd)
Runs a command on the console, and returns the console printout in a form of a string.
void MakeDirectory(const std::string &strDir) const
creates a new directory from a path.
std::string extensionlessFileName
the file name with extension
const struct FileInfo GetFileInfo(const std::string &strFile, bool caseInsensitive=false) const
struct holding information about a file.
static bool iMakeDirectory(const std::string &path)
bool operator()(char c) const
void DirGetFilesInArchive(const osgDB::ArchiveExtended &a, const std::string &path, DirectoryContents &result) const
Internal function used to find files within an archive subdirectory.
void ChangeDirectory(const std::string &path)
Changes the current directory to the one given in "path." This will clear the stack of directories th...
void RecursDeleteDir(bool bRecursive)
Recurs delete dir.
std::vector< std::string > DirectoryContents
std::vector< std::string > FileExtensionList
DirectoryContents DirGetSubs(const std::string &path) const
Dir get subs.
Exception for signalling file not found errors.
bool IsAbsolutePath(std::string strFileOrDir) const
Query whether a given string is an absolute path or not.
std::string ArchiveRelativeToAbsolute(const std::string &relativeFile) const
Archive relative to absolute.
DirectoryContents DirGetFiles(const std::string &path, const FileExtensionList &extensions=FileExtensionList()) const
Note: throws exceptions of type trUtil::Exception.
FileType GetFileTypeFromOSGDBFileType(osgDB::FileType ft) const
Gets file type from osgdb file type.
FileType
Values that represent file types.
static std::string ConcatPaths(const std::string &left, const std::string &right)
Concatenates two paths adding a path separator in between if necessary.
void FileMove(const std::string &strSrc, const std::string &strDest, bool bOverwrite) const
Moves a file.
void LogException(trUtil::Logging::LogLevel level=trUtil::Logging::LogLevel::LOG_ERROR) const
Logs the exception to the default logger.
time_t lastModified
when the file was last modified.
size_t size
the size of the file in bytes.
std::string RelativePath(const std::string &absolutePath, const std::string &file) const
Helper function that returns the relative path between absolutePath and file.
DirectoryPush(const std::string &dir)
Constructor.
static void tokenize(std::vector< std::string > &tokens, const std::string &stringToParse, const Pred &predFxn=Pred())
The predicate should evaluate to true when applied to a separator.
void ChangeDirectoryInternal(const std::string &path)
Change directory internal.
std::string GetAbsolutePath(const std::string &relativePath, bool removeFinalFile=false) const
Converts a relative path to an absolute path.
bool DirExists(const std::string &strDir, bool caseInsensitive=false) const
Queries if a given dir exists.
bool SplitArchiveFilename(const std::string &fullFilename, std::string &archiveFilename, std::string &fileInArchive) const
Splits a filename for a file within an archive into two parts, the archive filename and the actual fi...
std::vector< std::string > mStackOfDirectories
const std::string & CurrentDirectory() const
Current directory.
FileType fileType
The enum value specifying the type of file.
void InternalDirCopy(const std::string &srcPath, const std::string &destPath, bool bOverwrite) const
Internal dir copy.
bool IsSameFile(const std::string &file1, const std::string &file2) const
It is possible for two different path strings to point at the same file on disk.
std::string path
the path to the file
static FileUtils & GetInstance()
Character separating the parts of a file path.
bool isInArchive
true if the specified file lives within an archive
void PopDirectory()
sets the current directory to the last directory on the stack.
Namespace that holds various utility classes for the engine.
std::string fileName
the file name with full path
~DirectoryPush()
Destructor.
void FileCopy(const std::string &strSrc, const std::string &strDest, bool bOverwrite) const
Copys a file.
void DirCopy(const std::string &srcPath, const std::string &destPath, bool bOverwrite, bool copyContentsOnly=false) const
Copys an entire directory.
FileUtilIOException(const std::string &message, const std::string &filename, unsigned int linenum)
TR_UTIL_EXPORT int StrCompare(const std::string &one, const std::string &two, bool caseSensitive=true)
Compares strings like strcmp or stricmp or strcasecmp.
bool GetSucceeded()
Gets the succeeded.
void PushDirectory(const std::string &path)
Changes the current directory to the one given in "path" and adds the previous current directory to a...
void MakeDirectoryEX(std::string strDir)
A more powerful version of the standard mkdir.
std::string getFileExtensionIncludingDot(const std::string &fileName)
void CleanupFileString(std::string &strFileOrDir) const
Ensure that the passed in string is fit for use as a file or dir string.
bool DirDelete(const std::string &strDir, bool bRecursive)
Deletes a directory.
FileInfo GetFileInfoForFileInArchive(const osgDB::ArchiveExtended &a, const std::string &path) const
Gets file information for file in archive.
std::string extension
the file extension
bool IsSameFile_Internal(const std::string &file1, const std::string &file2) const
Query if 'file1' is same file internal.
const std::string & GetError()
Gets the error.
static const char PATH_SEPARATOR
Simple class to change directory where it automatically pop back out on destruction.
const struct FileInfo GetFileInfo_Internal(const std::string &strFile, bool caseInsensitive) const
static Log & GetInstance(const std::string &name=Log::LOG_DEFAULT_NAME)
Retrieve singleton instance of the log class for a give string name.
static std::string GetPathRoot(const std::string &path)
std::string baseName
the file name with extension
bool ContainsArchiveExtension(const std::string &path) const
Query if 'path' contains archive extension.