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 #ifdef _WIN32 23 typedef UINT_PTR My_UINT_PTR; 24 #else 25 typedef UINT My_UINT_PTR; 26 #endif 27 28 struct IInFileStream_Callback 29 { 30 virtual HRESULT InFileStream_On_Error(My_UINT_PTR val, DWORD error) = 0; 31 virtual void InFileStream_On_Destroy(My_UINT_PTR val) = 0; 32 }; 33 34 class CInFileStream: 35 public IInStream, 36 public IStreamGetSize, 37 #ifdef USE_WIN_FILE 38 public IStreamGetProps, 39 public IStreamGetProps2, 40 #endif 41 public CMyUnknownImp 42 { 43 public: 44 #ifdef USE_WIN_FILE 45 NWindows::NFile::NIO::CInFile File; 46 47 #ifdef SUPPORT_DEVICE_FILE 48 UInt64 VirtPos; 49 UInt64 PhyPos; 50 UInt64 BufStartPos; 51 Byte *Buf; 52 UInt32 BufSize; 53 #endif 54 55 #else 56 NC::NFile::NIO::CInFile File; 57 #endif 58 59 bool SupportHardLinks; 60 61 IInFileStream_Callback *Callback; 62 My_UINT_PTR CallbackRef; 63 64 virtual ~CInFileStream(); 65 66 CInFileStream(); 67 68 bool Open(CFSTR fileName) 69 { 70 return File.Open(fileName); 71 } 72 73 bool OpenShared(CFSTR fileName, bool shareForWrite) 74 { 75 return File.OpenShared(fileName, shareForWrite); 76 } 77 78 MY_QUERYINTERFACE_BEGIN2(IInStream) 79 MY_QUERYINTERFACE_ENTRY(IStreamGetSize) 80 #ifdef USE_WIN_FILE 81 MY_QUERYINTERFACE_ENTRY(IStreamGetProps) 82 MY_QUERYINTERFACE_ENTRY(IStreamGetProps2) 83 #endif 84 MY_QUERYINTERFACE_END 85 MY_ADDREF_RELEASE 86 87 STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); 88 STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition); 89 90 STDMETHOD(GetSize)(UInt64 *size); 91 #ifdef USE_WIN_FILE 92 STDMETHOD(GetProps)(UInt64 *size, FILETIME *cTime, FILETIME *aTime, FILETIME *mTime, UInt32 *attrib); 93 STDMETHOD(GetProps2)(CStreamFileProps *props); 94 #endif 95 }; 96 97 class CStdInFileStream: 98 public ISequentialInStream, 99 public CMyUnknownImp 100 { 101 public: 102 MY_UNKNOWN_IMP 103 104 virtual ~CStdInFileStream() {} 105 STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); 106 }; 107 108 class COutFileStream: 109 public IOutStream, 110 public CMyUnknownImp 111 { 112 public: 113 #ifdef USE_WIN_FILE 114 NWindows::NFile::NIO::COutFile File; 115 #else 116 NC::NFile::NIO::COutFile File; 117 #endif 118 virtual ~COutFileStream() {} 119 bool Create(CFSTR fileName, bool createAlways) 120 { 121 ProcessedSize = 0; 122 return File.Create(fileName, createAlways); 123 } 124 bool Open(CFSTR fileName, DWORD creationDisposition) 125 { 126 ProcessedSize = 0; 127 return File.Open(fileName, creationDisposition); 128 } 129 130 HRESULT Close(); 131 132 UInt64 ProcessedSize; 133 134 #ifdef USE_WIN_FILE 135 bool SetTime(const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime) 136 { 137 return File.SetTime(cTime, aTime, mTime); 138 } 139 bool SetMTime(const FILETIME *mTime) { return File.SetMTime(mTime); } 140 #endif 141 142 143 MY_UNKNOWN_IMP1(IOutStream) 144 145 STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize); 146 STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition); 147 STDMETHOD(SetSize)(UInt64 newSize); 148 149 HRESULT GetSize(UInt64 *size); 150 }; 151 152 class CStdOutFileStream: 153 public ISequentialOutStream, 154 public CMyUnknownImp 155 { 156 UInt64 _size; 157 public: 158 MY_UNKNOWN_IMP 159 160 UInt64 GetSize() const { return _size; } 161 CStdOutFileStream(): _size(0) {} 162 virtual ~CStdOutFileStream() {} 163 STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize); 164 }; 165 166 #endif 167