xref: /third_party/lzma/CPP/7zip/Common/FileStreams.h (revision 370b324c)
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
20class CInFileStream;
21
22Z7_PURE_INTERFACES_BEGIN
23DECLARE_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};
28Z7_PURE_INTERFACES_END
29
30
31/*
32Z7_CLASS_IMP_COM_5(
33  CInFileStream
34  , IInStream
35  , IStreamGetSize
36  , IStreamGetProps
37  , IStreamGetProps2
38  , IStreamGetProp
39)
40*/
41Z7_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_5(
50      IInStream,
51      IStreamGetSize,
52      IStreamGetProps,
53      IStreamGetProps2,
54      IStreamGetProp)
55
56  Z7_IFACE_COM7_IMP(ISequentialInStream)
57  Z7_IFACE_COM7_IMP(IInStream)
58public:
59  Z7_IFACE_COM7_IMP(IStreamGetSize)
60private:
61  Z7_IFACE_COM7_IMP(IStreamGetProps)
62public:
63  Z7_IFACE_COM7_IMP(IStreamGetProps2)
64  Z7_IFACE_COM7_IMP(IStreamGetProp)
65
66private:
67  NWindows::NFile::NIO::CInFile File;
68public:
69
70  #ifdef Z7_FILE_STREAMS_USE_WIN_FILE
71
72  #ifdef Z7_DEVICE_FILE
73  UInt64 VirtPos;
74  UInt64 PhyPos;
75  UInt64 BufStartPos;
76  Byte *Buf;
77  UInt32 BufSize;
78  #endif
79
80  #endif
81
82 #ifdef _WIN32
83  BY_HANDLE_FILE_INFORMATION _info;
84 #else
85  struct stat _info;
86  UInt32 _uid;
87  UInt32 _gid;
88  UString OwnerName;
89  UString OwnerGroup;
90  bool StoreOwnerId;
91  bool StoreOwnerName;
92 #endif
93
94  bool _info_WasLoaded;
95  bool SupportHardLinks;
96  IInFileStream_Callback *Callback;
97  UINT_PTR CallbackRef;
98
99  CInFileStream();
100  ~CInFileStream();
101
102  void Set_PreserveATime(bool v)
103  {
104    File.PreserveATime = v;
105  }
106
107  bool GetLength(UInt64 &length) const throw()
108  {
109    return File.GetLength(length);
110  }
111
112  bool Open(CFSTR fileName)
113  {
114    _info_WasLoaded = false;
115    return File.Open(fileName);
116  }
117
118  bool OpenShared(CFSTR fileName, bool shareForWrite)
119  {
120    _info_WasLoaded = false;
121    return File.OpenShared(fileName, shareForWrite);
122  }
123};
124
125
126Z7_CLASS_IMP_NOQIB_1(
127  CStdInFileStream
128  , ISequentialInStream
129)
130};
131
132
133Z7_CLASS_IMP_COM_1(
134  COutFileStream
135  , IOutStream
136)
137  Z7_IFACE_COM7_IMP(ISequentialOutStream)
138public:
139
140  NWindows::NFile::NIO::COutFile File;
141
142  bool Create(CFSTR fileName, bool createAlways)
143  {
144    ProcessedSize = 0;
145    return File.Create(fileName, createAlways);
146  }
147  bool Open(CFSTR fileName, DWORD creationDisposition)
148  {
149    ProcessedSize = 0;
150    return File.Open(fileName, creationDisposition);
151  }
152
153  HRESULT Close();
154
155  UInt64 ProcessedSize;
156
157  bool SetTime(const CFiTime *cTime, const CFiTime *aTime, const CFiTime *mTime)
158  {
159    return File.SetTime(cTime, aTime, mTime);
160  }
161  bool SetMTime(const CFiTime *mTime) {  return File.SetMTime(mTime); }
162
163  bool SeekToBegin_bool()
164  {
165    #ifdef Z7_FILE_STREAMS_USE_WIN_FILE
166    return File.SeekToBegin();
167    #else
168    return File.seekToBegin() == 0;
169    #endif
170  }
171
172  HRESULT GetSize(UInt64 *size);
173};
174
175
176Z7_CLASS_IMP_NOQIB_1(
177  CStdOutFileStream
178  , ISequentialOutStream
179)
180  UInt64 _size;
181public:
182  UInt64 GetSize() const { return _size; }
183  CStdOutFileStream(): _size(0) {}
184};
185
186#endif
187