00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __FS_Info__
00020 #define __FS_Info__
00021
00022 #include "FS_API.h"
00023 #include <iostream.h>
00024 #include <SYS/SYS_Types.h>
00025 #include <UT/UT_Assert.h>
00026 #include <UT/UT_PtrArray.h>
00027 #include <UT/UT_RefArray.h>
00028 #include <UT/UT_String.h>
00029 #include <UT/UT_StringArray.h>
00030
00031 class FS_InfoHelper;
00032 class FS_IndexFile;
00033
00034 enum FS_FileAccessMode
00035 {
00036 FS_READ = 0x01,
00037 FS_WRITE = 0x02,
00038 FS_EXECUTE = 0x04
00039 };
00040
00041
00042 class FS_API FS_Stat
00043 {
00044 public:
00045 FS_Stat(time_t f_mtime = 0, int64 fsize = 0, bool is_dir = false, bool is_shortcut = false)
00046 : myModTime(f_mtime), mySize(fsize), myDirectory(is_dir), myShortcut(is_shortcut)
00047 {
00048 }
00049
00050
00051
00052 void updateSequenceStat(const FS_Stat &entry)
00053 {
00054
00055
00056 if (myModTime < entry.myModTime)
00057 myModTime = entry.myModTime;
00058
00059
00060 mySize += entry.mySize;
00061 }
00062
00063 bool operator==(const FS_Stat &s)
00064 {
00065 return (myModTime == s.myModTime
00066 && mySize == s.mySize
00067 && myDirectory == s.myDirectory
00068 && myShortcut == s.myShortcut);
00069 }
00070
00071 time_t myModTime;
00072 int64 mySize;
00073 bool myDirectory:1,
00074 myShortcut:1;
00075 };
00076
00077
00078 class FS_API FS_Info
00079 {
00080 public:
00081
00082
00083
00084 FS_Info(const char *source);
00085
00086 virtual ~FS_Info();
00087
00088
00089
00090
00091
00092
00093
00094
00095 bool hasAccess(int mode = 0) const;
00096
00097
00098 bool getIsDirectory() const;
00099
00100
00101
00102
00103 int getModTime() const;
00104
00105
00106 int64 getFileDataSize() const;
00107
00108
00109
00110
00111
00112
00113 bool getContents(UT_StringArray &contents,
00114 UT_StringArray *dirs = 0,
00115 UT_RefArray<FS_Stat> *stats = 0,
00116 UT_RefArray<FS_Stat> *dir_stats = 0
00117 );
00118
00119 bool fileExists() const;
00120 bool canReadFile() const;
00121 bool canWriteFile() const;
00122 bool canWriteDirectory() const;
00123 bool canDeleteFile() const;
00124 static char getNextSepChar(const char *source);
00125 static char getPrevSepChar(const char *source);
00126
00127 static bool getContentsFromIndexFile(FS_IndexFile &index,
00128 UT_StringArray &contents,
00129 UT_StringArray *dirs);
00130
00131 static bool statFile(const char *source,
00132 const char *filename,
00133 FS_Stat *fstat);
00134
00135
00136 static void addInfoHelper(FS_InfoHelper *helper);
00137 static void removeInfoHelper(FS_InfoHelper *helper);
00138
00139 private:
00140 static UT_PtrArray<FS_InfoHelper *> &getHelpers();
00141
00142 UT_String myPath;
00143 UT_String mySection;
00144 };
00145
00146 class FS_API FS_InfoHelper
00147 {
00148 public:
00149 FS_InfoHelper()
00150 { FS_Info::addInfoHelper(this); }
00151 virtual ~FS_InfoHelper()
00152 { FS_Info::removeInfoHelper(this); }
00153
00154 virtual bool canHandle(const char *source) = 0;
00155 virtual bool hasAccess(const char *source, int mode) = 0;
00156 virtual bool getIsDirectory(const char *source) = 0;
00157 virtual int getModTime(const char *source) = 0;
00158 virtual int64 getSize (const char *source) = 0;
00159 virtual bool getContents(const char *source,
00160 UT_StringArray &contents,
00161 UT_StringArray *dirs) = 0;
00162 virtual char getNextSepChar(const char * )
00163 { return '/'; }
00164 virtual char getPrevSepChar(const char * )
00165 { return '/'; }
00166 };
00167
00168 #endif
00169