1370b324cSopenharmony_ci// ArchiveExtractCallback.h
2370b324cSopenharmony_ci
3370b324cSopenharmony_ci#ifndef ZIP7_INC_ARCHIVE_EXTRACT_CALLBACK_H
4370b324cSopenharmony_ci#define ZIP7_INC_ARCHIVE_EXTRACT_CALLBACK_H
5370b324cSopenharmony_ci
6370b324cSopenharmony_ci#include "../../../Common/MyCom.h"
7370b324cSopenharmony_ci#include "../../../Common/MyLinux.h"
8370b324cSopenharmony_ci#include "../../../Common/Wildcard.h"
9370b324cSopenharmony_ci
10370b324cSopenharmony_ci#include "../../IPassword.h"
11370b324cSopenharmony_ci
12370b324cSopenharmony_ci#include "../../Common/FileStreams.h"
13370b324cSopenharmony_ci#include "../../Common/ProgressUtils.h"
14370b324cSopenharmony_ci#include "../../Common/StreamObjects.h"
15370b324cSopenharmony_ci
16370b324cSopenharmony_ci#include "../../Archive/IArchive.h"
17370b324cSopenharmony_ci
18370b324cSopenharmony_ci#include "ExtractMode.h"
19370b324cSopenharmony_ci#include "IFileExtractCallback.h"
20370b324cSopenharmony_ci#include "OpenArchive.h"
21370b324cSopenharmony_ci
22370b324cSopenharmony_ci#include "HashCalc.h"
23370b324cSopenharmony_ci
24370b324cSopenharmony_ci#ifndef Z7_SFX
25370b324cSopenharmony_ci
26370b324cSopenharmony_ciZ7_CLASS_IMP_NOQIB_1(
27370b324cSopenharmony_ci  COutStreamWithHash
28370b324cSopenharmony_ci  , ISequentialOutStream
29370b324cSopenharmony_ci)
30370b324cSopenharmony_ci  CMyComPtr<ISequentialOutStream> _stream;
31370b324cSopenharmony_ci  UInt64 _size;
32370b324cSopenharmony_ci  bool _calculate;
33370b324cSopenharmony_cipublic:
34370b324cSopenharmony_ci  IHashCalc *_hash;
35370b324cSopenharmony_ci
36370b324cSopenharmony_ci  void SetStream(ISequentialOutStream *stream) { _stream = stream; }
37370b324cSopenharmony_ci  void ReleaseStream() { _stream.Release(); }
38370b324cSopenharmony_ci  void Init(bool calculate = true)
39370b324cSopenharmony_ci  {
40370b324cSopenharmony_ci    InitCRC();
41370b324cSopenharmony_ci    _size = 0;
42370b324cSopenharmony_ci    _calculate = calculate;
43370b324cSopenharmony_ci  }
44370b324cSopenharmony_ci  void EnableCalc(bool calculate) { _calculate = calculate; }
45370b324cSopenharmony_ci  void InitCRC() { _hash->InitForNewFile(); }
46370b324cSopenharmony_ci  UInt64 GetSize() const { return _size; }
47370b324cSopenharmony_ci};
48370b324cSopenharmony_ci
49370b324cSopenharmony_ci#endif
50370b324cSopenharmony_ci
51370b324cSopenharmony_cistruct CExtractNtOptions
52370b324cSopenharmony_ci{
53370b324cSopenharmony_ci  CBoolPair NtSecurity;
54370b324cSopenharmony_ci  CBoolPair SymLinks;
55370b324cSopenharmony_ci  CBoolPair SymLinks_AllowDangerous;
56370b324cSopenharmony_ci  CBoolPair HardLinks;
57370b324cSopenharmony_ci  CBoolPair AltStreams;
58370b324cSopenharmony_ci  bool ReplaceColonForAltStream;
59370b324cSopenharmony_ci  bool WriteToAltStreamIfColon;
60370b324cSopenharmony_ci
61370b324cSopenharmony_ci  bool ExtractOwner;
62370b324cSopenharmony_ci
63370b324cSopenharmony_ci  bool PreAllocateOutFile;
64370b324cSopenharmony_ci
65370b324cSopenharmony_ci  // used for hash arcs only, when we open external files
66370b324cSopenharmony_ci  bool PreserveATime;
67370b324cSopenharmony_ci  bool OpenShareForWrite;
68370b324cSopenharmony_ci
69370b324cSopenharmony_ci  CExtractNtOptions():
70370b324cSopenharmony_ci      ReplaceColonForAltStream(false),
71370b324cSopenharmony_ci      WriteToAltStreamIfColon(false),
72370b324cSopenharmony_ci      ExtractOwner(false),
73370b324cSopenharmony_ci      PreserveATime(false),
74370b324cSopenharmony_ci      OpenShareForWrite(false)
75370b324cSopenharmony_ci  {
76370b324cSopenharmony_ci    SymLinks.Val = true;
77370b324cSopenharmony_ci    SymLinks_AllowDangerous.Val = false;
78370b324cSopenharmony_ci    HardLinks.Val = true;
79370b324cSopenharmony_ci    AltStreams.Val = true;
80370b324cSopenharmony_ci
81370b324cSopenharmony_ci    PreAllocateOutFile =
82370b324cSopenharmony_ci      #ifdef _WIN32
83370b324cSopenharmony_ci        true;
84370b324cSopenharmony_ci      #else
85370b324cSopenharmony_ci        false;
86370b324cSopenharmony_ci      #endif
87370b324cSopenharmony_ci  }
88370b324cSopenharmony_ci};
89370b324cSopenharmony_ci
90370b324cSopenharmony_ci#ifndef Z7_SFX
91370b324cSopenharmony_ci
92370b324cSopenharmony_ciZ7_CLASS_IMP_COM_1(
93370b324cSopenharmony_ci  CGetProp
94370b324cSopenharmony_ci  , IGetProp
95370b324cSopenharmony_ci)
96370b324cSopenharmony_cipublic:
97370b324cSopenharmony_ci  UInt32 IndexInArc;
98370b324cSopenharmony_ci  const CArc *Arc;
99370b324cSopenharmony_ci  // UString Name; // relative path
100370b324cSopenharmony_ci};
101370b324cSopenharmony_ci
102370b324cSopenharmony_ci#endif
103370b324cSopenharmony_ci
104370b324cSopenharmony_ci#ifndef Z7_SFX
105370b324cSopenharmony_ci#ifndef UNDER_CE
106370b324cSopenharmony_ci
107370b324cSopenharmony_ci#define SUPPORT_LINKS
108370b324cSopenharmony_ci
109370b324cSopenharmony_ci#endif
110370b324cSopenharmony_ci#endif
111370b324cSopenharmony_ci
112370b324cSopenharmony_ci
113370b324cSopenharmony_ci#ifdef SUPPORT_LINKS
114370b324cSopenharmony_ci
115370b324cSopenharmony_cistruct CHardLinkNode
116370b324cSopenharmony_ci{
117370b324cSopenharmony_ci  UInt64 StreamId;
118370b324cSopenharmony_ci  UInt64 INode;
119370b324cSopenharmony_ci
120370b324cSopenharmony_ci  int Compare(const CHardLinkNode &a) const;
121370b324cSopenharmony_ci};
122370b324cSopenharmony_ci
123370b324cSopenharmony_ciclass CHardLinks
124370b324cSopenharmony_ci{
125370b324cSopenharmony_cipublic:
126370b324cSopenharmony_ci  CRecordVector<CHardLinkNode> IDs;
127370b324cSopenharmony_ci  CObjectVector<FString> Links;
128370b324cSopenharmony_ci
129370b324cSopenharmony_ci  void Clear()
130370b324cSopenharmony_ci  {
131370b324cSopenharmony_ci    IDs.Clear();
132370b324cSopenharmony_ci    Links.Clear();
133370b324cSopenharmony_ci  }
134370b324cSopenharmony_ci
135370b324cSopenharmony_ci  void PrepareLinks()
136370b324cSopenharmony_ci  {
137370b324cSopenharmony_ci    while (Links.Size() < IDs.Size())
138370b324cSopenharmony_ci      Links.AddNew();
139370b324cSopenharmony_ci  }
140370b324cSopenharmony_ci};
141370b324cSopenharmony_ci
142370b324cSopenharmony_ci#endif
143370b324cSopenharmony_ci
144370b324cSopenharmony_ci#ifdef SUPPORT_ALT_STREAMS
145370b324cSopenharmony_ci
146370b324cSopenharmony_cistruct CIndexToPathPair
147370b324cSopenharmony_ci{
148370b324cSopenharmony_ci  UInt32 Index;
149370b324cSopenharmony_ci  FString Path;
150370b324cSopenharmony_ci
151370b324cSopenharmony_ci  CIndexToPathPair(UInt32 index): Index(index) {}
152370b324cSopenharmony_ci  CIndexToPathPair(UInt32 index, const FString &path): Index(index), Path(path) {}
153370b324cSopenharmony_ci
154370b324cSopenharmony_ci  int Compare(const CIndexToPathPair &pair) const
155370b324cSopenharmony_ci  {
156370b324cSopenharmony_ci    return MyCompare(Index, pair.Index);
157370b324cSopenharmony_ci  }
158370b324cSopenharmony_ci};
159370b324cSopenharmony_ci
160370b324cSopenharmony_ci#endif
161370b324cSopenharmony_ci
162370b324cSopenharmony_ci
163370b324cSopenharmony_ci
164370b324cSopenharmony_cistruct CFiTimesCAM
165370b324cSopenharmony_ci{
166370b324cSopenharmony_ci  CFiTime CTime;
167370b324cSopenharmony_ci  CFiTime ATime;
168370b324cSopenharmony_ci  CFiTime MTime;
169370b324cSopenharmony_ci
170370b324cSopenharmony_ci  bool CTime_Defined;
171370b324cSopenharmony_ci  bool ATime_Defined;
172370b324cSopenharmony_ci  bool MTime_Defined;
173370b324cSopenharmony_ci
174370b324cSopenharmony_ci  bool IsSomeTimeDefined() const
175370b324cSopenharmony_ci  {
176370b324cSopenharmony_ci    return
177370b324cSopenharmony_ci      CTime_Defined |
178370b324cSopenharmony_ci      ATime_Defined |
179370b324cSopenharmony_ci      MTime_Defined;
180370b324cSopenharmony_ci  }
181370b324cSopenharmony_ci};
182370b324cSopenharmony_ci
183370b324cSopenharmony_cistruct CDirPathTime: public CFiTimesCAM
184370b324cSopenharmony_ci{
185370b324cSopenharmony_ci  FString Path;
186370b324cSopenharmony_ci
187370b324cSopenharmony_ci  bool SetDirTime() const;
188370b324cSopenharmony_ci};
189370b324cSopenharmony_ci
190370b324cSopenharmony_ci
191370b324cSopenharmony_ci#ifdef SUPPORT_LINKS
192370b324cSopenharmony_ci
193370b324cSopenharmony_cistruct CLinkInfo
194370b324cSopenharmony_ci{
195370b324cSopenharmony_ci  // bool isCopyLink;
196370b324cSopenharmony_ci  bool isHardLink;
197370b324cSopenharmony_ci  bool isJunction;
198370b324cSopenharmony_ci  bool isRelative;
199370b324cSopenharmony_ci  bool isWSL;
200370b324cSopenharmony_ci  UString linkPath;
201370b324cSopenharmony_ci
202370b324cSopenharmony_ci  bool IsSymLink() const { return !isHardLink; }
203370b324cSopenharmony_ci
204370b324cSopenharmony_ci  CLinkInfo():
205370b324cSopenharmony_ci    // IsCopyLink(false),
206370b324cSopenharmony_ci    isHardLink(false),
207370b324cSopenharmony_ci    isJunction(false),
208370b324cSopenharmony_ci    isRelative(false),
209370b324cSopenharmony_ci    isWSL(false)
210370b324cSopenharmony_ci    {}
211370b324cSopenharmony_ci
212370b324cSopenharmony_ci  void Clear()
213370b324cSopenharmony_ci  {
214370b324cSopenharmony_ci    // IsCopyLink = false;
215370b324cSopenharmony_ci    isHardLink = false;
216370b324cSopenharmony_ci    isJunction = false;
217370b324cSopenharmony_ci    isRelative = false;
218370b324cSopenharmony_ci    isWSL = false;
219370b324cSopenharmony_ci    linkPath.Empty();
220370b324cSopenharmony_ci  }
221370b324cSopenharmony_ci
222370b324cSopenharmony_ci  bool Parse(const Byte *data, size_t dataSize, bool isLinuxData);
223370b324cSopenharmony_ci};
224370b324cSopenharmony_ci
225370b324cSopenharmony_ci#endif // SUPPORT_LINKS
226370b324cSopenharmony_ci
227370b324cSopenharmony_ci
228370b324cSopenharmony_ci#ifndef _WIN32
229370b324cSopenharmony_ci
230370b324cSopenharmony_cistruct COwnerInfo
231370b324cSopenharmony_ci{
232370b324cSopenharmony_ci  bool Id_Defined;
233370b324cSopenharmony_ci  UInt32 Id;
234370b324cSopenharmony_ci  AString Name;
235370b324cSopenharmony_ci
236370b324cSopenharmony_ci  void Clear()
237370b324cSopenharmony_ci  {
238370b324cSopenharmony_ci    Id_Defined = false;
239370b324cSopenharmony_ci    Id = 0;
240370b324cSopenharmony_ci    Name.Empty();
241370b324cSopenharmony_ci  }
242370b324cSopenharmony_ci};
243370b324cSopenharmony_ci
244370b324cSopenharmony_ci#endif
245370b324cSopenharmony_ci
246370b324cSopenharmony_ci
247370b324cSopenharmony_ciclass CArchiveExtractCallback Z7_final:
248370b324cSopenharmony_ci  public IArchiveExtractCallback,
249370b324cSopenharmony_ci  public IArchiveExtractCallbackMessage2,
250370b324cSopenharmony_ci  public ICryptoGetTextPassword,
251370b324cSopenharmony_ci  public ICompressProgressInfo,
252370b324cSopenharmony_ci  public IArchiveUpdateCallbackFile,
253370b324cSopenharmony_ci  public IArchiveGetDiskProperty,
254370b324cSopenharmony_ci  public CMyUnknownImp
255370b324cSopenharmony_ci{
256370b324cSopenharmony_ci  Z7_COM_UNKNOWN_IMP_5(
257370b324cSopenharmony_ci      /* IArchiveExtractCallback, */
258370b324cSopenharmony_ci      IArchiveExtractCallbackMessage2,
259370b324cSopenharmony_ci      ICryptoGetTextPassword,
260370b324cSopenharmony_ci      ICompressProgressInfo,
261370b324cSopenharmony_ci      IArchiveUpdateCallbackFile,
262370b324cSopenharmony_ci      IArchiveGetDiskProperty)
263370b324cSopenharmony_ci
264370b324cSopenharmony_ci  Z7_IFACE_COM7_IMP(IProgress)
265370b324cSopenharmony_ci  Z7_IFACE_COM7_IMP(IArchiveExtractCallback)
266370b324cSopenharmony_ci  Z7_IFACE_COM7_IMP(IArchiveExtractCallbackMessage2)
267370b324cSopenharmony_ci  Z7_IFACE_COM7_IMP(ICryptoGetTextPassword)
268370b324cSopenharmony_ci  Z7_IFACE_COM7_IMP(ICompressProgressInfo)
269370b324cSopenharmony_ci  Z7_IFACE_COM7_IMP(IArchiveUpdateCallbackFile)
270370b324cSopenharmony_ci  Z7_IFACE_COM7_IMP(IArchiveGetDiskProperty)
271370b324cSopenharmony_ci
272370b324cSopenharmony_ci  const CArc *_arc;
273370b324cSopenharmony_ci  CExtractNtOptions _ntOptions;
274370b324cSopenharmony_ci
275370b324cSopenharmony_ci  bool _isSplit;
276370b324cSopenharmony_ci
277370b324cSopenharmony_ci  bool _extractMode;
278370b324cSopenharmony_ci
279370b324cSopenharmony_ci  bool Write_CTime;
280370b324cSopenharmony_ci  bool Write_ATime;
281370b324cSopenharmony_ci  bool Write_MTime;
282370b324cSopenharmony_ci  bool _keepAndReplaceEmptyDirPrefixes; // replace them to "_";
283370b324cSopenharmony_ci
284370b324cSopenharmony_ci  bool _encrypted;
285370b324cSopenharmony_ci
286370b324cSopenharmony_ci  // bool _is_SymLink_in_Data;
287370b324cSopenharmony_ci  bool _is_SymLink_in_Data_Linux; // false = WIN32, true = LINUX
288370b324cSopenharmony_ci
289370b324cSopenharmony_ci  bool _needSetAttrib;
290370b324cSopenharmony_ci  bool _isSymLinkCreated;
291370b324cSopenharmony_ci  bool _itemFailure;
292370b324cSopenharmony_ci
293370b324cSopenharmony_ci  bool _curSize_Defined;
294370b324cSopenharmony_ci  bool _fileLength_WasSet;
295370b324cSopenharmony_ci
296370b324cSopenharmony_ci  bool _removePartsForAltStreams;
297370b324cSopenharmony_ci
298370b324cSopenharmony_ci  bool _stdOutMode;
299370b324cSopenharmony_ci  bool _testMode;
300370b324cSopenharmony_ci  bool _multiArchives;
301370b324cSopenharmony_ci
302370b324cSopenharmony_ci  NExtract::NPathMode::EEnum _pathMode;
303370b324cSopenharmony_ci  NExtract::NOverwriteMode::EEnum _overwriteMode;
304370b324cSopenharmony_ci
305370b324cSopenharmony_ci  const NWildcard::CCensorNode *_wildcardCensor; // we need wildcard for single pass mode (stdin)
306370b324cSopenharmony_ci  CMyComPtr<IFolderArchiveExtractCallback> _extractCallback2;
307370b324cSopenharmony_ci  // CMyComPtr<ICompressProgressInfo> _compressProgress;
308370b324cSopenharmony_ci  // CMyComPtr<IArchiveExtractCallbackMessage2> _callbackMessage;
309370b324cSopenharmony_ci  CMyComPtr<IFolderArchiveExtractCallback2> _folderArchiveExtractCallback2;
310370b324cSopenharmony_ci  CMyComPtr<ICryptoGetTextPassword> _cryptoGetTextPassword;
311370b324cSopenharmony_ci
312370b324cSopenharmony_ci  FString _dirPathPrefix;
313370b324cSopenharmony_ci  FString _dirPathPrefix_Full;
314370b324cSopenharmony_ci
315370b324cSopenharmony_ci  #ifndef Z7_SFX
316370b324cSopenharmony_ci
317370b324cSopenharmony_ci  CMyComPtr<IFolderExtractToStreamCallback> ExtractToStreamCallback;
318370b324cSopenharmony_ci  CGetProp *GetProp_Spec;
319370b324cSopenharmony_ci  CMyComPtr<IGetProp> GetProp;
320370b324cSopenharmony_ci
321370b324cSopenharmony_ci  #endif
322370b324cSopenharmony_ci
323370b324cSopenharmony_ci  CReadArcItem _item;
324370b324cSopenharmony_ci  FString _diskFilePath;
325370b324cSopenharmony_ci  UInt64 _position;
326370b324cSopenharmony_ci
327370b324cSopenharmony_ci  struct CProcessedFileInfo
328370b324cSopenharmony_ci  {
329370b324cSopenharmony_ci    CArcTime CTime;
330370b324cSopenharmony_ci    CArcTime ATime;
331370b324cSopenharmony_ci    CArcTime MTime;
332370b324cSopenharmony_ci    UInt32 Attrib;
333370b324cSopenharmony_ci    bool Attrib_Defined;
334370b324cSopenharmony_ci
335370b324cSopenharmony_ci   #ifndef _WIN32
336370b324cSopenharmony_ci    COwnerInfo Owner;
337370b324cSopenharmony_ci    COwnerInfo Group;
338370b324cSopenharmony_ci   #endif
339370b324cSopenharmony_ci
340370b324cSopenharmony_ci    bool IsReparse() const
341370b324cSopenharmony_ci    {
342370b324cSopenharmony_ci      return (Attrib_Defined && (Attrib & FILE_ATTRIBUTE_REPARSE_POINT) != 0);
343370b324cSopenharmony_ci    }
344370b324cSopenharmony_ci
345370b324cSopenharmony_ci    bool IsLinuxSymLink() const
346370b324cSopenharmony_ci    {
347370b324cSopenharmony_ci      return (Attrib_Defined && MY_LIN_S_ISLNK(Attrib >> 16));
348370b324cSopenharmony_ci    }
349370b324cSopenharmony_ci
350370b324cSopenharmony_ci    void SetFromPosixAttrib(UInt32 a)
351370b324cSopenharmony_ci    {
352370b324cSopenharmony_ci      // here we set only part of combined attribute required by SetFileAttrib() call
353370b324cSopenharmony_ci      #ifdef _WIN32
354370b324cSopenharmony_ci      // Windows sets FILE_ATTRIBUTE_NORMAL, if we try to set 0 as attribute.
355370b324cSopenharmony_ci      Attrib = MY_LIN_S_ISDIR(a) ?
356370b324cSopenharmony_ci          FILE_ATTRIBUTE_DIRECTORY :
357370b324cSopenharmony_ci          FILE_ATTRIBUTE_ARCHIVE;
358370b324cSopenharmony_ci      if ((a & 0222) == 0) // (& S_IWUSR) in p7zip
359370b324cSopenharmony_ci        Attrib |= FILE_ATTRIBUTE_READONLY;
360370b324cSopenharmony_ci      // 22.00 : we need type bits for (MY_LIN_S_IFLNK) for IsLinuxSymLink()
361370b324cSopenharmony_ci      a &= MY_LIN_S_IFMT;
362370b324cSopenharmony_ci      if (a == MY_LIN_S_IFLNK)
363370b324cSopenharmony_ci        Attrib |= (a << 16);
364370b324cSopenharmony_ci      #else
365370b324cSopenharmony_ci      Attrib = (a << 16) | FILE_ATTRIBUTE_UNIX_EXTENSION;
366370b324cSopenharmony_ci      #endif
367370b324cSopenharmony_ci      Attrib_Defined = true;
368370b324cSopenharmony_ci    }
369370b324cSopenharmony_ci  } _fi;
370370b324cSopenharmony_ci
371370b324cSopenharmony_ci  UInt32 _index;
372370b324cSopenharmony_ci  UInt64 _curSize;
373370b324cSopenharmony_ci  UInt64 _fileLength_that_WasSet;
374370b324cSopenharmony_ci
375370b324cSopenharmony_ci  COutFileStream *_outFileStreamSpec;
376370b324cSopenharmony_ci  CMyComPtr<ISequentialOutStream> _outFileStream;
377370b324cSopenharmony_ci
378370b324cSopenharmony_ci  CByteBuffer _outMemBuf;
379370b324cSopenharmony_ci  CBufPtrSeqOutStream *_bufPtrSeqOutStream_Spec;
380370b324cSopenharmony_ci  CMyComPtr<ISequentialOutStream> _bufPtrSeqOutStream;
381370b324cSopenharmony_ci
382370b324cSopenharmony_ci
383370b324cSopenharmony_ci #ifndef Z7_SFX
384370b324cSopenharmony_ci
385370b324cSopenharmony_ci  COutStreamWithHash *_hashStreamSpec;
386370b324cSopenharmony_ci  CMyComPtr<ISequentialOutStream> _hashStream;
387370b324cSopenharmony_ci  bool _hashStreamWasUsed;
388370b324cSopenharmony_ci
389370b324cSopenharmony_ci  bool _use_baseParentFolder_mode;
390370b324cSopenharmony_ci  UInt32 _baseParentFolder;
391370b324cSopenharmony_ci #endif
392370b324cSopenharmony_ci
393370b324cSopenharmony_ci  UStringVector _removePathParts;
394370b324cSopenharmony_ci
395370b324cSopenharmony_ci  CMyComPtr<ICompressProgressInfo> _localProgress;
396370b324cSopenharmony_ci  UInt64 _packTotal;
397370b324cSopenharmony_ci
398370b324cSopenharmony_ci  UInt64 _progressTotal;
399370b324cSopenharmony_ci  bool _progressTotal_Defined;
400370b324cSopenharmony_ci
401370b324cSopenharmony_ci  CObjectVector<CDirPathTime> _extractedFolders;
402370b324cSopenharmony_ci
403370b324cSopenharmony_ci  #ifndef _WIN32
404370b324cSopenharmony_ci  // CObjectVector<NWindows::NFile::NDir::CDelayedSymLink> _delayedSymLinks;
405370b324cSopenharmony_ci  #endif
406370b324cSopenharmony_ci
407370b324cSopenharmony_ci  #if defined(_WIN32) && !defined(UNDER_CE) && !defined(Z7_SFX)
408370b324cSopenharmony_ci  bool _saclEnabled;
409370b324cSopenharmony_ci  #endif
410370b324cSopenharmony_ci
411370b324cSopenharmony_ci  void CreateComplexDirectory(const UStringVector &dirPathParts, FString &fullPath);
412370b324cSopenharmony_ci  HRESULT GetTime(UInt32 index, PROPID propID, CArcTime &ft);
413370b324cSopenharmony_ci  HRESULT GetUnpackSize();
414370b324cSopenharmony_ci
415370b324cSopenharmony_ci  FString Hash_GetFullFilePath();
416370b324cSopenharmony_ci
417370b324cSopenharmony_ci  void SetAttrib();
418370b324cSopenharmony_ci
419370b324cSopenharmony_cipublic:
420370b324cSopenharmony_ci  HRESULT SendMessageError(const char *message, const FString &path);
421370b324cSopenharmony_ci  HRESULT SendMessageError_with_LastError(const char *message, const FString &path);
422370b324cSopenharmony_ci  HRESULT SendMessageError2(HRESULT errorCode, const char *message, const FString &path1, const FString &path2);
423370b324cSopenharmony_ci
424370b324cSopenharmony_cipublic:
425370b324cSopenharmony_ci  #if defined(_WIN32) && !defined(UNDER_CE)
426370b324cSopenharmony_ci  NExtract::NZoneIdMode::EEnum ZoneMode;
427370b324cSopenharmony_ci  CByteBuffer ZoneBuf;
428370b324cSopenharmony_ci  #endif
429370b324cSopenharmony_ci
430370b324cSopenharmony_ci  CLocalProgress *LocalProgressSpec;
431370b324cSopenharmony_ci
432370b324cSopenharmony_ci  UInt64 NumFolders;
433370b324cSopenharmony_ci  UInt64 NumFiles;
434370b324cSopenharmony_ci  UInt64 NumAltStreams;
435370b324cSopenharmony_ci  UInt64 UnpackSize;
436370b324cSopenharmony_ci  UInt64 AltStreams_UnpackSize;
437370b324cSopenharmony_ci
438370b324cSopenharmony_ci  FString DirPathPrefix_for_HashFiles;
439370b324cSopenharmony_ci
440370b324cSopenharmony_ci  CArchiveExtractCallback();
441370b324cSopenharmony_ci
442370b324cSopenharmony_ci  void InitForMulti(bool multiArchives,
443370b324cSopenharmony_ci      NExtract::NPathMode::EEnum pathMode,
444370b324cSopenharmony_ci      NExtract::NOverwriteMode::EEnum overwriteMode,
445370b324cSopenharmony_ci      NExtract::NZoneIdMode::EEnum zoneMode,
446370b324cSopenharmony_ci      bool keepAndReplaceEmptyDirPrefixes)
447370b324cSopenharmony_ci  {
448370b324cSopenharmony_ci    _multiArchives = multiArchives;
449370b324cSopenharmony_ci    _pathMode = pathMode;
450370b324cSopenharmony_ci    _overwriteMode = overwriteMode;
451370b324cSopenharmony_ci   #if defined(_WIN32) && !defined(UNDER_CE)
452370b324cSopenharmony_ci     ZoneMode = zoneMode;
453370b324cSopenharmony_ci   #else
454370b324cSopenharmony_ci     UNUSED_VAR(zoneMode)
455370b324cSopenharmony_ci   #endif
456370b324cSopenharmony_ci    _keepAndReplaceEmptyDirPrefixes = keepAndReplaceEmptyDirPrefixes;
457370b324cSopenharmony_ci    NumFolders = NumFiles = NumAltStreams = UnpackSize = AltStreams_UnpackSize = 0;
458370b324cSopenharmony_ci  }
459370b324cSopenharmony_ci
460370b324cSopenharmony_ci  #ifndef Z7_SFX
461370b324cSopenharmony_ci
462370b324cSopenharmony_ci  void SetHashMethods(IHashCalc *hash)
463370b324cSopenharmony_ci  {
464370b324cSopenharmony_ci    if (!hash)
465370b324cSopenharmony_ci      return;
466370b324cSopenharmony_ci    _hashStreamSpec = new COutStreamWithHash;
467370b324cSopenharmony_ci    _hashStream = _hashStreamSpec;
468370b324cSopenharmony_ci    _hashStreamSpec->_hash = hash;
469370b324cSopenharmony_ci  }
470370b324cSopenharmony_ci
471370b324cSopenharmony_ci  #endif
472370b324cSopenharmony_ci
473370b324cSopenharmony_ci  void InitBeforeNewArchive();
474370b324cSopenharmony_ci
475370b324cSopenharmony_ci  void Init(
476370b324cSopenharmony_ci      const CExtractNtOptions &ntOptions,
477370b324cSopenharmony_ci      const NWildcard::CCensorNode *wildcardCensor,
478370b324cSopenharmony_ci      const CArc *arc,
479370b324cSopenharmony_ci      IFolderArchiveExtractCallback *extractCallback2,
480370b324cSopenharmony_ci      bool stdOutMode, bool testMode,
481370b324cSopenharmony_ci      const FString &directoryPath,
482370b324cSopenharmony_ci      const UStringVector &removePathParts, bool removePartsForAltStreams,
483370b324cSopenharmony_ci      UInt64 packSize);
484370b324cSopenharmony_ci
485370b324cSopenharmony_ci
486370b324cSopenharmony_ci  #ifdef SUPPORT_LINKS
487370b324cSopenharmony_ci
488370b324cSopenharmony_ciprivate:
489370b324cSopenharmony_ci  CHardLinks _hardLinks;
490370b324cSopenharmony_ci  CLinkInfo _link;
491370b324cSopenharmony_ci
492370b324cSopenharmony_ci  // FString _copyFile_Path;
493370b324cSopenharmony_ci  // HRESULT MyCopyFile(ISequentialOutStream *outStream);
494370b324cSopenharmony_ci  HRESULT Link(const FString &fullProcessedPath);
495370b324cSopenharmony_ci  HRESULT ReadLink();
496370b324cSopenharmony_ci
497370b324cSopenharmony_cipublic:
498370b324cSopenharmony_ci  // call PrepareHardLinks() after Init()
499370b324cSopenharmony_ci  HRESULT PrepareHardLinks(const CRecordVector<UInt32> *realIndices);  // NULL means all items
500370b324cSopenharmony_ci
501370b324cSopenharmony_ci  #endif
502370b324cSopenharmony_ci
503370b324cSopenharmony_ci
504370b324cSopenharmony_ci  #ifdef SUPPORT_ALT_STREAMS
505370b324cSopenharmony_ci  CObjectVector<CIndexToPathPair> _renamedFiles;
506370b324cSopenharmony_ci  #endif
507370b324cSopenharmony_ci
508370b324cSopenharmony_ci  // call it after Init()
509370b324cSopenharmony_ci
510370b324cSopenharmony_ci  #ifndef Z7_SFX
511370b324cSopenharmony_ci  void SetBaseParentFolderIndex(UInt32 indexInArc)
512370b324cSopenharmony_ci  {
513370b324cSopenharmony_ci    _baseParentFolder = indexInArc;
514370b324cSopenharmony_ci    _use_baseParentFolder_mode = true;
515370b324cSopenharmony_ci  }
516370b324cSopenharmony_ci  #endif
517370b324cSopenharmony_ci
518370b324cSopenharmony_ci  HRESULT CloseArc();
519370b324cSopenharmony_ci
520370b324cSopenharmony_ciprivate:
521370b324cSopenharmony_ci  void ClearExtractedDirsInfo()
522370b324cSopenharmony_ci  {
523370b324cSopenharmony_ci    _extractedFolders.Clear();
524370b324cSopenharmony_ci    #ifndef _WIN32
525370b324cSopenharmony_ci    // _delayedSymLinks.Clear();
526370b324cSopenharmony_ci    #endif
527370b324cSopenharmony_ci  }
528370b324cSopenharmony_ci
529370b324cSopenharmony_ci  HRESULT Read_fi_Props();
530370b324cSopenharmony_ci  void CorrectPathParts();
531370b324cSopenharmony_ci  void GetFiTimesCAM(CFiTimesCAM &pt);
532370b324cSopenharmony_ci  void CreateFolders();
533370b324cSopenharmony_ci
534370b324cSopenharmony_ci  bool _isRenamed;
535370b324cSopenharmony_ci  HRESULT CheckExistFile(FString &fullProcessedPath, bool &needExit);
536370b324cSopenharmony_ci  HRESULT GetExtractStream(CMyComPtr<ISequentialOutStream> &outStreamLoc, bool &needExit);
537370b324cSopenharmony_ci  HRESULT GetItem(UInt32 index);
538370b324cSopenharmony_ci
539370b324cSopenharmony_ci  HRESULT CloseFile();
540370b324cSopenharmony_ci  HRESULT CloseReparseAndFile();
541370b324cSopenharmony_ci  HRESULT CloseReparseAndFile2();
542370b324cSopenharmony_ci  HRESULT SetDirsTimes();
543370b324cSopenharmony_ci
544370b324cSopenharmony_ci  const void *NtReparse_Data;
545370b324cSopenharmony_ci  UInt32 NtReparse_Size;
546370b324cSopenharmony_ci
547370b324cSopenharmony_ci  #ifdef SUPPORT_LINKS
548370b324cSopenharmony_ci  HRESULT SetFromLinkPath(
549370b324cSopenharmony_ci      const FString &fullProcessedPath,
550370b324cSopenharmony_ci      const CLinkInfo &linkInfo,
551370b324cSopenharmony_ci      bool &linkWasSet);
552370b324cSopenharmony_ci  #endif
553370b324cSopenharmony_ci};
554370b324cSopenharmony_ci
555370b324cSopenharmony_ci
556370b324cSopenharmony_cistruct CArchiveExtractCallback_Closer
557370b324cSopenharmony_ci{
558370b324cSopenharmony_ci  CArchiveExtractCallback *_ref;
559370b324cSopenharmony_ci
560370b324cSopenharmony_ci  CArchiveExtractCallback_Closer(CArchiveExtractCallback *ref): _ref(ref) {}
561370b324cSopenharmony_ci
562370b324cSopenharmony_ci  HRESULT Close()
563370b324cSopenharmony_ci  {
564370b324cSopenharmony_ci    HRESULT res = S_OK;
565370b324cSopenharmony_ci    if (_ref)
566370b324cSopenharmony_ci    {
567370b324cSopenharmony_ci      res = _ref->CloseArc();
568370b324cSopenharmony_ci      _ref = NULL;
569370b324cSopenharmony_ci    }
570370b324cSopenharmony_ci    return res;
571370b324cSopenharmony_ci  }
572370b324cSopenharmony_ci
573370b324cSopenharmony_ci  ~CArchiveExtractCallback_Closer()
574370b324cSopenharmony_ci  {
575370b324cSopenharmony_ci    Close();
576370b324cSopenharmony_ci  }
577370b324cSopenharmony_ci};
578370b324cSopenharmony_ci
579370b324cSopenharmony_ci
580370b324cSopenharmony_cibool CensorNode_CheckPath(const NWildcard::CCensorNode &node, const CReadArcItem &item);
581370b324cSopenharmony_ci
582370b324cSopenharmony_civoid ReadZoneFile_Of_BaseFile(CFSTR fileName2, CByteBuffer &buf);
583370b324cSopenharmony_ci
584370b324cSopenharmony_ci#endif
585