HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 <sys/types.h>
21 #include <UT/UT_Array.h>
22 #include <UT/UT_String.h>
23 #include <UT/UT_StringArray.h>
24 #include "FS_Info.h"
25 
26 typedef int (*FS_FileFilter)(const char *filename, void *data);
27 
29 public:
30  FS_FileSystem(const char *start_path="");
31  ~FS_FileSystem();
32 
33  // When over-riding the changePath() method, make sure to harden the myPath
34  // member data.
35 
36  int changePath(const char *newpath);
37  const char *getPath(char *buffer=0, int len=0);
38  void setPattern(const char *p) { myPattern.harden(p); }
39 
40  int canCreateDir(const char *path);
41  int createDir(const char *path);
42 
43  int canViewFile() const;
44  void viewFile(const char *path);
45 
46  // The pollDirectory() call should be called to load up the
47  // directories, files, and respective stats. This is NOT done automatically
48  // when changePath() is called.
49  int pollDirectory();
50  void forceReload()
51  {
52  // Cause a reload of directory next poll
53  myLastReadTime = 0;
54  }
55 
56  // Both of these methods (stat/access) return 1 if successful, 0 on fail.
57  // This is not like the unix system calls stat()/access() which return 0 on
58  // success, -1 on fail.
59  int statFile(const char *name, FS_Stat *stats=0);
60  int accessFile(const char *name, int access_mode);
61 
62  void setFileFilter(FS_FileFilter filter, void *data);
63  void setDirectoryFilter(FS_FileFilter filter, void *data);
64 
66  { return myDirectories; }
68  { return myFilenames; }
69  //UT_ValArray<char *> &getHiddenFiles() { return myFilenames; }
70  UT_Array<FS_Stat> &getFileStats() { return myFileStats; }
71  UT_Array<FS_Stat> &getDirStats () { return myDirStats; }
72 
73  void setHidden (bool hidden) { myIgnoreHidden = hidden; }
74  // By default, isRoot() checks the current path to see if it's "/"
75  int isRoot(const char *otherpath = 0);
76 
77 protected:
78  // Stat should return the last modification date of a directory. This
79  // allows us to determine whether the directory has been modified
80  // externally or not.
81  time_t statDirectory();
82 
83  // The readContents() method should return 1 if the directory was read
84  // successfully, 0 if there was an error.
85  // As a note, the file/directory filters will always be set. By default,
86  // they will return the filename passed in.
87  int readContents();
88 
89  /// It would be nice to sort these as we read them in but then the
90  /// fileStats will not match up. Therefore, we append entries now and
91  /// sort them later.
92  void addDirectory(const char *name, const FS_Stat &fstat);
93  void addFilename(const char *name, const FS_Stat &fstat);
94 
95  UT_String myPath, myLastReadPath;
96 
98 
101 
104 
105 private:
106  void clearLists();
107 
108  time_t myLastReadTime;
109  UT_StringArray myDirectories;
110  UT_StringArray myFilenames;
111  UT_String myPattern;
112 
113  UT_Array<FS_Stat> myFileStats;
114  UT_Array<FS_Stat> myDirStats;
115 };
116 
117 #endif
FS_FileFilter myFilter
Definition: FS_FileSystem.h:99
UT_StringArray & getFiles()
Definition: FS_FileSystem.h:67
UT_StringArray & getDirectories()
Definition: FS_FileSystem.h:65
UT_Array< FS_Stat > & getFileStats()
Definition: FS_FileSystem.h:70
GLsizei const GLchar *const * path
Definition: glcorearb.h:3340
void setHidden(bool hidden)
Definition: FS_FileSystem.h:73
GLuint buffer
Definition: glcorearb.h:659
void setPattern(const char *p)
Definition: FS_FileSystem.h:38
GLboolean * data
Definition: glcorearb.h:130
GLuint const GLchar * name
Definition: glcorearb.h:785
Helper class for encapsulating file information.
Definition: FS_Info.h:56
typedef int
Definition: png.h:1175
int(* FS_FileFilter)(const char *filename, void *data)
Definition: FS_FileSystem.h:26
UT_String myPath
Definition: FS_FileSystem.h:95
void forceReload()
Definition: FS_FileSystem.h:50
FS_FileFilter myDirFilter
void * myFilterData
void * myDirFilterData
#define FS_API
Definition: FS_API.h:10
UT_Array< FS_Stat > & getDirStats()
Definition: FS_FileSystem.h:71
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glcorearb.h:1296