TrueReality  v0.1.1912
trUtil::FileUtils Class Reference

Singleton class implementing basic file operations. More...

#include <FileUtils.h>

Inheritance diagram for trUtil::FileUtils:
Collaboration diagram for trUtil::FileUtils:

Public Member Functions

std::string RunCommand (const char *cmd)
 Runs a command on the console, and returns the console printout in a form of a string. More...
 
std::string RunCommand (const std::string cmd)
 Runs a command on the console, and returns the console printout in a form of a string. More...
 
bool FileExists (const std::string &strFile, bool caseInsensitive=false) const
 Queries if a given file exists. More...
 
void FileCopy (const std::string &strSrc, const std::string &strDest, bool bOverwrite) const
 Copys a file. More...
 
void FileMove (const std::string &strSrc, const std::string &strDest, bool bOverwrite) const
 Moves a file. More...
 
void FileDelete (const std::string &strFile) const
 Deletes the given file. More...
 
const struct FileInfo GetFileInfo (const std::string &strFile, bool caseInsensitive=false) const
 
void CleanupFileString (std::string &strFileOrDir) const
 Ensure that the passed in string is fit for use as a file or dir string. More...
 
bool IsAbsolutePath (std::string strFileOrDir) const
 Query whether a given string is an absolute path or not. More...
 
void MakeDirectoryEX (std::string strDir)
 A more powerful version of the standard mkdir. More...
 
void ChangeDirectory (const std::string &path)
 Changes the current directory to the one given in "path." This will clear the stack of directories that is set by pushDirectory and popDirectory. More...
 
const std::string & CurrentDirectory () const
 Current directory. More...
 
void PushDirectory (const std::string &path)
 Changes the current directory to the one given in "path" and adds the previous current directory to an internal stack so it can be returned to via popDirectory. More...
 
void PopDirectory ()
 sets the current directory to the last directory on the stack. More...
 
std::string GetAbsolutePath (const std::string &relativePath, bool removeFinalFile=false) const
 Converts a relative path to an absolute path. More...
 
DirectoryContents DirGetFiles (const std::string &path, const FileExtensionList &extensions=FileExtensionList()) const
 Note: throws exceptions of type trUtil::Exception. More...
 
DirectoryContents DirGetSubs (const std::string &path) const
 Dir get subs. More...
 
void DirCopy (const std::string &srcPath, const std::string &destPath, bool bOverwrite, bool copyContentsOnly=false) const
 Copys an entire directory. More...
 
bool DirDelete (const std::string &strDir, bool bRecursive)
 Deletes a directory. More...
 
void MakeDirectory (const std::string &strDir) const
 creates a new directory from a path. More...
 
bool DirExists (const std::string &strDir, bool caseInsensitive=false) const
 Queries if a given dir exists. More...
 
std::string RelativePath (const std::string &absolutePath, const std::string &file) const
 Helper function that returns the relative path between absolutePath and file. More...
 
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. More...
 
osg::Object * ReadObject (const std::string &filename, osgDB::ReaderWriter::Options *options=NULL)
 Reads an object. More...
 
osg::Node * ReadNode (const std::string &filename, osgDB::ReaderWriter::Options *options=NULL)
 Reads a node. More...
 
osgDB::ArchiveExtended * FindArchive (const std::string &archiveFileName) const
 Used to search for archives by filename. More...
 

Static Public Member Functions

static FileUtilsGetInstance ()
 Character separating the parts of a file path. More...
 
static std::string ConcatPaths (const std::string &left, const std::string &right)
 Concatenates two paths adding a path separator in between if necessary. More...
 

Static Public Attributes

static const char PATH_SEPARATOR = '/'
 

Private Member Functions

 FileUtils ()
 Default constructor. More...
 
virtual ~FileUtils ()
 Destructor. More...
 
void ChangeDirectoryInternal (const std::string &path)
 Change directory internal. More...
 
void InternalDirCopy (const std::string &srcPath, const std::string &destPath, bool bOverwrite) const
 Internal dir copy. More...
 
void RecursDeleteDir (bool bRecursive)
 Recurs delete dir. More...
 
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 filename relative to the archive root. More...
 
void DirGetFilesInArchive (const osgDB::ArchiveExtended &a, const std::string &path, DirectoryContents &result) const
 Internal function used to find files within an archive subdirectory. More...
 
FileType GetFileTypeForFileInArchive (const osgDB::ArchiveExtended &a, const std::string &path) const
 Gets file type for file in archive. More...
 
FileInfo GetFileInfoForFileInArchive (const osgDB::ArchiveExtended &a, const std::string &path) const
 Gets file information for file in archive. More...
 
FileType GetFileTypeFromOSGDBFileType (osgDB::FileType ft) const
 Gets file type from osgdb file type. More...
 
bool ContainsArchiveExtension (const std::string &path) const
 Query if 'path' contains archive extension. More...
 
std::string ArchiveRelativeToAbsolute (const std::string &relativeFile) const
 Archive relative to absolute. More...
 
const struct FileInfo GetFileInfo_Internal (const std::string &strFile, bool caseInsensitive) const
 
bool IsSameFile_Internal (const std::string &file1, const std::string &file2) const
 Query if 'file1' is same file internal. More...
 

Private Attributes

trUtil::Logging::LogmLogger
 
std::string mCurrentDirectory
 
std::vector< std::string > mStackOfDirectories
 

Static Private Attributes

static const int PATH_BUFFER_SIZE = 1024
 Size of the path buffer. More...
 
static osg::ref_ptr< FileUtilsmInstance
 

Detailed Description

Singleton class implementing basic file operations.

Definition at line 125 of file FileUtils.h.

Constructor & Destructor Documentation

◆ FileUtils()

trUtil::FileUtils::FileUtils ( )
private

Default constructor.

Definition at line 1498 of file FileUtils.cpp.

References ChangeDirectory(), trUtil::Logging::Log::GetInstance(), and mLogger.

Here is the call graph for this function:

◆ ~FileUtils()

trUtil::FileUtils::~FileUtils ( )
privatevirtual

Destructor.

Definition at line 1509 of file FileUtils.cpp.

Member Function Documentation

◆ ArchiveRelativeToAbsolute()

std::string trUtil::FileUtils::ArchiveRelativeToAbsolute ( const std::string &  relativeFile) const
private

Archive relative to absolute.

Parameters
relativeFileThe relative file.
Returns
A std::string.

Definition at line 478 of file FileUtils.cpp.

References CleanupFileString(), mCurrentDirectory, and trUtil::StringUtils::StringTokenizer< Pred >::tokenize().

Referenced by ChangeDirectory(), DirGetFiles(), FindArchive(), GetFileInfo(), IsSameFile(), ReadNode(), and ReadObject().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ChangeDirectory()

void trUtil::FileUtils::ChangeDirectory ( const std::string &  path)

Changes the current directory to the one given in "path." This will clear the stack of directories that is set by pushDirectory and popDirectory.

If this call fails, the stack will not be cleared.

See also
popDirectory.
Parameters
pathThe path to the new directory.
See also
pushDirectory
Exceptions
trUtil::FileNotFoundExceptionif the path does not exist.

Definition at line 707 of file FileUtils.cpp.

References ArchiveRelativeToAbsolute(), ChangeDirectoryInternal(), CleanupFileString(), ContainsArchiveExtension(), IsAbsolutePath(), mCurrentDirectory, and mStackOfDirectories.

Referenced by FileUtils().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ChangeDirectoryInternal()

void trUtil::FileUtils::ChangeDirectoryInternal ( const std::string &  path)
private

Change directory internal.

Parameters
pathFull pathname of the file.

Definition at line 740 of file FileUtils.cpp.

References trUtil::DIRECTORY, trUtil::FileInfo::fileType, FindArchive(), GetFileInfoForFileInArchive(), trUtil::Logging::Log::IsLevelEnabled(), LOG_DEBUG, trUtil::Logging::Log::LogMessage(), mCurrentDirectory, mLogger, and SplitArchiveFilename().

Referenced by ChangeDirectory(), PopDirectory(), PushDirectory(), and RecursDeleteDir().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CleanupFileString()

void trUtil::FileUtils::CleanupFileString ( std::string &  strFileOrDir) const

Ensure that the passed in string is fit for use as a file or dir string.

In our case we want all separators to be the '/' character and we do not want a separator at the end.

Parameters
[in,out]strFileOrDirThe string to cleanup.
Note
The original string passed in is changed.

Definition at line 601 of file FileUtils.cpp.

References PATH_SEPARATOR.

Referenced by ArchiveRelativeToAbsolute(), ChangeDirectory(), GetFileInfo(), IsAbsolutePath(), MakeDirectoryEX(), and SplitArchiveFilename().

Here is the caller graph for this function:

◆ ConcatPaths()

std::string trUtil::FileUtils::ConcatPaths ( const std::string &  left,
const std::string &  right 
)
static

Concatenates two paths adding a path separator in between if necessary.

Parameters
leftThe left.
rightThe right.
Returns
A std::string.

Definition at line 1485 of file FileUtils.cpp.

◆ ContainsArchiveExtension()

bool trUtil::FileUtils::ContainsArchiveExtension ( const std::string &  path) const
private

Query if 'path' contains archive extension.

Parameters
pathFull pathname of the file.
Returns
True if it succeeds, false if it fails.

Definition at line 1680 of file FileUtils.cpp.

Referenced by ChangeDirectory(), and GetFileInfo().

Here is the caller graph for this function:

◆ CurrentDirectory()

const std::string & trUtil::FileUtils::CurrentDirectory ( ) const

Current directory.

Returns
the full path to the current directory.

Definition at line 734 of file FileUtils.cpp.

References mCurrentDirectory.

◆ DirCopy()

void trUtil::FileUtils::DirCopy ( const std::string &  srcPath,
const std::string &  destPath,
bool  bOverwrite,
bool  copyContentsOnly = false 
) const

Copys an entire directory.

If destPath exists, then a subdirectory will be created in destPath with the same name as srcPath unless copyContentsOnly is true, in which case the contents of srcPath will be copied into destPath. If destPath does not exist, destPath will be created if the parent exists and the contents of srcPath will be copied to destPath whether copyContentsOnly is true or false.

Exceptions
trUtil::FileNotFoundExceptionif the source file is not found.
trUtil::IOExceptionif an error occurs copying the data or bOverwrite was false and a destination file exists.
Parameters
srcPaththe source directory to copy.
destPaththe destination directory.
bOverwritetrue if this call should overwrite the destination file if it exists.
copyContentsOnly(Optional) true if the contents of srcPath should be copied into destPath rather than create a subdirectory.

Definition at line 1046 of file FileUtils.cpp.

References DirExists(), trUtil::FILE_NOT_FOUND, trUtil::FileInfo::fileType, GetAbsolutePath(), GetFileInfo(), InternalDirCopy(), trUtil::Logging::Log::IsLevelEnabled(), LOG_DEBUG, trUtil::Logging::Log::LogMessage(), MakeDirectory(), mLogger, PATH_SEPARATOR, and trUtil::REGULAR_FILE.

Here is the call graph for this function:

◆ DirDelete()

bool trUtil::FileUtils::DirDelete ( const std::string &  strDir,
bool  bRecursive 
)

Deletes a directory.

If bRecursive is true, the directory and all it's contents will be removed. If it's false, the call will fail unless the directory is empty.

Exceptions
trUtil::FileNotFoundExceptionif the path does not exist.
trUtil::IOExceptionif an error occurs deleteting the directory.
Parameters
strDirThe path of the directory to delete.
bRecursivetrue if the directory should be deleted recursively.
Returns
true if successful or false if the directory is NOT empty and bRecursive is false.

Definition at line 1139 of file FileUtils.cpp.

References DirExists(), trUtil::Logging::Log::IsLevelEnabled(), LOG_DEBUG, trUtil::Exception::LogException(), trUtil::Logging::Log::LogMessage(), mLogger, PopDirectory(), PushDirectory(), and RecursDeleteDir().

Here is the call graph for this function:

◆ DirExists()

bool trUtil::FileUtils::DirExists ( const std::string &  strDir,
bool  caseInsensitive = false 
) const

Queries if a given dir exists.

Parameters
strDirThe directory to check.
caseInsensitive(Optional) false for native, true for forced case insensitivity on platforms that normally are sensitive.
Returns
true if the path exists and is a directory.

Definition at line 1247 of file FileUtils.cpp.

References trUtil::DIRECTORY, trUtil::FileInfo::fileType, and GetFileInfo().

Referenced by DirCopy(), DirDelete(), MakeDirectory(), and MakeDirectoryEX().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DirGetFiles()

DirectoryContents trUtil::FileUtils::DirGetFiles ( const std::string &  path,
const FileExtensionList extensions = FileExtensionList() 
) const

Note: throws exceptions of type trUtil::Exception.

Exceptions
trUtil::FileNotFoundExceptionif the path does not exist.
trUtil::IOExceptionif the path is not an actual directory.
Parameters
paththe path to the directory to list the contents of.
extensions(Optional) Optional list of file extensions to filter on, including the "dot". (e.g., ".txt", ".xml")
Returns
a vector of file names.

Definition at line 901 of file FileUtils.cpp.

References trUtil::ARCHIVE, ArchiveRelativeToAbsolute(), DirGetFilesInArchive(), trUtil::FILE_NOT_FOUND, trUtil::FileInfo::fileType, FindArchive(), trUtil::getFileExtensionIncludingDot(), GetFileInfo(), IsAbsolutePath(), trUtil::FileInfo::isInArchive, trUtil::REGULAR_FILE, SplitArchiveFilename(), and trUtil::StringUtils::StrCompare().

Referenced by DirGetSubs(), InternalDirCopy(), and RecursDeleteDir().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DirGetFilesInArchive()

void trUtil::FileUtils::DirGetFilesInArchive ( const osgDB::ArchiveExtended &  a,
const std::string &  path,
DirectoryContents result 
) const
private

Internal function used to find files within an archive subdirectory.

Parameters
aThe osgDB::ArchiveExtended to process.
pathFull pathname of the file.
[in,out]resultThe result.

Definition at line 1569 of file FileUtils.cpp.

References SplitArchiveFilename().

Referenced by DirGetFiles().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DirGetSubs()

DirectoryContents trUtil::FileUtils::DirGetSubs ( const std::string &  path) const

Dir get subs.

Exceptions
trUtil::FileNotFoundExceptionif the path does not exist.
Parameters
paththe path to the directory to get the subdirectories for.
Returns
a vector holding the list of subdirectories.

Definition at line 977 of file FileUtils.cpp.

References trUtil::DIRECTORY, DirGetFiles(), trUtil::FileInfo::fileType, GetFileInfo(), and PATH_SEPARATOR.

Here is the call graph for this function:

◆ FileCopy()

void trUtil::FileUtils::FileCopy ( const std::string &  strSrc,
const std::string &  strDest,
bool  bOverwrite 
) const

Copys a file.

Exceptions
trUtil::FileNotFoundExceptionif the source file is not found.
trUtil::IOExceptionif an error occurs copying the data or bOverwrite was false and the destination file exists.
Parameters
strSrcThe path to the source file.
strDestThe path to the destination file or directory.
bOverwritetrue if this call should overwrite the destination file if it exists.

Definition at line 223 of file FileUtils.cpp.

References trUtil::DIRECTORY, FileExists(), trUtil::FileInfo::fileType, GetFileInfo(), trUtil::Logging::Log::IsLevelEnabled(), IsSameFile(), LOG_DEBUG, trUtil::Logging::Log::LogMessage(), mLogger, and PATH_SEPARATOR.

Referenced by FileMove(), and InternalDirCopy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FileDelete()

void trUtil::FileUtils::FileDelete ( const std::string &  strFile) const

Deletes the given file.

Exceptions
trUtil::IOExceptionif an error occurs deleting the data.
Parameters
strFilethe path to the file to delete.

Definition at line 417 of file FileUtils.cpp.

References trUtil::FILE_NOT_FOUND, trUtil::FileInfo::fileType, GetFileInfo(), and trUtil::REGULAR_FILE.

Here is the call graph for this function:

◆ FileExists()

bool trUtil::FileUtils::FileExists ( const std::string &  strFile,
bool  caseInsensitive = false 
) const

Queries if a given file exists.

Parameters
strFilethe path to the file to check.
caseInsensitive(Optional) false for native, true for forced case insensitivity on platforms that normally are sensitive.
Returns
true if the file exists.

Definition at line 217 of file FileUtils.cpp.

References trUtil::FILE_NOT_FOUND, trUtil::FileInfo::fileType, and GetFileInfo().

Referenced by FileCopy(), and trUtil::JSON::File::FileExists().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FileMove()

void trUtil::FileUtils::FileMove ( const std::string &  strSrc,
const std::string &  strDest,
bool  bOverwrite 
) const

Moves a file.

This call will attempt to move the file without moving the data, but if it can't, the file will first be copied then the source file will be removed.

Exceptions
trUtil::FileNotFoundExceptionif the source file is not found.
trUtil::IOExceptionif an error occurs moving the data or bOverwrite was false and the destination file exists.
Parameters
strSrcThe path to the source file.
strDestThe path to the destintion file or directory.
bOverwritetrue if this call should overwrite the destination file if it exists.

Definition at line 348 of file FileUtils.cpp.

References trUtil::DIRECTORY, trUtil::FILE_NOT_FOUND, FileCopy(), trUtil::FileInfo::fileType, GetFileInfo(), trUtil::Logging::Log::IsLevelEnabled(), LOG_DEBUG, trUtil::Logging::Log::LogMessage(), mLogger, PATH_SEPARATOR, and trUtil::REGULAR_FILE.

Here is the call graph for this function:

◆ FindArchive()

osgDB::ArchiveExtended * trUtil::FileUtils::FindArchive ( const std::string &  archiveFileName) const

Used to search for archives by filename.

Parameters
archiveFileNameFilename of the archive file.
Returns
Null if it fails, else the found archive.

Definition at line 1614 of file FileUtils.cpp.

References ArchiveRelativeToAbsolute(), trUtil::FILE_NOT_FOUND, trUtil::FileInfo::fileType, GetFileInfo(), IsAbsolutePath(), and SplitArchiveFilename().

Referenced by ChangeDirectoryInternal(), DirGetFiles(), GetFileInfo_Internal(), ReadNode(), and ReadObject().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetAbsolutePath()

std::string trUtil::FileUtils::GetAbsolutePath ( const std::string &  relativePath,
bool  removeFinalFile = false 
) const

Converts a relative path to an absolute path.

Exceptions
trUtil::FileNotFoundExceptionif the path does not exist.
Parameters
relativePaththe relative path to convert to absolute.
removeFinalFile(Optional) If this refers to a file, then remove the final file in the result.
Returns
the absolute path.

Definition at line 833 of file FileUtils.cpp.

References trUtil::ARCHIVE, trUtil::FileInfo::baseName, trUtil::FILE_NOT_FOUND, trUtil::FileInfo::fileType, GetFileInfo(), trUtil::DirectoryPush::GetSucceeded(), trUtil::FileInfo::isInArchive, mCurrentDirectory, trUtil::FileInfo::path, PATH_SEPARATOR, and trUtil::REGULAR_FILE.

Referenced by DirCopy(), and IsSameFile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetFileInfo()

const struct FileInfo trUtil::FileUtils::GetFileInfo ( const std::string &  strFile,
bool  caseInsensitive = false 
) const

◆ GetFileInfo_Internal()

const struct FileInfo trUtil::FileUtils::GetFileInfo_Internal ( const std::string &  strFile,
bool  caseInsensitive 
) const
private

◆ GetFileInfoForFileInArchive()

trUtil::FileInfo trUtil::FileUtils::GetFileInfoForFileInArchive ( const osgDB::ArchiveExtended &  a,
const std::string &  path 
) const
private

Gets file information for file in archive.

Parameters
aThe osgDB::ArchiveExtended to process.
pathFull pathname of the file.
Returns
The file information for file in archive.

Definition at line 1581 of file FileUtils.cpp.

References trUtil::FileInfo::baseName, trUtil::FileInfo::extension, trUtil::FileInfo::extensionlessFileName, trUtil::FILE_NOT_FOUND, trUtil::FileInfo::fileName, trUtil::FileInfo::fileType, GetFileTypeFromOSGDBFileType(), trUtil::FileInfo::isInArchive, trUtil::FileInfo::lastModified, trUtil::FileInfo::path, and trUtil::FileInfo::size.

Referenced by ChangeDirectoryInternal(), and GetFileInfo_Internal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetFileTypeForFileInArchive()

trUtil::FileType trUtil::FileUtils::GetFileTypeForFileInArchive ( const osgDB::ArchiveExtended &  a,
const std::string &  path 
) const
private

Gets file type for file in archive.

Parameters
aThe osgDB::ArchiveExtended to process.
pathFull pathname of the file.
Returns
The file type for file in archive.

Definition at line 1562 of file FileUtils.cpp.

References GetFileTypeFromOSGDBFileType().

Here is the call graph for this function:

◆ GetFileTypeFromOSGDBFileType()

trUtil::FileType trUtil::FileUtils::GetFileTypeFromOSGDBFileType ( osgDB::FileType  ft) const
private

Gets file type from osgdb file type.

Parameters
ftThe ft.
Returns
The file type from osgdb file type.

Definition at line 1662 of file FileUtils.cpp.

References trUtil::DIRECTORY, trUtil::FILE_NOT_FOUND, and trUtil::REGULAR_FILE.

Referenced by GetFileInfoForFileInArchive(), and GetFileTypeForFileInArchive().

Here is the caller graph for this function:

◆ GetInstance()

static FileUtils & trUtil::FileUtils::GetInstance ( )
inlinestatic

Character separating the parts of a file path.

Gets the instance.

Returns
the single instance of this class.

Definition at line 137 of file FileUtils.h.

Referenced by trUtil::PathUtils::CreateDataPathTree(), trUtil::PathUtils::CreateUserDataPathTree(), trUtil::DirectoryPush::DirectoryPush(), trUtil::JSON::File::FileExists(), trUtil::PathUtils::FindFile(), trUtil::VersionUtil::GetCurrentCommitNum(), trUtil::Logging::LogWriterFile::OpenFile(), and trUtil::DirectoryPush::~DirectoryPush().

Here is the caller graph for this function:

◆ InternalDirCopy()

void trUtil::FileUtils::InternalDirCopy ( const std::string &  srcPath,
const std::string &  destPath,
bool  bOverwrite 
) const
private

Internal dir copy.

Parameters
srcPathFull pathname of the source file.
destPathFull pathname of the destination file.
bOverwriteTrue to overwrite, false to preserve.

Definition at line 995 of file FileUtils.cpp.

References trUtil::DIRECTORY, DirGetFiles(), trUtil::FILE_NOT_FOUND, FileCopy(), trUtil::FileInfo::fileType, GetFileInfo(), trUtil::Logging::Log::IsLevelEnabled(), LOG_WARNING, trUtil::Logging::Log::LogMessage(), MakeDirectory(), mLogger, PATH_SEPARATOR, and trUtil::REGULAR_FILE.

Referenced by DirCopy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsAbsolutePath()

bool trUtil::FileUtils::IsAbsolutePath ( std::string  strFileOrDir) const

Query whether a given string is an absolute path or not.

Parameters
strFileOrDirThe path to check.
Returns
True if absolute, False if relative.
Note
This maybe a subjective determination, may need to add to this later.

Definition at line 630 of file FileUtils.cpp.

References CleanupFileString().

Referenced by ChangeDirectory(), DirGetFiles(), FindArchive(), GetFileInfo(), IsSameFile(), ReadNode(), ReadObject(), and RelativePath().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsSameFile()

bool trUtil::FileUtils::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.

(Things like relative paths and filesystem links make this possible).

This function makes absolutely certain that the two files aren't the same by checking the inodes of the two files – preventing things like having the FileUtils::FileCopy accidentally blow away a file by copying it onto itself.

Parameters
file1– Path to first file.
file2– Path to second file.
Returns
True if inodes match, false otherwise (if one or both files are inaccessible, returns false).

Definition at line 1318 of file FileUtils.cpp.

References ArchiveRelativeToAbsolute(), GetAbsolutePath(), GetFileInfo(), IsAbsolutePath(), trUtil::FileInfo::isInArchive, IsSameFile_Internal(), trUtil::FileInfo::path, and SplitArchiveFilename().

Referenced by FileCopy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsSameFile_Internal()

bool trUtil::FileUtils::IsSameFile_Internal ( const std::string &  file1,
const std::string &  file2 
) const
private

Query if 'file1' is same file internal.

Parameters
file1The first file.
file2The second file.
Returns
True if same file internal, false if not.

Definition at line 1380 of file FileUtils.cpp.

Referenced by IsSameFile().

Here is the caller graph for this function:

◆ MakeDirectory()

void trUtil::FileUtils::MakeDirectory ( const std::string &  strDir) const

creates a new directory from a path.

Exceptions
trUtil::FileNotFoundExceptionif the parent path does not exist.
trUtil::IOExceptionif an error occurs creating the directory.
Parameters
strDirthe directory to create.

Definition at line 1219 of file FileUtils.cpp.

References trUtil::DIRECTORY, DirExists(), trUtil::FileInfo::fileType, GetFileInfo(), trUtil::iMakeDirectory(), and trUtil::REGULAR_FILE.

Referenced by DirCopy(), InternalDirCopy(), and MakeDirectoryEX().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MakeDirectoryEX()

void trUtil::FileUtils::MakeDirectoryEX ( std::string  strDir)

A more powerful version of the standard mkdir.

This function will check to see if the directory exists first and only create if needed. Also, it will recursively create all subdirectories needed to create the final directory in the passed in string.

Exceptions
allthe exceptions that MakeDirectory throws.
Parameters
strDirThe directory to create.
See also
::MakeDirectory

Definition at line 651 of file FileUtils.cpp.

References CleanupFileString(), DirExists(), and MakeDirectory().

Referenced by trUtil::PathUtils::CreateDataPathTree(), trUtil::PathUtils::CreateUserDataPathTree(), and trUtil::Logging::LogWriterFile::OpenFile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PopDirectory()

void trUtil::FileUtils::PopDirectory ( )

sets the current directory to the last directory on the stack.

Exceptions
trUtil::FileNotFoundExceptionif the previous directory no longer exists.
See also
pushDirectory

Definition at line 816 of file FileUtils.cpp.

References ChangeDirectoryInternal(), trUtil::Logging::Log::IsLevelEnabled(), LOG_DEBUG, trUtil::Logging::Log::LogMessage(), mLogger, and mStackOfDirectories.

Referenced by DirDelete(), and trUtil::DirectoryPush::~DirectoryPush().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PushDirectory()

void trUtil::FileUtils::PushDirectory ( const std::string &  path)

Changes the current directory to the one given in "path" and adds the previous current directory to an internal stack so it can be returned to via popDirectory.

If this call fails, the stack will not be changed.

Exceptions
trUtil::FileNameFoundExceptionif the path does not exist.
Parameters
pathThe path to the new directory.
See also
popDirectory

Definition at line 801 of file FileUtils.cpp.

References ChangeDirectoryInternal(), trUtil::Logging::Log::IsLevelEnabled(), LOG_DEBUG, trUtil::Logging::Log::LogMessage(), mCurrentDirectory, mLogger, and mStackOfDirectories.

Referenced by DirDelete(), and trUtil::DirectoryPush::DirectoryPush().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReadNode()

osg::Node * trUtil::FileUtils::ReadNode ( const std::string &  filename,
osgDB::ReaderWriter::Options *  options = NULL 
)

Reads a node.

Parameters
filenameFilename of the file.
[in,out]options(Optional) If non-null, options for controlling the operation.
Returns
Null if it fails, else the node.

Definition at line 1761 of file FileUtils.cpp.

References trUtil::ARCHIVE, ArchiveRelativeToAbsolute(), trUtil::FileInfo::fileType, FindArchive(), GetFileInfo(), IsAbsolutePath(), trUtil::FileInfo::isInArchive, and SplitArchiveFilename().

Here is the call graph for this function:

◆ ReadObject()

osg::Object * trUtil::FileUtils::ReadObject ( const std::string &  filename,
osgDB::ReaderWriter::Options *  options = NULL 
)

Reads an object.

Parameters
filenameFilename of the file.
[in,out]options(Optional) If non-null, options for controlling the operation.
Returns
Null if it fails, else the object.

Definition at line 1710 of file FileUtils.cpp.

References trUtil::ARCHIVE, ArchiveRelativeToAbsolute(), trUtil::FileInfo::fileType, FindArchive(), GetFileInfo(), IsAbsolutePath(), trUtil::FileInfo::isInArchive, trUtil::REGULAR_FILE, and SplitArchiveFilename().

Here is the call graph for this function:

◆ RecursDeleteDir()

void trUtil::FileUtils::RecursDeleteDir ( bool  bRecursive)
private

Recurs delete dir.

Parameters
bRecursiveTrue to process recursively, false to process locally only.

Definition at line 1432 of file FileUtils.cpp.

References ChangeDirectoryInternal(), trUtil::DIRECTORY, DirGetFiles(), trUtil::FileInfo::fileType, GetFileInfo(), trUtil::Logging::Log::IsLevelEnabled(), LOG_DEBUG, trUtil::Logging::Log::LogMessage(), mCurrentDirectory, mLogger, PATH_SEPARATOR, and trUtil::REGULAR_FILE.

Referenced by DirDelete().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RelativePath()

std::string trUtil::FileUtils::RelativePath ( const std::string &  absolutePath,
const std::string &  file 
) const

Helper function that returns the relative path between absolutePath and file.

Parameters
absolutePathThe absolute path to search.
fileThe absolute path to the file.
Returns
The relative path or empty string for failure
Note
This function assumes that directory separators are equal for both paths.

Definition at line 1253 of file FileUtils.cpp.

References trUtil::GetPathRoot(), IsAbsolutePath(), PATH_SEPARATOR, and trUtil::StringUtils::StringTokenizer< Pred >::tokenize().

Here is the call graph for this function:

◆ RunCommand() [1/2]

std::string trUtil::FileUtils::RunCommand ( const char *  cmd)

Runs a command on the console, and returns the console printout in a form of a string.

Parameters
cmdThe command.
Returns
A std::string.

Definition at line 195 of file FileUtils.cpp.

Referenced by trUtil::VersionUtil::GetCurrentCommitNum(), and RunCommand().

Here is the caller graph for this function:

◆ RunCommand() [2/2]

std::string trUtil::FileUtils::RunCommand ( const std::string  cmd)

Runs a command on the console, and returns the console printout in a form of a string.

Parameters
cmdThe command.
Returns
A std::string.

Definition at line 189 of file FileUtils.cpp.

References RunCommand().

Here is the call graph for this function:

◆ SplitArchiveFilename()

bool trUtil::FileUtils::SplitArchiveFilename ( const std::string &  fullFilename,
std::string &  archiveFilename,
std::string &  fileInArchive 
) const
private

Splits a filename for a file within an archive into two parts, the archive filename and the actual filename relative to the archive root.

Parameters
fullFilenameFilename of the full file.
[in,out]archiveFilenameFilename of the archive file.
[in,out]fileInArchiveThe file in archive.
Returns
True if it succeeds, false if it fails.

Definition at line 1513 of file FileUtils.cpp.

References CleanupFileString().

Referenced by ChangeDirectoryInternal(), DirGetFiles(), DirGetFilesInArchive(), FindArchive(), GetFileInfo_Internal(), IsSameFile(), ReadNode(), and ReadObject().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ mCurrentDirectory

std::string trUtil::FileUtils::mCurrentDirectory
private

◆ mInstance

osg::ref_ptr< FileUtils > trUtil::FileUtils::mInstance
staticprivate

Definition at line 680 of file FileUtils.h.

◆ mLogger

◆ mStackOfDirectories

std::vector<std::string> trUtil::FileUtils::mStackOfDirectories
private

Definition at line 685 of file FileUtils.h.

Referenced by ChangeDirectory(), PopDirectory(), and PushDirectory().

◆ PATH_BUFFER_SIZE

const int trUtil::FileUtils::PATH_BUFFER_SIZE = 1024
staticprivate

Size of the path buffer.

Definition at line 532 of file FileUtils.h.

◆ PATH_SEPARATOR


The documentation for this class was generated from the following files: