Subversion Repositories autosfx

Rev

Blame | Last modification | View Log | RSS feed

  1. #ifndef HelpersH
  2. #define HelpersH
  3.  
  4. /*
  5.   Helpers.h - internal 'stream' like helpers
  6.  
  7. ************************************************************************
  8.  Copyright (C) 2009, 2010  by Russell J. Peters, Roger Aelbrecht
  9.  
  10.    This file is part of TZipMaster Version 1.9.
  11.  
  12.     TZipMaster is free software: you can redistribute it and/or modify
  13.     it under the terms of the GNU Lesser General Public License as published by
  14.     the Free Software Foundation, either version 3 of the License, or
  15.     (at your option) any later version.
  16.  
  17.     TZipMaster is distributed in the hope that it will be useful,
  18.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20.     GNU Lesser General Public License for more details.
  21.  
  22.     You should have received a copy of the GNU Lesser General Public License
  23.     along with TZipMaster.  If not, see <http://www.gnu.org/licenses/>.
  24.  
  25.     contact: problems@delphizip.org (include ZipMaster in the subject).
  26.     updates: http://www.delphizip.org
  27.     DelphiZip maillist subscribe at http://www.freelists.org/list/delphizip
  28. ************************************************************************
  29.  
  30.   last modified 2009-07-05
  31. ---------------------------------------------------------------------------*/
  32.  
  33. // return >0 has drive, 0 no drive, -1 stream, -2 autostream
  34. bool __fastcall ZStreamStat(const char *fn, struct stati64 *res);
  35.  
  36. class ZStreamIO
  37. {
  38. private:
  39.     ZStreamIO(const ZStreamIO& src);
  40.     ZStreamIO& operator=(const ZStreamIO &src);
  41.     int canseek;
  42.     bool __fastcall GetIsSeekable(void);
  43. protected:
  44.     DZStrW ffname;
  45.     bool fFile;
  46.     bool fIsTemp;
  47.     DZOp *Owner;
  48.     virtual bool __fastcall DefSeekable(void) = 0;
  49. public:
  50.     ZStreamIO(DZOp *theOwner, const DZStrW& filename);
  51.     virtual ~ZStreamIO();
  52.     bool operator!() const;
  53.     virtual bool Read(LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
  54.                       LPDWORD lpNumberOfBytesRead) = 0;
  55.     virtual bool Write(LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite,
  56.                        LPDWORD lpNumberOfBytesWritten) = 0;
  57.     virtual __int64 SetPosition(__int64 ofs, int from) = 0;
  58.     virtual bool SetTime(const FILETIME* lpCreationTime,
  59.                          const FILETIME* lpLastAccessTime,
  60.                          const FILETIME* lpLastWriteTime) = 0;
  61.     virtual bool GetTime(FILETIME* lpCreationTime,
  62.                          FILETIME* lpLastAccessTime,
  63.                                                  FILETIME* lpLastWriteTime) = 0;
  64.         virtual bool SetEndOfFile(void);
  65.     virtual bool Close() = 0;
  66.     virtual bool IsOpen() const = 0;
  67.     __property bool IsFile = {read = fFile};
  68.     __property DZStrW fname = {read = ffname};
  69.     __property bool IsTemp = {read = fIsTemp, write = fIsTemp};
  70.     __property bool IsSeekable = {read = GetIsSeekable};
  71. };
  72.  
  73. class ZFile: public ZStreamIO
  74. {
  75. private:
  76.     ZFile(const ZFile& src);
  77.     ZFile& operator=(const ZFile &src);
  78.     HANDLE fHandle;
  79. protected:
  80.     virtual bool __fastcall DefSeekable(void);
  81. public:
  82.     ZFile(DZOp *theOwner, const DZStrW& lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
  83.           LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  84.           DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes);
  85.     ZFile(DZOp *theOwner, const DZStrW& lpFileName, DWORD Flags);
  86.     virtual ~ZFile();
  87.     bool Read(LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
  88.               LPDWORD lpNumberOfBytesRead);
  89.     bool Write(LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite,
  90.                LPDWORD lpNumberOfBytesWritten);
  91.     __int64 SetPosition(__int64 ofs, int from);
  92.     bool SetTime(const FILETIME* lpCreationTime,
  93.                  const FILETIME* lpLastAccessTime,
  94.                  const FILETIME* lpLastWriteTime);
  95.     bool GetTime(FILETIME* lpCreationTime,
  96.                  FILETIME* lpLastAccessTime,
  97.                                  FILETIME* lpLastWriteTime);
  98.         bool SetEndOfFile(void);
  99.     bool Close();
  100.         bool IsOpen() const;
  101. };
  102.  
  103. class ZStream: public ZStreamIO
  104. {
  105. private:
  106.     ZStream(const ZStream& src);
  107.     ZStream& operator=(const ZStream &src);
  108.     bool CanClose;
  109.     void* zHandle;
  110.     int Number;
  111. protected:
  112.     virtual bool __fastcall DefSeekable(void);
  113. public:
  114.     ZStream(DZOp *theOwner, const DZStrW& filename, void* astream);
  115.     ZStream(DZOp *theOwner, const DZStrW& filename);
  116.     virtual ~ZStream();
  117.     bool Read(LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
  118.               LPDWORD lpNumberOfBytesRead);
  119.     bool Write(LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite,
  120.                LPDWORD lpNumberOfBytesWritten);
  121.     __int64 SetPosition(__int64 ofs, int from);
  122.     bool SetTime(const FILETIME* lpCreationTime,
  123.                  const FILETIME* lpLastAccessTime,
  124.                  const FILETIME* lpLastWriteTime);
  125.     bool GetTime(FILETIME* lpCreationTime,
  126.                  FILETIME* lpLastAccessTime,
  127.                                  FILETIME* lpLastWriteTime);
  128.     bool Close();
  129.         bool IsOpen() const;
  130. };
  131.  
  132. class AutoStream
  133. {
  134. private:
  135.     AutoStream(const AutoStream& src);
  136.     AutoStream& operator=(const AutoStream &src);
  137.     ZStreamIO **theStream;
  138. public:
  139.     AutoStream(ZStreamIO **zs);
  140.     ~AutoStream();
  141.     operator ZStreamIO*()const
  142.     {
  143.         return *theStream;
  144.     };
  145.  
  146.     void Assign(ZStreamIO **zs);
  147.     ZStreamIO *Stream()
  148.     {
  149.         return *theStream;
  150.     };
  151. };
  152.  
  153. #endif
  154.  
  155.  
  156.  
  157.