1 // FileStreams.h 2 3 #ifndef __FILE_STREAMS_H 4 #define __FILE_STREAMS_H 5 6 #ifdef _WIN32 7 #define USE_WIN_FILE 8 #endif 9 10 #include "../../Common/MyString.h" 11 12 #ifdef USE_WIN_FILE 13 #include "../../Windows/FileIO.h" 14 #else 15 #include "../../Common/C_FileIO.h" 16 #endif 17 18 #include "../../Common/MyCom.h" 19 20 #include "../IStream.h" 21 22 class CInFileStream: 23 public IInStream, 24 public IStreamGetSize, 25 #ifdef USE_WIN_FILE 26 public IStreamGetProps, 27 public IStreamGetProps2, 28 #endif 29 public CMyUnknownImp 30 { 31 public: 32 #ifdef USE_WIN_FILE 33 NWindows::NFile::NIO::CInFile File; 34 35 #ifdef SUPPORT_DEVICE_FILE 36 UInt64 VirtPos; 37 UInt64 PhyPos; 38 UInt64 BufStartPos; 39 Byte *Buf; 40 UInt32 BufSize; 41 #endif 42 43 #else 44 NC::NFile::NIO::CInFile File; 45 #endif 46 47 bool SupportHardLinks; 48 49 virtual ~CInFileStream(); 50 51 #ifdef SUPPORT_DEVICE_FILE 52 CInFileStream(); 53 #endif 54 Open(CFSTR fileName)55 bool Open(CFSTR fileName) 56 { 57 return File.Open(fileName); 58 } 59 OpenShared(CFSTR fileName,bool shareForWrite)60 bool OpenShared(CFSTR fileName, bool shareForWrite) 61 { 62 return File.OpenShared(fileName, shareForWrite); 63 } 64 65 MY_QUERYINTERFACE_BEGIN2(IInStream) 66 MY_QUERYINTERFACE_ENTRY(IStreamGetSize) 67 #ifdef USE_WIN_FILE 68 MY_QUERYINTERFACE_ENTRY(IStreamGetProps) 69 MY_QUERYINTERFACE_ENTRY(IStreamGetProps2) 70 #endif 71 MY_QUERYINTERFACE_END 72 MY_ADDREF_RELEASE 73 74 STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); 75 STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition); 76 77 STDMETHOD(GetSize)(UInt64 *size); 78 #ifdef USE_WIN_FILE 79 STDMETHOD(GetProps)(UInt64 *size, FILETIME *cTime, FILETIME *aTime, FILETIME *mTime, UInt32 *attrib); 80 STDMETHOD(GetProps2)(CStreamFileProps *props); 81 #endif 82 }; 83 84 class CStdInFileStream: 85 public ISequentialInStream, 86 public CMyUnknownImp 87 { 88 public: 89 MY_UNKNOWN_IMP 90 ~CStdInFileStream()91 virtual ~CStdInFileStream() {} 92 STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); 93 }; 94 95 class COutFileStream: 96 public IOutStream, 97 public CMyUnknownImp 98 { 99 public: 100 #ifdef USE_WIN_FILE 101 NWindows::NFile::NIO::COutFile File; 102 #else 103 NC::NFile::NIO::COutFile File; 104 #endif ~COutFileStream()105 virtual ~COutFileStream() {} Create(CFSTR fileName,bool createAlways)106 bool Create(CFSTR fileName, bool createAlways) 107 { 108 ProcessedSize = 0; 109 return File.Create(fileName, createAlways); 110 } Open(CFSTR fileName,DWORD creationDisposition)111 bool Open(CFSTR fileName, DWORD creationDisposition) 112 { 113 ProcessedSize = 0; 114 return File.Open(fileName, creationDisposition); 115 } 116 117 HRESULT Close(); 118 119 UInt64 ProcessedSize; 120 121 #ifdef USE_WIN_FILE SetTime(const FILETIME * cTime,const FILETIME * aTime,const FILETIME * mTime)122 bool SetTime(const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime) 123 { 124 return File.SetTime(cTime, aTime, mTime); 125 } SetMTime(const FILETIME * mTime)126 bool SetMTime(const FILETIME *mTime) { return File.SetMTime(mTime); } 127 #endif 128 129 130 MY_UNKNOWN_IMP1(IOutStream) 131 132 STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize); 133 STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition); 134 STDMETHOD(SetSize)(UInt64 newSize); 135 }; 136 137 class CStdOutFileStream: 138 public ISequentialOutStream, 139 public CMyUnknownImp 140 { 141 public: 142 MY_UNKNOWN_IMP 143 ~CStdOutFileStream()144 virtual ~CStdOutFileStream() {} 145 STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize); 146 }; 147 148 #endif 149