include/df/file.hpp

00001 class File : public SystemCode {
00002     friend class FileFind;
00003     friend class FileFindArc;
00004     friend class ComPort;
00005   _PROTECTED_:
00006     int32 handle;
00007   public:
00008     BOOL Valid;    //is class valid (file opened?)
00009     //constructors
00010     File();
00011     //destructors
00012     ~File();
00013     //normal/arc functions
00014     BOOL Open(char *_filename, int _action, int attr = 0, int _share = 0);
00015     virtual BOOL Close();
00016     virtual int32 Read(PTR buf, uint32 siz);
00017     virtual int32 Write(PTR buf, uint32 siz);
00018     virtual uint32 Seek(int32 offset, int8 fromwhere);
00019     virtual uint64 Seek64(int64 offset, int8 fromwhere);
00020     uint32 SetPos(uint32 offset) { return Seek(offset, SEEK_SET);}
00021     uint32 SetPos64(uint64 offset) { return Seek64(offset, SEEK_SET);}
00022     virtual uint32 GetPos();  //get file position
00023     virtual uint64 GetPos64();  //get file position
00024     virtual uint32 GetSize();  //return size of file
00025     virtual uint64 GetSize64();  //return size of file
00026     //file stuff only
00027     int32 Write(const char *str) { return Write((PTR)str, strlen(str));}
00028     BOOL Eof();
00029     //the rest are based on C-functions
00030     uint32 Tell() { return GetPos();}  //ANSI-C
00031     uint64 Tell64() { return GetPos64();}  //ANSI-C
00032     //BUG! The following do not RaiseException() on errors
00033 #ifndef _CONSOLE  //BUG! These cause problems in CONSOLE apps
00034     char PutChar(char _c) { if (Write(&_c, 1) != 1) return -1; return _c;}
00035     char GetChar() { char _c; if (Read(&_c, 1) != 1) return -1; return _c;}
00036 #endif
00037     int32 GetHandle() { return handle;}
00038     //the following will always return FALSE with files inside ARCs
00039     virtual BOOL SetEof();
00040     BOOL Truncate() { return SetEof();}
00041     BOOL Sync();      //flush all buffers
00042     //system wide functions
00043     static BOOL Exist(char *_filename);
00044     static BOOL Delete(char *fname);       //del x  (no wildcards)
00045     static BOOL DeleteEx(char *fname);     //del x  (wildcards OK) //DF/0.5.5 : New member
00046     static BOOL DeletePathEx(char *path);  //deltree (delete all files/folders!!!)
00047     static BOOL Rename(char *oldname, char *newname);
00048     static int32 GetSize(char *fname);
00049     static BOOL GetAttr(char *fname, int32 &attr);
00050     static BOOL SetAttr(char *fname, int32 attr);
00051     static BOOL DeletePath(char *name);         //rd x
00052     static BOOL CreatePath(char *name);         //md x
00053     static BOOL CreatePathEx(char *name);       //md x/y/z
00054     static BOOL SetCurrentPath(char *name);     //cd x
00055     static BOOL GetCurrentPath(String &);       //cd
00056     static void Split(const char *full, String *drv, String *path, String *nam, String *ext);
00057     // Splits 'full' into 'drv' 'path' 'nam' and 'ext'
00058     static void Merge(String &full, const char *drv, const char *path, const char *nam, const char *ext);
00059     // Merges ('drv' 'path' 'nam' and 'ext') into 'full'
00060     static BOOL GetShort(String &_short, char *_long);
00061     //system paths
00062     static void GetTempPath(String &s);
00063     static void GetTempFileName(String &s, char *ext = NULL);
00064     static void GetOSPath(String &s);
00065     static BOOL GetStartMenuPath(String &s, BOOL AllUsers = TRUE);
00066     static BOOL GetDesktopPath(String &s);
00067     //version info
00068     static BOOL GetVersion(char *fname, Version &ver, char *verfn = "$DFVER$.TMP");  //also try $SSLVER$.TMP
00069     //see SystemCode::CmpVersion(v1,v2);
00070     //copy/move
00071     static BOOL CopyFile(char *src, char *dest, BOOL deldst = FALSE);
00072     static BOOL MoveFile(char *src, char *dest, BOOL deldst = FALSE);
00073     //misc
00074     static BOOL WildcardCompare(char *wc, char *fn, BOOL cs = CASE_SENSITIVE);
00075     //DF/1.5.5 - new members
00076     static BOOL GetDeviceFreeSpace(char *, uint64 &free);
00077     static BOOL IsDeviceRemovable(char *);
00078     static BOOL GetTime(char *file, Time *creation, Time *lastaccess = (Time*)NULL, Time *lastwrite = (Time*)NULL);
00079     static BOOL SetTime(char *file, Time *creation, Time *lastaccess = (Time*)NULL, Time *lastwrite = (Time*)NULL);
00080     static BOOL IsFolder(uint32 attr);
00081     static BOOL IsReadOnly(uint32 attr);
00082     //DF/3.0 - new members
00083     static BOOL GetFullPath(String &fn, char *currentpath = NULL);  //resolves "." and ".."
00084 };
00085 
00086 class MemFile : public File {
00087   _PROTECTED_:
00088     PTR mem;
00089     uint32 pos;
00090     uint32 siz;
00091     BOOL freeonclose;
00092   public:
00093     BOOL Open(PTR data, uint32 size);  //will not Free() on Close()
00094     BOOL Open(char *_filename, int _action, int _attribute = 0, int _share = 0);
00095     BOOL Open(char *_filename, char *_subname);
00096     BOOL Open(uint32 siz, BOOL ZeroMemory = FALSE);
00097     BOOL Open(Archive *, char *_filename);  //loads a file from Arc File
00098     virtual BOOL Close();
00099     virtual int32 Read(PTR buf, uint32 siz);
00100     virtual int32 Write(PTR buf, uint32 siz);
00101     int32 Write(const char *str) { return Write((PTR)str, strlen(str));}
00102     virtual uint32 Seek(int32 offset, int8 fromwhere);
00103     virtual uint64 Seek64(int64 offset, int8 fromwhere) {return Seek(offset, fromwhere);}
00104     virtual uint32 GetPos() { return pos;}
00105     virtual uint64 GetPos64() { return pos;}
00106     virtual uint32 GetSize() { return siz;}
00107     virtual uint64 GetSize64() { return siz;}
00108     virtual BOOL SetEof();
00109     void Compact();
00110     PTR GetPTR() { return mem;}
00111     MemFile() {mem = (PTR)NULL;pos = siz = 0;}
00112     ~MemFile() {Close();}
00113 };
00114 
00115 class dfarc;  //forward decl
00116 
00117 //Compression Types (32bits)
00118 
00119 #define DFA_CT_NONE     1  //data stored "as is"
00120 #define DFA_CT_ZLIB     2  //default
00121 #define DFA_CT_BZ2      3  //future implementation
00122 #define DFA_CT_LZMA     4  //future implementation (LGPL/CPL)
00123 
00124 //Checksum types (32bits)
00125 
00126 #define DFA_CS_NONE     0  //should be omited from physical file
00127 #define DFA_CS_MD5      1  //MD5 checksum (128bit)
00128 
00129 class Archive : public SystemCode {
00130     friend class ArchiveFind;
00131   private:
00132     File f;
00133     dfarc *arc;
00134     int ct;  //compression type
00135     int cst;  //checksum type
00136     BOOL Valid;
00137     int GetCount();
00138   public:
00139     Archive() {ct= DFA_CT_ZLIB; cst = DFA_CS_MD5; Valid = FALSE;}
00140     ~Archive() {CloseArchive();}
00141     //ZIP functions
00142     BOOL OpenArchive(char *_fn, char *_subname = (char*)NULL);
00143     //fn=filename subname=assigned package name(if used XADDFILE utility)
00144     // else subname=NULL
00145     BOOL OpenArchive(char *_fn, int flgs, int initseekpos = 0);  //flgs = FO_RDONLY | FO_CREATE | FO_RDWR
00146     BOOL CloseArchive();
00147     BOOL Extract(char *fn, char *destpath, BOOL expandpath = TRUE, BOOL overwrite = TRUE);
00148     BOOL Extract(char *fn, File &dest);
00149     BOOL Add(char *fn, char *path);  //add fn
00150     BOOL SetPassword(char *);  //currently not implemented
00151     void SetCompressionType(int _ct) {ct = _ct;}
00152     void SetChecksumType(int _cst) {cst = _cst;}
00153 };
00154 
00155 class FileFind : public Enumerator {
00156   _PROTECTED_:
00157     iPTR ff_reserved;  // HANDLE
00158     int ff_idx;        //internal usage only! (needed by Win32 API)
00159     String mask;       //internal usage only! (needed by Linux API)
00160     String path;       //internal usage only! (needed by Linux API)
00161   public:
00162     //ctor/dtor
00163     FileFind() { ff_reserved = 0; }
00164     ~FileFind() { if (ff_reserved) Close(); }
00165     //public members
00166     BOOL First(char *fname);
00167     BOOL Next();
00168     BOOL Close();
00169 };
00170 
00171 class ArchiveFind : public Enumerator {
00172   _PROTECTED_:
00173     int32 idx;      //idx into package
00174     uint32 count;   //# of entries in archive
00175     Archive *arc;
00176     String mask;
00177   public:
00178     //NOTE : only ff_name is filed in !!!
00179     ArchiveFind();
00180     ArchiveFind(Archive *);
00181     void SetArchive(Archive *);
00182     BOOL First(char *mask);
00183     BOOL Next();
00184     BOOL Close() {return TRUE;}  //nothing to do
00185 };
00186 
00187 class LogFile : public SystemCode {
00188   _PROTECTED_:
00189     String path;
00190     File f;
00191     Time t;
00192     BOOL _open();
00193     ExclusiveUsage usage;  //private usage DF/1.0.1
00194   public:
00195     ExclusiveUsage Usage;  //public usage
00196     LogFile();
00197     BOOL Valid;
00198     BOOL Open(char *path);
00199     BOOL Close();
00200     BOOL Write(PTR, uint32);
00201     BOOL Write(char *, ...);  //DF/3.5 - printf style
00202     BOOL Sync();  //DF/1.3.1
00203 };

Generated on Mon Mar 5 09:49:14 2007 for DigiForce by  doxygen 1.4.7