113 lines
4.1 KiB
C++
113 lines
4.1 KiB
C++
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
|
|
*
|
|
* This library is open source and may be redistributed and/or modified under
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* OpenSceneGraph Public License for more details.
|
|
*/
|
|
|
|
#ifndef OSGDB_FILEUTILS
|
|
#define OSGDB_FILEUTILS 1
|
|
|
|
#include <osgDB/Registry>
|
|
|
|
#include <vector>
|
|
#include <deque>
|
|
#include <string>
|
|
|
|
|
|
namespace osgDB {
|
|
|
|
enum CaseSensitivity
|
|
{
|
|
CASE_SENSITIVE,
|
|
CASE_INSENSITIVE,
|
|
};
|
|
|
|
enum FileType
|
|
{
|
|
FILE_NOT_FOUND,
|
|
REGULAR_FILE,
|
|
DIRECTORY,
|
|
};
|
|
|
|
// Make a new directory. Returns true if directory exists or was created.
|
|
extern OSGDB_EXPORT bool makeDirectory( const std::string &directoryPath );
|
|
|
|
// Make a new directory for a given file.
|
|
extern OSGDB_EXPORT bool makeDirectoryForFile( const std::string &filePath );
|
|
|
|
|
|
/** return true if a file exisits. */
|
|
extern OSGDB_EXPORT bool fileExists(const std::string& filename);
|
|
|
|
/** return type of file. */
|
|
extern OSGDB_EXPORT FileType fileType(const std::string& filename);
|
|
|
|
/** find specified file in specified file path.*/
|
|
extern OSGDB_EXPORT std::string findFileInPath(const std::string& filename, const FilePathList& filePath,CaseSensitivity caseSensitivity=CASE_SENSITIVE);
|
|
|
|
/** return the directory/filename of a file if its is contained within specified directory.
|
|
* return "" if directory does not contain file. If caseInsensitive is set to true then
|
|
* a case insensitive comparison is used to compare fileName to directory contents.
|
|
* This is useful when unix programs attempt read case insentive windows filenames.
|
|
*/
|
|
extern OSGDB_EXPORT std::string findFileInDirectory(const std::string& fileName,const std::string& dirName,CaseSensitivity caseSensitivity=CASE_SENSITIVE);
|
|
|
|
/** simple list of names to represent a directory's contents. */
|
|
typedef std::vector<std::string> DirectoryContents;
|
|
|
|
/** return the contents of a directory.
|
|
* returns an empty array on any error.*/
|
|
extern OSGDB_EXPORT DirectoryContents getDirectoryContents(const std::string& dirName);
|
|
|
|
|
|
|
|
inline void setDataFilePathList(const FilePathList& filepath) { osgDB::Registry::instance()->setDataFilePathList(filepath); }
|
|
|
|
inline void setDataFilePathList(const std::string& paths) { osgDB::Registry::instance()->setDataFilePathList(paths); }
|
|
|
|
inline FilePathList& getDataFilePathList() { return osgDB::Registry::instance()->getDataFilePathList(); }
|
|
|
|
extern OSGDB_EXPORT std::string findDataFile(const std::string& filename,CaseSensitivity caseSensitivity=CASE_SENSITIVE);
|
|
|
|
/** Convinience class for pushing a path on construction, and popping the path
|
|
* and destruction. This helps keep the addition of a path local to a block
|
|
* of code, even in the presence of exceptions.*/
|
|
class PushAndPopDataPath
|
|
{
|
|
public:
|
|
PushAndPopDataPath(const std::string& path)
|
|
{
|
|
getDataFilePathList().push_front(path);
|
|
}
|
|
|
|
~PushAndPopDataPath()
|
|
{
|
|
getDataFilePathList().pop_front();
|
|
}
|
|
};
|
|
|
|
|
|
inline void setLibraryFilePathList(const FilePathList& filepaths) { osgDB::Registry::instance()->setLibraryFilePathList(filepaths); }
|
|
|
|
inline void setLibraryFilePathList(const std::string& paths) { osgDB::Registry::instance()->setLibraryFilePathList(paths); }
|
|
|
|
inline FilePathList& getLibraryFilePathList() { return osgDB::Registry::instance()->getLibraryFilePathList(); }
|
|
|
|
extern OSGDB_EXPORT std::string findLibraryFile(const std::string& filename,CaseSensitivity caseSensitivity=CASE_SENSITIVE);
|
|
|
|
/** convert a string containing a list of paths deliminated either with ';' (Windows) or ':' (All other platforms) into FilePath represetation.*/
|
|
extern OSGDB_EXPORT void convertStringPathIntoFilePathList(const std::string& paths,FilePathList& filepath);
|
|
|
|
extern OSGDB_EXPORT void appendPlatformSpecificLibraryFilePaths(FilePathList& filepath);
|
|
|
|
}
|
|
|
|
#endif
|