00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00022 #ifndef __LRT_FILE__
00023 #define __LRT_FILE__
00024
00025 #include "rtcollect.h"
00026
00027 #ifdef __SYMBIAN32__
00028 class TEntry;
00029 #endif
00030
00031 namespace lrt {
00032
00033 class File;
00034 class String;
00035 class InputStream;
00036 class OutputStream;
00037 class FileAttributes;
00038
00042 class IFilenameFilter
00043 {
00044 public:
00046 virtual ~IFilenameFilter() {}
00054 virtual bool accept(const File &parent, const String &child) const = 0;
00055 };
00056
00074 class File
00075 {
00076 public:
00079 static const char separatorChar;
00082 static const String separator;
00084 static const bool caseSensitive;
00085
00090 static void setCurrentFolder(const File &newFolder);
00093 static const String getCurrentFolder();
00097 static const File getExecutableFile();
00101 static const File getHomeFolder();
00107 static const File getSettingsFolder();
00113 static bool createFolder(const File& folder);
00117 static void initialize(const String &executableFileName);
00121 static void finalize();
00123 static bool isAbsolute(const String &fname);
00124
00126 File();
00129 File(const String &name);
00131 File(const File &);
00136 File(const File &parent, const String &child);
00138 File &operator=(const File &);
00139 ~File();
00142 String getName() const;
00146 String getFileName() const;
00151 String getLocalName(const File& relFile = (*currentFolder)) const;
00152
00155 String getParent() const;
00158 File getParentFile() const;
00159
00161 bool isFolder() const;
00164 bool isFile() const;
00166 bool exists();
00169 bool canWrite();
00172 bool canRead();
00174 int getSize();
00176 Time getLastModified();
00177
00182 InputStream *openRead(bool textMode);
00184 OutputStream *openWrite();
00186 OutputStream *openAppend();
00187
00192 Array<File> list();
00196 Array<File> list(const IFilenameFilter*);
00197
00198 private:
00199 static File *executableFile;
00200 static File *homeFolder;
00201 static File *settingsFolder;
00202 static File *currentFolder;
00203 static const int minNameCount;
00204
00205 static String getAbsolutePrefix();
00206
00207
00208
00209 static bool createSingleFolder(const File& folder);
00210
00211 enum Attrib { ATTRIB_TRUE, ATTRIB_FALSE, ATTRIB_UNKNOWN };
00212
00214 class FileAttributes {
00215 public:
00216 FileAttributes();
00217 FileAttributes(const FileAttributes &);
00218
00219 Attrib exists, isFolder, canWrite, canRead;
00220 int size;
00221 Time lastModified;
00222 };
00223
00224 File(Array<String>* names, FileAttributes* attribs);
00225
00226 void fetchAttributes();
00227 void resolve(File *file, const String& fname) const;
00228 bool resolveExtra(File *file, const String& fname) const;
00231
00232
00233 void set(Array<String>*);
00234 void set(Array<String>*, FileAttributes*);
00235
00236 #ifdef __SYMBIAN32__
00237 void setAttribs(TEntry& entry);
00238 #endif
00239
00240 Array<String>* names;
00241 FileAttributes* attribs;
00242
00243 friend class File::FileAttributes;
00244 };
00245
00250 class StarFilenameFilter : public IFilenameFilter {
00251
00252 public:
00263 static Array<File> getFiles(const String& query);
00264
00266 virtual bool accept(const File& parent, const String& child) const;
00267
00268 virtual ~StarFilenameFilter();
00269
00275 StarFilenameFilter(const String& query);
00276 private:
00277 Vector<String> queryComps;
00278
00279 int findQM(const String& a, const String& b, int fromPos = 0) const;
00280 };
00281
00282
00283
00284 }
00285
00286
00287 #endif