| [5328] | 1 | /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield |
|---|
| [1529] | 2 | * |
|---|
| 3 | * This library is open source and may be redistributed and/or modified under |
|---|
| 4 | * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or |
|---|
| 5 | * (at your option) any later version. The full license is in LICENSE file |
|---|
| 6 | * included with this distribution, and on the openscenegraph.org website. |
|---|
| 7 | * |
|---|
| 8 | * This library is distributed in the hope that it will be useful, |
|---|
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 11 | * OpenSceneGraph Public License for more details. |
|---|
| 12 | */ |
|---|
| [51] | 13 | |
|---|
| [8] | 14 | #ifndef OSGDB_FILEUTILS |
|---|
| 15 | #define OSGDB_FILEUTILS 1 |
|---|
| 16 | |
|---|
| [773] | 17 | #include <osgDB/Registry> |
|---|
| [8] | 18 | |
|---|
| 19 | #include <vector> |
|---|
| [773] | 20 | #include <deque> |
|---|
| [8] | 21 | #include <string> |
|---|
| [9475] | 22 | #include <stdio.h> |
|---|
| [8] | 23 | |
|---|
| 24 | namespace osgDB { |
|---|
| 25 | |
|---|
| [2971] | 26 | enum FileType |
|---|
| 27 | { |
|---|
| 28 | FILE_NOT_FOUND, |
|---|
| 29 | REGULAR_FILE, |
|---|
| [5142] | 30 | DIRECTORY |
|---|
| [2971] | 31 | }; |
|---|
| [2444] | 32 | |
|---|
| [9124] | 33 | // Overload of the standard fopen function. If OSG_USE_UTF8_FILENAME is defined, |
|---|
| 34 | // filename will be expanded from UTF8 to UTF16 and _wfopen will be called. |
|---|
| 35 | extern OSGDB_EXPORT FILE* fopen(const char* filename, const char* mode); |
|---|
| 36 | |
|---|
| [3367] | 37 | // Make a new directory. Returns true if directory exists or was created. |
|---|
| 38 | extern OSGDB_EXPORT bool makeDirectory( const std::string &directoryPath ); |
|---|
| [2971] | 39 | |
|---|
| [3367] | 40 | // Make a new directory for a given file. |
|---|
| 41 | extern OSGDB_EXPORT bool makeDirectoryForFile( const std::string &filePath ); |
|---|
| 42 | |
|---|
| [10818] | 43 | // Get current working directory. |
|---|
| 44 | extern OSGDB_EXPORT std::string getCurrentWorkingDirectory( void ); |
|---|
| [3367] | 45 | |
|---|
| [10818] | 46 | // Set current working directory. |
|---|
| 47 | extern OSGDB_EXPORT bool setCurrentWorkingDirectory( const std::string &newCurrentWorkingDirectory ); |
|---|
| 48 | |
|---|
| 49 | |
|---|
| [7648] | 50 | /** return true if a file exists. */ |
|---|
| [1363] | 51 | extern OSGDB_EXPORT bool fileExists(const std::string& filename); |
|---|
| [8] | 52 | |
|---|
| [2971] | 53 | /** return type of file. */ |
|---|
| 54 | extern OSGDB_EXPORT FileType fileType(const std::string& filename); |
|---|
| [8] | 55 | |
|---|
| [773] | 56 | /** find specified file in specified file path.*/ |
|---|
| [2444] | 57 | extern OSGDB_EXPORT std::string findFileInPath(const std::string& filename, const FilePathList& filePath,CaseSensitivity caseSensitivity=CASE_SENSITIVE); |
|---|
| [136] | 58 | |
|---|
| [8] | 59 | /** return the directory/filename of a file if its is contained within specified directory. |
|---|
| 60 | * return "" if directory does not contain file. If caseInsensitive is set to true then |
|---|
| [31] | 61 | * a case insensitive comparison is used to compare fileName to directory contents. |
|---|
| [7648] | 62 | * This is useful when unix programs attempt read case insensitive windows filenames. |
|---|
| [8] | 63 | */ |
|---|
| [2444] | 64 | extern OSGDB_EXPORT std::string findFileInDirectory(const std::string& fileName,const std::string& dirName,CaseSensitivity caseSensitivity=CASE_SENSITIVE); |
|---|
| [8] | 65 | |
|---|
| [773] | 66 | /** simple list of names to represent a directory's contents. */ |
|---|
| 67 | typedef std::vector<std::string> DirectoryContents; |
|---|
| 68 | |
|---|
| [8] | 69 | /** return the contents of a directory. |
|---|
| 70 | * returns an empty array on any error.*/ |
|---|
| [1363] | 71 | extern OSGDB_EXPORT DirectoryContents getDirectoryContents(const std::string& dirName); |
|---|
| [8] | 72 | |
|---|
| 73 | |
|---|
| [773] | 74 | |
|---|
| 75 | inline void setDataFilePathList(const FilePathList& filepath) { osgDB::Registry::instance()->setDataFilePathList(filepath); } |
|---|
| 76 | |
|---|
| 77 | inline void setDataFilePathList(const std::string& paths) { osgDB::Registry::instance()->setDataFilePathList(paths); } |
|---|
| 78 | |
|---|
| 79 | inline FilePathList& getDataFilePathList() { return osgDB::Registry::instance()->getDataFilePathList(); } |
|---|
| 80 | |
|---|
| [3689] | 81 | /** Search for specified file in file system, checking the DataFilePathList for possible paths, |
|---|
| 82 | * returning the full path of the first valid file found, return an empty string if no string is found. |
|---|
| 83 | */ |
|---|
| [2444] | 84 | extern OSGDB_EXPORT std::string findDataFile(const std::string& filename,CaseSensitivity caseSensitivity=CASE_SENSITIVE); |
|---|
| [773] | 85 | |
|---|
| [3689] | 86 | /** Search for specified file in file system, checking first the database path set in the Options structure, then the DataFilePathList for possible paths, |
|---|
| 87 | * returning the full path of the first valid file found, return an empty string if no string is found. |
|---|
| 88 | */ |
|---|
| [10171] | 89 | extern OSGDB_EXPORT std::string findDataFile(const std::string& filename,const Options* options, CaseSensitivity caseSensitivity=CASE_SENSITIVE); |
|---|
| [3689] | 90 | |
|---|
| [773] | 91 | inline void setLibraryFilePathList(const FilePathList& filepaths) { osgDB::Registry::instance()->setLibraryFilePathList(filepaths); } |
|---|
| 92 | |
|---|
| 93 | inline void setLibraryFilePathList(const std::string& paths) { osgDB::Registry::instance()->setLibraryFilePathList(paths); } |
|---|
| 94 | |
|---|
| 95 | inline FilePathList& getLibraryFilePathList() { return osgDB::Registry::instance()->getLibraryFilePathList(); } |
|---|
| 96 | |
|---|
| [2444] | 97 | extern OSGDB_EXPORT std::string findLibraryFile(const std::string& filename,CaseSensitivity caseSensitivity=CASE_SENSITIVE); |
|---|
| [773] | 98 | |
|---|
| [10818] | 99 | /** convert a string containing a list of paths delimited either with ';' (Windows) or ':' (All other platforms) into FilePath representation.*/ |
|---|
| [3330] | 100 | extern OSGDB_EXPORT void convertStringPathIntoFilePathList(const std::string& paths,FilePathList& filepath); |
|---|
| [773] | 101 | |
|---|
| [3330] | 102 | extern OSGDB_EXPORT void appendPlatformSpecificLibraryFilePaths(FilePathList& filepath); |
|---|
| [4420] | 103 | extern OSGDB_EXPORT void appendPlatformSpecificResourceFilePaths(FilePathList& filepath); |
|---|
| [3330] | 104 | |
|---|
| [349] | 105 | } |
|---|
| [8] | 106 | |
|---|
| 107 | #endif |
|---|