File: FileUtils

package info (click to toggle)
openscenegraph 2.8.3-5
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 33,968 kB
  • ctags: 30,935
  • sloc: cpp: 287,169; ansic: 9,050; sh: 654; yacc: 548; objc: 374; makefile: 264; lex: 151; perl: 119
file content (113 lines) | stat: -rw-r--r-- 4,965 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* -*-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>
#include <stdio.h>

namespace osgDB {

enum CaseSensitivity
{
    CASE_SENSITIVE,
    CASE_INSENSITIVE
};

enum FileType
{
    FILE_NOT_FOUND,
    REGULAR_FILE,
    DIRECTORY
};

// Overload of the standard fopen function. If OSG_USE_UTF8_FILENAME is defined,
// filename will be expanded from UTF8 to UTF16 and _wfopen will be called.
extern OSGDB_EXPORT FILE* fopen(const char* filename, const char* mode);

// 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 );
    
// Get current working directory.
extern OSGDB_EXPORT std::string getCurrentWorkingDirectory( void );

// Set current working directory.
extern OSGDB_EXPORT bool setCurrentWorkingDirectory( const std::string &newCurrentWorkingDirectory );


/** return true if a file exists. */
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 insensitive 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 delimited either with ';' (Windows) or ':' (All other platforms) into FilePath representation.*/
extern OSGDB_EXPORT void convertStringPathIntoFilePathList(const std::string& paths,FilePathList& filepath);

extern OSGDB_EXPORT void appendPlatformSpecificLibraryFilePaths(FilePathList& filepath);
extern OSGDB_EXPORT void appendPlatformSpecificResourceFilePaths(FilePathList& filepath);

}

#endif