HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FS_FileSystem.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: FS_FileSystem.h ( SI Library, C++)
7  *
8  * COMMENTS: This provides a "filesystem" interface that's used by
9  * SI_FileChooser.[Ch] This is used both by the Unix/NT file
10  * system and the Houdini OP "filesystem"
11  *
12  * This class does not ever include "." or ".." in the directory
13  * list.
14  */
15 
16 #ifndef __FS_FileSystem__
17 #define __FS_FileSystem__
18 
19 #include "FS_API.h"
20 #include <UT/UT_Array.h>
21 #include <UT/UT_String.h>
22 #include <UT/UT_StringArray.h>
23 #include <time.h>
24 
25 class FS_Stat;
26 
27 typedef int (*FS_FileFilter)(const char *filename, void *data);
28 
30 public:
31  FS_FileSystem(const char *start_path="");
32  ~FS_FileSystem();
33 
34  // When over-riding the changePath() method, make sure to harden the myPath
35  // member data.
36 
37  int changePath(const char *newpath);
38  const char *getPath(char *buffer=0, int len=0);
39  void setPattern(const char *p) { myPattern.harden(p); }
40 
41  int canCreateDir(const char *path);
42  int createDir(const char *path);
43 
44  int canViewFile() const;
45  void viewFile(const char *path);
46 
47  // The pollDirectory() call should be called to load up the
48  // directories, files, and respective stats. This is NOT done automatically
49  // when changePath() is called.
50  int pollDirectory();
51  void forceReload()
52  {
53  // Cause a reload of directory next poll
54  myLastReadTime = 0;
55  }
56 
57  // Both of these methods (stat/access) return 1 if successful, 0 on fail.
58  // This is not like the unix system calls stat()/access() which return 0 on
59  // success, -1 on fail.
60  int statFile(const char *name, FS_Stat *stats=0);
61  int accessFile(const char *name, int access_mode);
62 
63  void setFileFilter(FS_FileFilter filter, void *data);
64  void setDirectoryFilter(FS_FileFilter filter, void *data);
65 
67  { return myDirectories; }
69  { return myFilenames; }
70  //UT_ValArray<char *> &getHiddenFiles() { return myFilenames; }
71  UT_Array<FS_Stat> &getFileStats() { return myFileStats; }
72  UT_Array<FS_Stat> &getDirStats () { return myDirStats; }
73 
74  void setHidden (bool hidden) { myIgnoreHidden = hidden; }
75  // By default, isRoot() checks the current path to see if it's "/"
76  int isRoot(const char *otherpath = 0);
77 
78 protected:
79  // Stat should return the last modification date of a directory. This
80  // allows us to determine whether the directory has been modified
81  // externally or not.
82  time_t statDirectory();
83 
84  // The readContents() method should return 1 if the directory was read
85  // successfully, 0 if there was an error.
86  // As a note, the file/directory filters will always be set. By default,
87  // they will return the filename passed in.
88  int readContents();
89 
90  /// It would be nice to sort these as we read them in but then the
91  /// fileStats will not match up. Therefore, we append entries now and
92  /// sort them later.
93  void addDirectory(const char *name, const FS_Stat &fstat);
94  void addFilename(const char *name, const FS_Stat &fstat);
95 
96  UT_String myPath, myLastReadPath;
97 
99 
102 
105 
106 private:
107  void clearLists();
108 
109  time_t myLastReadTime;
110  UT_StringArray myDirectories;
111  UT_StringArray myFilenames;
112  UT_String myPattern;
113 
114  UT_Array<FS_Stat> myFileStats;
115  UT_Array<FS_Stat> myDirStats;
116 };
117 
118 #endif
FS_FileFilter myFilter
GT_API const UT_StringHolder filename
GLuint const GLchar * name
Definition: glew.h:1814
UT_StringArray & getFiles()
Definition: FS_FileSystem.h:68
UT_StringArray & getDirectories()
Definition: FS_FileSystem.h:66
UT_Array< FS_Stat > & getFileStats()
Definition: FS_FileSystem.h:71
void setHidden(bool hidden)
Definition: FS_FileSystem.h:74
void setPattern(const char *p)
Definition: FS_FileSystem.h:39
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glew.h:2981
GLuint buffer
Definition: glew.h:1680
GLint GLenum GLsizei GLint GLsizei const void * data
Definition: glew.h:1379
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
Helper class for encapsulating file information.
Definition: FS_Info.h:56
GLsizei const GLchar *const * path
Definition: glew.h:6461
GLfloat GLfloat p
Definition: glew.h:16321
int(* FS_FileFilter)(const char *filename, void *data)
Definition: FS_FileSystem.h:27
UT_String myPath
Definition: FS_FileSystem.h:96
void forceReload()
Definition: FS_FileSystem.h:51
FS_FileFilter myDirFilter
void * myFilterData
void * myDirFilterData
#define FS_API
Definition: FS_API.h:10
GLenum GLsizei len
Definition: glew.h:7752
UT_Array< FS_Stat > & getDirStats()
Definition: FS_FileSystem.h:72