OpenSceneGraph/include/osgDB/FileUtils

104 lines
4.4 KiB
Plaintext
Raw Normal View History

2006-07-18 23:21:48 +08:00
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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
2001-09-28 20:36:40 +08:00
* 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(); }
/** Search for specified file in file system, checking the DataFilePathList for possible paths,
* returning the full path of the first valid file found, return an empty string if no string is found.
*/
extern OSGDB_EXPORT std::string findDataFile(const std::string& filename,CaseSensitivity caseSensitivity=CASE_SENSITIVE);
/** Search for specified file in file system, checking first the database path set in the Options structure, then the DataFilePathList for possible paths,
* returning the full path of the first valid file found, return an empty string if no string is found.
*/
extern OSGDB_EXPORT std::string findDataFile(const std::string& filename,const ReaderWriter::Options* options, CaseSensitivity caseSensitivity=CASE_SENSITIVE);
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);
From Jeremy Bell, "My patch is a slight refactoring of the mac specific code in Registry.cpp and FileUtils.cpp, specifically around the library and resource file path initilialization methods. This patch cleans up a lot of the mac specific code by moving repeated code into separate local functions in FileUtils.cpp that are only compiled on mac builds. It also adds one function to the API, appendPlatformSpecificResourceFilePaths in FileUtils. This function will mirror the already existing appendPlatformSpecificLibraryFilePaths except for resource file paths. Currently this function is empty except when built on the mac, in which case it will add the application bundle's internal Resources folder and the bundle's parent folder. Previously this code was implemented as a separate mac specific #ifdef block in Registry.cpp around the initDataFilePathList method. However, it now is implemented in appendPlatformSpecificResourceFilePaths in FileUtils.cpp and the initDataFilePathList method is now the same on all platforms. This patch should behave the same as before on non-mac platforms. This patch already includes the fix that Eric mentioned earlier. This patch is based off of the 0.99 release code. I have tested this patch using the following testing scheme: Make a proper bundled application. While Run from the Finder: Test that it finds plugins in its internal plugins path. Test that it finds resources in its internal resources path. Test that it finds resources in the bundle's parent directory Test that it finds plugins in the user's Application Support Directory Test that it finds plugins in the system's Application Support Directory Test that it finds plugins in the Network Application Support Directory Check the plugin and resource path lists after they have been initialized to see if they are in the correct order While Run from the command line (both from it's parent directory and from inside the /Contents/MacOS directory) and repeat the above tests. Check that it also finds plugins and resources within the paths defined by various environment variables. Now, Make an application that is NOT bundled/command line only Test that it does NOT try to look in an internal bundle plugin/resource directory for plugins or resources. Test that it finds plugins/resources in the paths defined by the environment variables. "
2005-07-27 05:07:31 +08:00
extern OSGDB_EXPORT void appendPlatformSpecificResourceFilePaths(FilePathList& filepath);
}
#endif