xref: /aosp_15_r20/external/lzma/CPP/7zip/Common/FileStreams.h (revision f6dc9357d832569d4d1f5d24eacdb3935a1ae8e6)
1 // FileStreams.h
2 
3 #ifndef ZIP7_INC_FILE_STREAMS_H
4 #define ZIP7_INC_FILE_STREAMS_H
5 
6 #ifdef _WIN32
7 #define Z7_FILE_STREAMS_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 
22 Z7_PURE_INTERFACES_BEGIN
DECLARE_INTERFACE(IInFileStream_Callback)23 DECLARE_INTERFACE(IInFileStream_Callback)
24 {
25   virtual HRESULT InFileStream_On_Error(UINT_PTR val, DWORD error) = 0;
26   virtual void InFileStream_On_Destroy(CInFileStream *stream, UINT_PTR val) = 0;
27 };
28 Z7_PURE_INTERFACES_END
29 
30 
31 /*
32 Z7_CLASS_IMP_COM_5(
33   CInFileStream
34   , IInStream
35   , IStreamGetSize
36   , IStreamGetProps
37   , IStreamGetProps2
38   , IStreamGetProp
39 )
40 */
Z7_class_final(CInFileStream)41 Z7_class_final(CInFileStream) :
42   public IInStream,
43   public IStreamGetSize,
44   public IStreamGetProps,
45   public IStreamGetProps2,
46   public IStreamGetProp,
47   public CMyUnknownImp
48 {
49   Z7_COM_UNKNOWN_IMP_6(
50       IInStream,
51       ISequentialInStream,
52       IStreamGetSize,
53       IStreamGetProps,
54       IStreamGetProps2,
55       IStreamGetProp)
56 
57   Z7_IFACE_COM7_IMP(ISequentialInStream)
58   Z7_IFACE_COM7_IMP(IInStream)
59 public:
60   Z7_IFACE_COM7_IMP(IStreamGetSize)
61 private:
62   Z7_IFACE_COM7_IMP(IStreamGetProps)
63 public:
64   Z7_IFACE_COM7_IMP(IStreamGetProps2)
65   Z7_IFACE_COM7_IMP(IStreamGetProp)
66 
67 private:
68   NWindows::NFile::NIO::CInFile File;
69 public:
70 
71   #ifdef Z7_FILE_STREAMS_USE_WIN_FILE
72 
73   #ifdef Z7_DEVICE_FILE
74   UInt64 VirtPos;
75   UInt64 PhyPos;
76   UInt64 BufStartPos;
77   Byte *Buf;
78   UInt32 BufSize;
79   #endif
80 
81   #endif
82 
83  #ifdef _WIN32
84   BY_HANDLE_FILE_INFORMATION _info;
85  #else
86   struct stat _info;
87   UInt32 _uid;
88   UInt32 _gid;
89   UString OwnerName;
90   UString OwnerGroup;
91   bool StoreOwnerId;
92   bool StoreOwnerName;
93  #endif
94 
95   bool _info_WasLoaded;
96   bool SupportHardLinks;
97   IInFileStream_Callback *Callback;
98   UINT_PTR CallbackRef;
99 
100   CInFileStream();
101   ~CInFileStream();
102 
103   void Set_PreserveATime(bool v)
104   {
105     File.PreserveATime = v;
106   }
107 
108   bool GetLength(UInt64 &length) const throw()
109   {
110     return File.GetLength(length);
111   }
112 
113 #if 0
114   bool OpenStdIn();
115 #endif
116 
117   bool Open(CFSTR fileName)
118   {
119     _info_WasLoaded = false;
120     return File.Open(fileName);
121   }
122 
123   bool OpenShared(CFSTR fileName, bool shareForWrite)
124   {
125     _info_WasLoaded = false;
126     return File.OpenShared(fileName, shareForWrite);
127   }
128 };
129 
130 // bool CreateStdInStream(CMyComPtr<ISequentialInStream> &str);
131 
132 Z7_CLASS_IMP_NOQIB_1(
133   CStdInFileStream
134   , ISequentialInStream
135 )
136 };
137 
138 
139 Z7_CLASS_IMP_COM_1(
140   COutFileStream
141   , IOutStream
142 )
143   Z7_IFACE_COM7_IMP(ISequentialOutStream)
144 public:
145 
146   NWindows::NFile::NIO::COutFile File;
147 
148   bool Create_NEW(CFSTR fileName)
149   {
150     ProcessedSize = 0;
151     return File.Create_NEW(fileName);
152   }
153 
154   bool Create_ALWAYS(CFSTR fileName)
155   {
156     ProcessedSize = 0;
157     return File.Create_ALWAYS(fileName);
158   }
159 
160   bool Open_EXISTING(CFSTR fileName)
161   {
162     ProcessedSize = 0;
163     return File.Open_EXISTING(fileName);
164   }
165 
166   bool Create_ALWAYS_or_Open_ALWAYS(CFSTR fileName, bool createAlways)
167   {
168     ProcessedSize = 0;
169     return File.Create_ALWAYS_or_Open_ALWAYS(fileName, createAlways);
170   }
171 
172   HRESULT Close();
173 
174   UInt64 ProcessedSize;
175 
176   bool SetTime(const CFiTime *cTime, const CFiTime *aTime, const CFiTime *mTime)
177   {
178     return File.SetTime(cTime, aTime, mTime);
179   }
180   bool SetMTime(const CFiTime *mTime) {  return File.SetMTime(mTime); }
181 
182   bool SeekToBegin_bool()
183   {
184     #ifdef Z7_FILE_STREAMS_USE_WIN_FILE
185     return File.SeekToBegin();
186     #else
187     return File.seekToBegin() == 0;
188     #endif
189   }
190 
191   HRESULT GetSize(UInt64 *size);
192 };
193 
194 
195 Z7_CLASS_IMP_NOQIB_1(
196   CStdOutFileStream
197   , ISequentialOutStream
198 )
199   UInt64 _size;
200 public:
201   UInt64 GetSize() const { return _size; }
202   CStdOutFileStream(): _size(0) {}
203 };
204 
205 #endif
206