Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

GFile.h

Go to the documentation of this file.
00001 
00009 #ifndef __FILE_H
00010 #define __FILE_H
00011 
00012 #include <fcntl.h>
00013 
00014 #include "LgiOsDefs.h"
00015 #include "GMem.h"
00016 #include "GStream.h"
00017 #include "GArray.h"
00018 
00019 #ifdef WIN32
00020 
00021 #include <dos.h>
00022 #include <sys\types.h>
00023 #include <sys\stat.h>
00024 #include <io.h>
00025 
00026 typedef HANDLE                          OsFile;
00027 #define INVALID_HANDLE                  INVALID_HANDLE_VALUE
00028 #define ValidHandle(hnd)                ((hnd) != INVALID_HANDLE_VALUE)
00029 
00030 #define O_READ                          GENERIC_READ
00031 #define O_WRITE                         GENERIC_WRITE
00032 #define O_READWRITE                     (GENERIC_READ | GENERIC_WRITE)
00033 #define O_SHARE                         0x01000000
00034 
00035 #else
00036 
00037 #include <sys/types.h>
00038 #include <sys/stat.h>
00039 #include <dirent.h>
00040 #include <unistd.h>
00041 
00042 typedef int                             OsFile;
00043 #define INVALID_HANDLE                  -1
00044 #define ValidHandle(hnd)                ((hnd) >= 0)
00045 
00046 #define O_READ                          O_RDONLY
00047 #define O_WRITE                         O_WRONLY
00048 #define O_READWRITE                     O_RDWR
00049 
00050 #endif
00051 
00053 // Defines
00054 #define FileDev                         (GFileSystem::GetInstance())
00055 #define MAX_PATH                        260
00056 
00057 // File system types (used by GDirectory and GVolume)
00058 #define VT_NONE                         0
00059 #define VT_3_5FLOPPY                    1
00060 #define VT_5_25FLOPPY                   2
00061 #define VT_HARDDISK                     3
00062 #define VT_CDROM                        4
00063 #define VT_RAMDISK                      5
00064 #define VT_REMOVABLE                    6
00065 #define VT_FOLDER                       7
00066 #define VT_FILE                         8
00067 #define VT_DESKTOP                      9
00068 #define VT_NETWORK_NEIGHBOURHOOD        10
00069 #define VT_NETWORK_MACHINE              11
00070 #define VT_NETWORK_SHARE                12
00071 #define VT_NETWORK_PRINTER              13
00072 #define VT_NETWORK_GROUP                14   // e.g. workgroup
00073 #define VT_MAX                          15
00074 
00075 // Volume attributes
00076 #define VA_CASE_SENSITIVE               0x0001
00077 #define VA_CASE_PRESERVED               0x0002
00078 #define VA_UNICODE_ON_DISK              0x0004
00079 #define VA_LFN_API                      0x4000
00080 #define VA_COMPRESSED                   0x8000
00081 
00082 // File attributes
00083 #define FA_NORMAL                       0x0000
00084 #define FA_READONLY                     0x0001
00085 #define FA_HIDDEN                       0x0002
00086 #define FA_SYSTEM                       0x0004
00087 #define FA_VOLUME                       0x0008
00088 #define FA_DIRECTORY                    0x0010
00089 #define FA_ARCHIVE                      0x0020
00090 
00092 // Abstract classes
00093 
00095 class LgiClass GDirectory
00096 {
00097 public:
00098     virtual ~GDirectory() { }
00099 
00103     virtual int First
00104     (
00106         char *Name,
00109         char *Pattern = LGI_ALL_FILES
00110     ) = 0;
00111     
00114     virtual int Next() = 0;
00115 
00118     virtual int Close() = 0;
00119 
00122     virtual bool Path
00123     (
00124         // The buffer to write to
00125         char *s,
00126         // The size of the output buffer in bytes
00127         int BufSize
00128     ) = 0;
00129 
00131     virtual long GetAttributes() = 0;
00132     
00134     virtual char *GetName() = 0;
00135     
00137     virtual int GetUser
00138     (
00140         bool Group
00141     ) = 0;
00142     
00144     virtual const uint64 GetCreationTime() = 0;
00145 
00147     virtual const uint64 GetLastAccessTime() = 0;
00148 
00150     virtual const uint64 GetLastWriteTime() = 0;
00151 
00153     virtual const uint64 GetSize() = 0;
00154 
00156     virtual bool IsDir() = 0;
00157     
00159     virtual bool IsReadOnly() = 0;
00160 
00163     virtual bool IsHidden() = 0;
00164 
00166     virtual GDirectory *Clone() = 0;
00167     
00169     virtual int GetType() = 0;
00170 
00172     bool ConvertToTime(char *Str, uint64 Time);
00173 
00175     bool ConvertToDate(char *Str, uint64 Time);
00176 };
00177 
00179 class LgiClass GVolume
00180 {
00181     friend class GFileSystem;
00182 
00183 protected:
00184     char *_Name;
00185     char *_Path;
00186     int _Type;          // VT_??
00187     int _Flags;         // VA_??
00188     int64 _Size;
00189     int64 _Free;
00190 
00191 public:
00192     GVolume();
00193     virtual ~GVolume();
00194 
00195     char *Name() { return _Name; }
00196     char *Path() { return _Path; }
00197     int Type() { return _Type; } // VT_??
00198     int Flags() { return _Flags; }
00199     uint64 Size() { return _Size; }
00200     uint64 Free() { return _Free; }
00201 
00202     virtual bool IsMounted() = 0;
00203     virtual bool SetMounted(bool Mount) = 0;
00204     virtual GVolume *First() = 0;
00205     virtual GVolume *Next() = 0;
00206     virtual GDirectory *GetContents() = 0;
00207 };
00208 
00209 
00211 class LgiClass GDirImpl : public GDirectory
00212 {
00213     class GDirImplPrivate *d;
00214     
00215 public:
00216     GDirImpl();
00217     ~GDirImpl();
00218 
00219     int First(char *Path, char *Pattern);
00220     int Next();
00221     int Close();
00222     bool Path(char *s, int len = -1);
00223     GDirectory *Clone();
00224 
00225     long GetAttributes();
00226     bool IsDir();
00227     bool IsHidden();
00228     bool IsReadOnly();
00229     char *GetName();
00230     const uint64 GetCreationTime();
00231     const uint64 GetLastAccessTime();
00232     const uint64 GetLastWriteTime();
00233     const uint64 GetSize();
00234     int GetUser(bool Group);
00235     int GetType();
00236 };
00237 
00239 class LgiClass GFileSystem
00240 {
00241     friend class GFile;
00242     static GFileSystem *Instance;
00243     class GFileSystemPrivate *d;
00244 
00245     GVolume *Root;
00246 
00247 public:
00248     GFileSystem();
00249     ~GFileSystem();
00250     
00251     #ifdef WIN32
00252     static bool Win9x;
00253     #endif
00254     
00256     static GFileSystem *GetInstance() { return Instance; }
00257 
00259     GVolume *GetRootVolume();
00260     
00262     GDirectory *GetDir();
00263 
00265     bool DeleteFile(char *FileName, bool ToTrash = true);
00267     bool DeleteFiles
00268     (
00270         GArray<char*> &Files,
00272         GArray<int> *Status = 0,
00274         bool ToTrash = true
00275     );
00276     
00278     bool CreateDirectory(char *PathName);
00279     
00281     bool RemoveDirectory
00282     (
00284         char *PathName,
00286         bool Recurse = false
00287     );
00288     
00289     bool SetCurrentDirectory(char *PathName);
00290     bool GetCurrentDirectory(char *PathName, int Length);
00291 
00293     bool MoveFile(char *OldName, char *NewName);
00294 };
00295 
00296 #ifdef BEOS
00297 
00298 #define GFileOps()                      \
00299     GFilePre char GFilePost;            \
00300     GFilePre int8 GFilePost;            \
00301     GFilePre uint8 GFilePost;           \
00302     GFilePre int16 GFilePost;           \
00303     GFilePre uint16 GFilePost;          \
00304     GFilePre signed int GFilePost;      \
00305     GFilePre unsigned int GFilePost;    \
00306     GFilePre signed long GFilePost;     \
00307     GFilePre unsigned long GFilePost;   \
00308     GFilePre int64 GFilePost;           \
00309     GFilePre uint64 GFilePost;          \
00310     GFilePre double GFilePost
00311 
00312 #else
00313 
00314 #define GFileOps()                      \
00315     GFilePre char GFilePost;            \
00316     GFilePre uint8 GFilePost;           \
00317     GFilePre int16 GFilePost;           \
00318     GFilePre uint16 GFilePost;          \
00319     GFilePre signed int GFilePost;      \
00320     GFilePre unsigned int GFilePost;    \
00321     GFilePre signed long GFilePost;     \
00322     GFilePre unsigned long GFilePost;   \
00323     GFilePre int64 GFilePost;           \
00324     GFilePre uint64 GFilePost;          \
00325     GFilePre double GFilePost
00326 
00327 #endif
00328 
00330 class LgiClass GFile : public GStream
00331 {
00332 protected:
00333     class GFilePrivate *d;
00334 
00335     int SwapRead(uchar *Buf, int Size);
00336     int SwapWrite(uchar *Buf, int Size);
00337 
00338 public:
00339     GFile();
00340     virtual ~GFile();
00341 
00342     OsFile Handle();
00343 
00346     int Open
00347     (
00349         char *Name,
00351         int Attrib
00352     );
00353     
00355     bool IsOpen();
00356     
00358     int Close();
00359     
00361     int GetOpenMode();
00362 
00365     int64 GetPos();
00366     
00369     int64 SetPos(int64 Pos);
00370 
00373     int64 GetSize();
00374 
00377     int64 SetSize(int64 Size);
00378 
00381     int Read(void *Buffer, int Size, int Flags = 0);
00382 
00385     int Write(void *Buffer, int Size, int Flags = 0);
00386 
00388     virtual char *GetName();
00389     
00391     virtual int64 Seek(int64 To, int Whence);
00392     
00394     virtual bool Eof();
00395 
00397     virtual void SetStatus(bool s = false);
00398     
00401     virtual bool GetStatus();
00402 
00405     virtual void SetSwap(bool s);
00406     
00408     virtual bool GetSwap();
00409 
00410     // String
00411     virtual int ReadStr(char *Buf, int Size);
00412     virtual int WriteStr(char *Buf, int Size);
00413 
00414     // Operators
00415     #define GFilePre        virtual GFile &operator >> (
00416     #define GFilePost       &i)
00417     GFileOps();
00418     #undef GFilePre
00419     #undef GFilePost
00420 
00421     #define GFilePre        virtual GFile &operator << (
00422     #define GFilePost       i)
00423     GFileOps();
00424     #undef GFilePre
00425     #undef GFilePost
00426 };
00427 
00428 // Functions
00429 LgiFunc int64 FileSize(char *FileName);
00430 LgiFunc bool FileExists(char *File);
00431 LgiFunc bool DirExists(char *Dir);
00432 LgiFunc bool ResolveShortcut(char *LinkFile, char *Path, int Len);
00433 LgiFunc void WriteStr(GFile &f, char *s);
00434 LgiFunc char *ReadStr(GFile &f DeclDebugArgs);
00435 LgiFunc int SizeofStr(char *s);
00436 LgiFunc char *ReadTextFile(char *File);
00437 LgiFunc bool LgiTrimDir(char *Path);
00438 LgiFunc char *LgiMakeRelitivePath(char *Base, char *Path);
00439 LgiFunc bool LgiMakePath(char *Str, int StrBufLen, char *Dir, char *File);
00440 LgiFunc char *LgiGetExtension(char *File);
00441 LgiFunc bool LgiIsFileNameExecutable(char *FileName);
00442 LgiFunc bool LgiIsFileExecutable(char *FileName, GStream *f, int64 Start, int64 Len);
00443 LgiFunc char *GetErrorName(int e);
00444 
00446 LgiFunc bool LgiGetDriveInfo(char *Path, uint64 *Free, uint64 *Size = 0, uint64 *Available = 0);
00447 
00448 #endif

Generated on Wed Oct 26 14:46:48 2005 for Lgi by  doxygen 1.4.1