• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/MyCom.h"
11 #include "../../Common/MyString.h"
12 
13 #include "../../Windows/FileIO.h"
14 
15 #include "../IStream.h"
16 
17 #include "UniqBlocks.h"
18 
19 
20 class CInFileStream;
21 struct IInFileStream_Callback
22 {
23   virtual HRESULT InFileStream_On_Error(UINT_PTR val, DWORD error) = 0;
24   virtual void InFileStream_On_Destroy(CInFileStream *stream, UINT_PTR val) = 0;
25 };
26 
27 class CInFileStream:
28   public IInStream,
29   public IStreamGetSize,
30   public IStreamGetProps,
31   public IStreamGetProps2,
32   public IStreamGetProp,
33   public CMyUnknownImp
34 {
35   NWindows::NFile::NIO::CInFile File;
36 public:
37 
38   #ifdef USE_WIN_FILE
39 
40   #ifdef SUPPORT_DEVICE_FILE
41   UInt64 VirtPos;
42   UInt64 PhyPos;
43   UInt64 BufStartPos;
44   Byte *Buf;
45   UInt32 BufSize;
46   #endif
47 
48   #endif
49 
50  #ifdef _WIN32
51   BY_HANDLE_FILE_INFORMATION _info;
52  #else
53   struct stat _info;
54   UInt32 _uid;
55   UInt32 _gid;
56   UString OwnerName;
57   UString OwnerGroup;
58   bool StoreOwnerId;
59   bool StoreOwnerName;
60  #endif
61 
62   bool _info_WasLoaded;
63   bool SupportHardLinks;
64   IInFileStream_Callback *Callback;
65   UINT_PTR CallbackRef;
66 
67   virtual ~CInFileStream();
68 
69   CInFileStream();
70 
Set_PreserveATime(bool v)71   void Set_PreserveATime(bool v)
72   {
73     File.PreserveATime = v;
74   }
75 
GetLength(UInt64 & length)76   bool GetLength(UInt64 &length) const throw()
77   {
78     return File.GetLength(length);
79   }
80 
Open(CFSTR fileName)81   bool Open(CFSTR fileName)
82   {
83     _info_WasLoaded = false;
84     return File.Open(fileName);
85   }
86 
OpenShared(CFSTR fileName,bool shareForWrite)87   bool OpenShared(CFSTR fileName, bool shareForWrite)
88   {
89     _info_WasLoaded = false;
90     return File.OpenShared(fileName, shareForWrite);
91   }
92 
93   MY_QUERYINTERFACE_BEGIN2(IInStream)
94   MY_QUERYINTERFACE_ENTRY(IStreamGetSize)
95   MY_QUERYINTERFACE_ENTRY(IStreamGetProps)
96   MY_QUERYINTERFACE_ENTRY(IStreamGetProps2)
97   MY_QUERYINTERFACE_ENTRY(IStreamGetProp)
98   MY_QUERYINTERFACE_END
99   MY_ADDREF_RELEASE
100 
101   STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
102   STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
103 
104   STDMETHOD(GetSize)(UInt64 *size);
105   STDMETHOD(GetProps)(UInt64 *size, FILETIME *cTime, FILETIME *aTime, FILETIME *mTime, UInt32 *attrib);
106   STDMETHOD(GetProps2)(CStreamFileProps *props);
107   STDMETHOD(GetProperty)(PROPID propID, PROPVARIANT *value);
108   STDMETHOD(ReloadProps)();
109 };
110 
111 class CStdInFileStream:
112   public ISequentialInStream,
113   public CMyUnknownImp
114 {
115 public:
116   MY_UNKNOWN_IMP
117 
~CStdInFileStream()118   virtual ~CStdInFileStream() {}
119   STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
120 };
121 
122 class COutFileStream:
123   public IOutStream,
124   public CMyUnknownImp
125 {
126 public:
127   NWindows::NFile::NIO::COutFile File;
128 
~COutFileStream()129   virtual ~COutFileStream() {}
Create(CFSTR fileName,bool createAlways)130   bool Create(CFSTR fileName, bool createAlways)
131   {
132     ProcessedSize = 0;
133     return File.Create(fileName, createAlways);
134   }
Open(CFSTR fileName,DWORD creationDisposition)135   bool Open(CFSTR fileName, DWORD creationDisposition)
136   {
137     ProcessedSize = 0;
138     return File.Open(fileName, creationDisposition);
139   }
140 
141   HRESULT Close();
142 
143   UInt64 ProcessedSize;
144 
SetTime(const CFiTime * cTime,const CFiTime * aTime,const CFiTime * mTime)145   bool SetTime(const CFiTime *cTime, const CFiTime *aTime, const CFiTime *mTime)
146   {
147     return File.SetTime(cTime, aTime, mTime);
148   }
SetMTime(const CFiTime * mTime)149   bool SetMTime(const CFiTime *mTime) {  return File.SetMTime(mTime); }
150 
151   MY_UNKNOWN_IMP1(IOutStream)
152 
153   STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
154   STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
155   STDMETHOD(SetSize)(UInt64 newSize);
156 
SeekToBegin_bool()157   bool SeekToBegin_bool()
158   {
159     #ifdef USE_WIN_FILE
160     return File.SeekToBegin();
161     #else
162     return File.seekToBegin() == 0;
163     #endif
164   }
165 
166   HRESULT GetSize(UInt64 *size);
167 };
168 
169 class CStdOutFileStream:
170   public ISequentialOutStream,
171   public CMyUnknownImp
172 {
173   UInt64 _size;
174 public:
175   MY_UNKNOWN_IMP
176 
GetSize()177   UInt64 GetSize() const { return _size; }
CStdOutFileStream()178   CStdOutFileStream(): _size(0) {}
~CStdOutFileStream()179   virtual ~CStdOutFileStream() {}
180   STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
181 };
182 
183 #endif
184