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

Old GFile.h

00001 /*
00002 **  FILE:           File.h
00003 **  AUTHOR:         Matthew Allen
00004 **  DATE:           11/7/95
00005 **  DESCRIPTION:    File subsystem header
00006 **
00007 **
00008 **  Copyright (C) 1995, Matthew Allen
00009 **      fret@memecode.com
00010 */
00011 
00012 #ifndef __FILE_H
00013 #define __FILE_H
00014 
00015 #include <sys/types.h>
00016 #include <dirent.h>
00017 #include <unistd.h>
00018 #include <sys/stat.h>
00019 #include <fcntl.h>
00020 
00021 #include "LibDefs.h"
00022 #include "LgiOsDefs.h"
00023 #include "GMem.h"
00024 
00025 #define MAX_PATH                    256
00026 
00027 #define O_READ                      O_RDONLY
00028 #define O_WRITE                     O_WRONLY
00029 #define O_READWRITE                 O_RDWR
00030 
00031 #define ValidHandle(h)              (h >= 0)
00032 #define INVALID_HANDLE              -1
00033 
00034 // Time/Date related functions infomation
00035 #define DECNANOPERSEC               10000000
00036 #define SECPERMINUTE                60
00037 #define SECPERHOUR                  (60 * SECPERMINUTE)
00038 #define SECPERDAY                   (24 * SECPERHOUR)
00039 
00040 // File attributes
00041 #define FA_NORMAL                   0x0000
00042 #define FA_READONLY                 0x0001
00043 #define FA_HIDDEN                   0x0002
00044 #define FA_SYSTEM                   0x0004
00045 #define FA_VOLUME                   0x0008
00046 #define FA_DIRECTORY                0x0010
00047 #define FA_ARCHIVE                  0x0020
00048 
00049 class NodeInfo {
00050 protected:
00051     char *Name;
00052     int Attributes;
00053     quad Size;
00054 
00055 public:
00056     NodeInfo();
00057     NodeInfo(char *n, int a, quad s);
00058     virtual ~NodeInfo();
00059 
00060     virtual int operator ^(NodeInfo &N);
00061     char *GetName() { return Name; }
00062     int GetAttributes() { return Attributes; }
00063     quad GetSize() { return Size; }
00064 };
00065 
00066 class VDirectory {
00067 public:
00068     VDirectory() { }
00069     virtual ~VDirectory() { Close(); }
00070     virtual void GetDirType(char *Str, int Len) {}
00071     virtual bool First(char *Name, char Must, char Search) { return true; }
00072     virtual bool Next() { return true; }
00073     virtual bool Close() { return true; }
00074 
00075     virtual long GetAttributes() { return 0; }
00076     virtual bool IsDir() { return false; }
00077     virtual char *GetName() { return NULL; }
00078     virtual void GetName(char *Buf, int Len) { }
00079     virtual const quad GetCreationTime() { return 0; }
00080     virtual const quad GetLastAccessTime() { return 0; }
00081     virtual const quad GetLastWriteTime() { return 0; }
00082     virtual const quad GetSize() { return 0; }
00083 
00084     bool ConvertToTime(char *Str, quad Time);
00085     bool ConvertToDate(char *Str, quad Time);
00086 };
00087 
00088 class VDirView : public VDirectory {
00089 
00090     int Items;
00091     int Files;
00092     int Dirs;
00093     char CurrentDir[MAX_PATH];
00094 
00095     class Node : public NodeInfo {
00096 
00097         Node *Left, *Right;
00098 
00099     public:
00100         Node();
00101         Node(char *n, int a, quad s);
00102         ~Node();
00103 
00104         Node **Traverse(Node **ppNode, int Type);
00105         void Add(Node *Info);
00106 
00107     } *Root, **Index;
00108 
00109 public:
00110     VDirView();
00111     ~VDirView();
00112 
00113     bool Read(char *Dir);
00114 
00115     int GetFiles() { return Files; }
00116     NodeInfo *File(int i)
00117     {
00118         if (Index) return (NodeInfo*) Index[Dirs + i];
00119         return 0;
00120     }
00121 
00122     int GetDirs() { return Dirs; }
00123     NodeInfo *Dir(int i)
00124     {
00125         if (Index) return (NodeInfo*) Index[i];
00126         return 0;
00127     }
00128 
00129     int GetItems() { return Items; }
00130     NodeInfo *operator [](int i)
00131     {
00132         if (Index) return (NodeInfo*) Index[i];
00133         return 0;
00134     }
00135 };
00136 
00137 class VLinuxDir : public VDirView {
00138 
00139     DIR *Dir;
00140     char *Path;
00141 
00142     struct dirent *De;
00143     struct stat Stat;
00144 
00145 public:
00146     VLinuxDir();
00147     ~VLinuxDir();
00148 
00149     bool First(char *Name, char Must, char Search);
00150     bool Next();
00151     bool Close();
00152 
00153     long GetAttributes();
00154     bool IsDir();
00155     char *GetName();
00156     void GetName(char *Buf, int Len);
00157     const quad GetCreationTime();
00158     const quad GetLastAccessTime();
00159     const quad GetLastWriteTime();
00160     const quad GetSize();
00161 };
00162 
00163 // classes
00164 class VolumeInfo {
00165 public:
00166     char        Drive;
00167     char        Name[32];
00168     char        System[32];
00169     ulong       MaxPath;
00170     ulong       Flags;
00171 };
00172 
00173 #define DIF_NONE                    0
00174 #define DIF_3_5FLOPPY                   1
00175 #define DIF_5_25FLOPPY                  2
00176 #define DIF_HARDDISK                    3
00177 #define DIF_CDROM                   4
00178 #define DIF_NET                     5
00179 #define DIF_RAM                     6
00180 #define DIF_REMOVABLE                   7
00181 #define DIF_MAX                     9
00182 
00183 class DriveInfo {
00184 public:
00185     int     Type;
00186     char        Name[64];
00187     long        TotalSpace;
00188     long        FreeSpace;
00189 };
00190 
00191 #define FileDev         (FileDevice::GetInstance())
00192 
00193 class FileDevice
00194 {
00195     friend class GFile;
00196 
00197     char CurDir[256];
00198     int NumDrive;
00199     DriveInfo *DriveList;
00200     int FillDiskList();
00201 
00202     static FileDevice *Instance;
00203 
00204 public:
00205     FileDevice();
00206     virtual ~FileDevice();
00207     static FileDevice *GetInstance() { return Instance; }
00208 
00209     int GetNumDrives() { return NumDrive; }
00210     DriveInfo *GetDriveInfo(int Drive);
00211     VDirectory *GetDir(char *DirName);
00212 
00213     bool DeleteFile(char *FileName);
00214     bool CreateDirectory(char *PathName);
00215     bool RemoveDirectory(char *PathName);
00216     bool SetCurrentDirectory(char *PathName);
00217     bool GetCurrentDirectory(char *PathName, int Length);
00218     bool MoveFile(char *OldName, char *NewName);
00219     bool GetVolumeInfomation(char Drive, VolumeInfo *pInfo);
00220 };
00221 
00222 class GFile {
00223 protected:
00224     char    *Name;
00225     bool    Swap;
00226     bool    Status;
00227     int     Pos;
00228     int     Handle;
00229     int     Attributes;
00230 
00231     uchar *Buffer;
00232     int BufferSize;
00233     int Start, End;
00234 
00235     int BufferedRead(uchar *Buf, int Size);
00236     int BufferedWrite(uchar *Buf, int Size);
00237 
00238     int SwapRead(uchar *Buf, int Size);
00239     int SwapWrite(uchar *Buf, int Size);
00240 
00241 public:
00242     GFile();
00243     virtual ~GFile();
00244 
00245     virtual bool Open(char *Name, int Attrib);
00246     virtual bool Open();
00247     virtual bool Close();
00248 
00249     virtual int Read(void *Buffer, int Size);
00250     virtual int Write(void *Buffer, int Size);
00251     virtual int Seek(int To, int Whence);
00252     virtual int GetPosition();
00253     virtual int GetSize();
00254     virtual bool SetSize(int Size);
00255     virtual bool Eof();
00256     void SetStatus(bool s);
00257     bool GetStatus();
00258 
00259     // swap bytes on variable io
00260     void SetSwap(bool s) { Swap = s; }
00261     bool GetSwap() { return Swap; }
00262 
00263     int ReadStr(char *Buf, int Size);
00264     int WriteStr(char *Buf, int Size);
00265 
00266     int Print(char *Format, ...);
00267 
00268     // Read
00269     virtual GFile &operator >> (char        &i);
00270     virtual GFile &operator >> (signed char     &i);
00271     virtual GFile &operator >> (unsigned char   &i);
00272     virtual GFile &operator >> (signed short    &i);
00273     virtual GFile &operator >> (unsigned short  &i);
00274     virtual GFile &operator >> (signed int      &i);
00275     virtual GFile &operator >> (unsigned int    &i);
00276     virtual GFile &operator >> (signed long     &i);
00277     virtual GFile &operator >> (unsigned long   &i);
00278     virtual GFile &operator >> (float       &i);
00279     virtual GFile &operator >> (double      &i);
00280     virtual GFile &operator >> (long double     &i);
00281     virtual GFile &operator >> (quad        &i);
00282 
00283     // Write
00284     virtual GFile &operator << (char        i);
00285     virtual GFile &operator << (signed char     i);
00286     virtual GFile &operator << (unsigned char   i);
00287     virtual GFile &operator << (signed short    i);
00288     virtual GFile &operator << (unsigned short  i);
00289     virtual GFile &operator << (signed int      i);
00290     virtual GFile &operator << (unsigned int    i);
00291     virtual GFile &operator << (signed long     i);
00292     virtual GFile &operator << (unsigned long   i);
00293     virtual GFile &operator << (float       i);
00294     virtual GFile &operator << (double      i);
00295     virtual GFile &operator << (long double     i);
00296     virtual GFile &operator << (quad        i);
00297 };
00298 
00299 // C functions
00300 extern bool Match(char *Name, char *Mask);
00301 extern bool ResolveShortcut(char *LinkFile, char *Path, int Length);
00302 extern int FileSize(char *FileName);
00303 extern bool FileExists(char *Name);
00304 extern int SizeofStr(char *s);
00305 extern void WriteStr(GFile &f, char *s);
00306 extern char *ReadStr(GFile &f);
00307 extern bool TrimDir(char *Path);
00308 
00309 #endif

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