summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/lzma/CPP/7zip/Common/FileStreams.h
blob: 7e1b086b1391a993d7623c7a994f29a56d7ee64a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
// FileStreams.h

#ifndef ZIP7_INC_FILE_STREAMS_H
#define ZIP7_INC_FILE_STREAMS_H

#ifdef _WIN32
#define Z7_FILE_STREAMS_USE_WIN_FILE
#endif

#include "../../Common/MyCom.h"
#include "../../Common/MyString.h"

#include "../../Windows/FileIO.h"

#include "../IStream.h"

#include "UniqBlocks.h"


class CInFileStream;

Z7_PURE_INTERFACES_BEGIN
DECLARE_INTERFACE(IInFileStream_Callback)
{
  virtual HRESULT InFileStream_On_Error(UINT_PTR val, DWORD error) = 0;
  virtual void InFileStream_On_Destroy(CInFileStream *stream, UINT_PTR val) = 0;
};
Z7_PURE_INTERFACES_END


/*
Z7_CLASS_IMP_COM_5(
  CInFileStream
  , IInStream
  , IStreamGetSize
  , IStreamGetProps
  , IStreamGetProps2
  , IStreamGetProp
)
*/
Z7_class_final(CInFileStream) :
  public IInStream,
  public IStreamGetSize,
  public IStreamGetProps,
  public IStreamGetProps2,
  public IStreamGetProp,
  public CMyUnknownImp
{
  Z7_COM_UNKNOWN_IMP_5(
      IInStream,
      IStreamGetSize,
      IStreamGetProps,
      IStreamGetProps2,
      IStreamGetProp)

  Z7_IFACE_COM7_IMP(ISequentialInStream)
  Z7_IFACE_COM7_IMP(IInStream)
public:
  Z7_IFACE_COM7_IMP(IStreamGetSize)
private:
  Z7_IFACE_COM7_IMP(IStreamGetProps)
public:
  Z7_IFACE_COM7_IMP(IStreamGetProps2)
  Z7_IFACE_COM7_IMP(IStreamGetProp)

private:
  NWindows::NFile::NIO::CInFile File;
public:

  #ifdef Z7_FILE_STREAMS_USE_WIN_FILE
  
  #ifdef Z7_DEVICE_FILE
  UInt64 VirtPos;
  UInt64 PhyPos;
  UInt64 BufStartPos;
  Byte *Buf;
  UInt32 BufSize;
  #endif

  #endif

 #ifdef _WIN32
  BY_HANDLE_FILE_INFORMATION _info;
 #else
  struct stat _info;
  UInt32 _uid;
  UInt32 _gid;
  UString OwnerName;
  UString OwnerGroup;
  bool StoreOwnerId;
  bool StoreOwnerName;
 #endif

  bool _info_WasLoaded;
  bool SupportHardLinks;
  IInFileStream_Callback *Callback;
  UINT_PTR CallbackRef;

  CInFileStream();
  ~CInFileStream();
    
  void Set_PreserveATime(bool v)
  {
    File.PreserveATime = v;
  }

  bool GetLength(UInt64 &length) const throw()
  {
    return File.GetLength(length);
  }
  
  bool Open(CFSTR fileName)
  {
    _info_WasLoaded = false;
    return File.Open(fileName);
  }
  
  bool OpenShared(CFSTR fileName, bool shareForWrite)
  {
    _info_WasLoaded = false;
    return File.OpenShared(fileName, shareForWrite);
  }
};


Z7_CLASS_IMP_NOQIB_1(
  CStdInFileStream
  , ISequentialInStream
)
};


Z7_CLASS_IMP_COM_1(
  COutFileStream
  , IOutStream
)
  Z7_IFACE_COM7_IMP(ISequentialOutStream)
public:

  NWindows::NFile::NIO::COutFile File;

  bool Create(CFSTR fileName, bool createAlways)
  {
    ProcessedSize = 0;
    return File.Create(fileName, createAlways);
  }
  bool Open(CFSTR fileName, DWORD creationDisposition)
  {
    ProcessedSize = 0;
    return File.Open(fileName, creationDisposition);
  }

  HRESULT Close();
  
  UInt64 ProcessedSize;

  bool SetTime(const CFiTime *cTime, const CFiTime *aTime, const CFiTime *mTime)
  {
    return File.SetTime(cTime, aTime, mTime);
  }
  bool SetMTime(const CFiTime *mTime) {  return File.SetMTime(mTime); }

  bool SeekToBegin_bool()
  {
    #ifdef Z7_FILE_STREAMS_USE_WIN_FILE
    return File.SeekToBegin();
    #else
    return File.seekToBegin() == 0;
    #endif
  }

  HRESULT GetSize(UInt64 *size);
};


Z7_CLASS_IMP_NOQIB_1(
  CStdOutFileStream
  , ISequentialOutStream
)
  UInt64 _size;
public:
  UInt64 GetSize() const { return _size; }
  CStdOutFileStream(): _size(0) {}
};

#endif