1370b324cSopenharmony_ci// OpenArchive.h
2370b324cSopenharmony_ci
3370b324cSopenharmony_ci#ifndef ZIP7_INC_OPEN_ARCHIVE_H
4370b324cSopenharmony_ci#define ZIP7_INC_OPEN_ARCHIVE_H
5370b324cSopenharmony_ci
6370b324cSopenharmony_ci#include "../../../Windows/PropVariant.h"
7370b324cSopenharmony_ci
8370b324cSopenharmony_ci#include "ArchiveOpenCallback.h"
9370b324cSopenharmony_ci#include "LoadCodecs.h"
10370b324cSopenharmony_ci#include "Property.h"
11370b324cSopenharmony_ci#include "DirItem.h"
12370b324cSopenharmony_ci
13370b324cSopenharmony_ci#ifndef Z7_SFX
14370b324cSopenharmony_ci
15370b324cSopenharmony_ci#define SUPPORT_ALT_STREAMS
16370b324cSopenharmony_ci
17370b324cSopenharmony_ci#endif
18370b324cSopenharmony_ci
19370b324cSopenharmony_ciHRESULT Archive_GetItemBoolProp(IInArchive *arc, UInt32 index, PROPID propID, bool &result) throw();
20370b324cSopenharmony_ciHRESULT Archive_IsItem_Dir(IInArchive *arc, UInt32 index, bool &result) throw();
21370b324cSopenharmony_ciHRESULT Archive_IsItem_Aux(IInArchive *arc, UInt32 index, bool &result) throw();
22370b324cSopenharmony_ciHRESULT Archive_IsItem_AltStream(IInArchive *arc, UInt32 index, bool &result) throw();
23370b324cSopenharmony_ciHRESULT Archive_IsItem_Deleted(IInArchive *arc, UInt32 index, bool &deleted) throw();
24370b324cSopenharmony_ci
25370b324cSopenharmony_ci#ifdef SUPPORT_ALT_STREAMS
26370b324cSopenharmony_ciint FindAltStreamColon_in_Path(const wchar_t *path);
27370b324cSopenharmony_ci#endif
28370b324cSopenharmony_ci
29370b324cSopenharmony_ci/*
30370b324cSopenharmony_cistruct COptionalOpenProperties
31370b324cSopenharmony_ci{
32370b324cSopenharmony_ci  UString FormatName;
33370b324cSopenharmony_ci  CObjectVector<CProperty> Props;
34370b324cSopenharmony_ci};
35370b324cSopenharmony_ci*/
36370b324cSopenharmony_ci
37370b324cSopenharmony_ci#ifdef Z7_SFX
38370b324cSopenharmony_ci#define OPEN_PROPS_DECL
39370b324cSopenharmony_ci#else
40370b324cSopenharmony_ci#define OPEN_PROPS_DECL const CObjectVector<CProperty> *props;
41370b324cSopenharmony_ci// #define OPEN_PROPS_DECL , const CObjectVector<COptionalOpenProperties> *props
42370b324cSopenharmony_ci#endif
43370b324cSopenharmony_ci
44370b324cSopenharmony_cistruct COpenSpecFlags
45370b324cSopenharmony_ci{
46370b324cSopenharmony_ci  // bool CanReturnFull;
47370b324cSopenharmony_ci  bool CanReturnFrontal;
48370b324cSopenharmony_ci  bool CanReturnTail;
49370b324cSopenharmony_ci  bool CanReturnMid;
50370b324cSopenharmony_ci
51370b324cSopenharmony_ci  bool CanReturn_NonStart() const { return CanReturnTail || CanReturnMid; }
52370b324cSopenharmony_ci
53370b324cSopenharmony_ci  COpenSpecFlags():
54370b324cSopenharmony_ci    // CanReturnFull(true),
55370b324cSopenharmony_ci    CanReturnFrontal(false),
56370b324cSopenharmony_ci    CanReturnTail(false),
57370b324cSopenharmony_ci    CanReturnMid(false)
58370b324cSopenharmony_ci    {}
59370b324cSopenharmony_ci};
60370b324cSopenharmony_ci
61370b324cSopenharmony_cistruct COpenType
62370b324cSopenharmony_ci{
63370b324cSopenharmony_ci  int FormatIndex;
64370b324cSopenharmony_ci
65370b324cSopenharmony_ci  COpenSpecFlags SpecForcedType;
66370b324cSopenharmony_ci  COpenSpecFlags SpecMainType;
67370b324cSopenharmony_ci  COpenSpecFlags SpecWrongExt;
68370b324cSopenharmony_ci  COpenSpecFlags SpecUnknownExt;
69370b324cSopenharmony_ci
70370b324cSopenharmony_ci  bool Recursive;
71370b324cSopenharmony_ci
72370b324cSopenharmony_ci  bool CanReturnArc;
73370b324cSopenharmony_ci  bool CanReturnParser;
74370b324cSopenharmony_ci  bool IsHashType;
75370b324cSopenharmony_ci  bool EachPos;
76370b324cSopenharmony_ci
77370b324cSopenharmony_ci  // bool SkipSfxStub;
78370b324cSopenharmony_ci  // bool ExeAsUnknown;
79370b324cSopenharmony_ci
80370b324cSopenharmony_ci  bool ZerosTailIsAllowed;
81370b324cSopenharmony_ci
82370b324cSopenharmony_ci  bool MaxStartOffset_Defined;
83370b324cSopenharmony_ci  UInt64 MaxStartOffset;
84370b324cSopenharmony_ci
85370b324cSopenharmony_ci  const COpenSpecFlags &GetSpec(bool isForced, bool isMain, bool isUnknown) const
86370b324cSopenharmony_ci  {
87370b324cSopenharmony_ci    return isForced ? SpecForcedType : (isMain ? SpecMainType : (isUnknown ? SpecUnknownExt : SpecWrongExt));
88370b324cSopenharmony_ci  }
89370b324cSopenharmony_ci
90370b324cSopenharmony_ci  COpenType():
91370b324cSopenharmony_ci      FormatIndex(-1),
92370b324cSopenharmony_ci      Recursive(true),
93370b324cSopenharmony_ci      CanReturnArc(true),
94370b324cSopenharmony_ci      CanReturnParser(false),
95370b324cSopenharmony_ci      IsHashType(false),
96370b324cSopenharmony_ci      EachPos(false),
97370b324cSopenharmony_ci      // SkipSfxStub(true),
98370b324cSopenharmony_ci      // ExeAsUnknown(true),
99370b324cSopenharmony_ci      ZerosTailIsAllowed(false),
100370b324cSopenharmony_ci      MaxStartOffset_Defined(false),
101370b324cSopenharmony_ci      MaxStartOffset(0)
102370b324cSopenharmony_ci  {
103370b324cSopenharmony_ci    SpecForcedType.CanReturnFrontal = true;
104370b324cSopenharmony_ci    SpecForcedType.CanReturnTail = true;
105370b324cSopenharmony_ci    SpecForcedType.CanReturnMid = true;
106370b324cSopenharmony_ci
107370b324cSopenharmony_ci    SpecMainType.CanReturnFrontal = true;
108370b324cSopenharmony_ci
109370b324cSopenharmony_ci    SpecUnknownExt.CanReturnTail = true; // for sfx
110370b324cSopenharmony_ci    SpecUnknownExt.CanReturnMid = true;
111370b324cSopenharmony_ci    SpecUnknownExt.CanReturnFrontal = true; // for alt streams of sfx with pad
112370b324cSopenharmony_ci
113370b324cSopenharmony_ci    // ZerosTailIsAllowed = true;
114370b324cSopenharmony_ci  }
115370b324cSopenharmony_ci};
116370b324cSopenharmony_ci
117370b324cSopenharmony_cistruct COpenOptions
118370b324cSopenharmony_ci{
119370b324cSopenharmony_ci  CCodecs *codecs;
120370b324cSopenharmony_ci  COpenType openType;
121370b324cSopenharmony_ci  const CObjectVector<COpenType> *types;
122370b324cSopenharmony_ci  const CIntVector *excludedFormats;
123370b324cSopenharmony_ci
124370b324cSopenharmony_ci  IInStream *stream;
125370b324cSopenharmony_ci  ISequentialInStream *seqStream;
126370b324cSopenharmony_ci  IArchiveOpenCallback *callback;
127370b324cSopenharmony_ci  COpenCallbackImp *callbackSpec; // it's used for SFX only
128370b324cSopenharmony_ci  OPEN_PROPS_DECL
129370b324cSopenharmony_ci  // bool openOnlySpecifiedByExtension,
130370b324cSopenharmony_ci
131370b324cSopenharmony_ci  bool stdInMode;
132370b324cSopenharmony_ci  UString filePath;
133370b324cSopenharmony_ci
134370b324cSopenharmony_ci  COpenOptions():
135370b324cSopenharmony_ci      codecs(NULL),
136370b324cSopenharmony_ci      types(NULL),
137370b324cSopenharmony_ci      excludedFormats(NULL),
138370b324cSopenharmony_ci      stream(NULL),
139370b324cSopenharmony_ci      seqStream(NULL),
140370b324cSopenharmony_ci      callback(NULL),
141370b324cSopenharmony_ci      callbackSpec(NULL),
142370b324cSopenharmony_ci      stdInMode(false)
143370b324cSopenharmony_ci    {}
144370b324cSopenharmony_ci
145370b324cSopenharmony_ci};
146370b324cSopenharmony_ci
147370b324cSopenharmony_ciUInt32 GetOpenArcErrorFlags(const NWindows::NCOM::CPropVariant &prop, bool *isDefinedProp = NULL);
148370b324cSopenharmony_ci
149370b324cSopenharmony_cistruct CArcErrorInfo
150370b324cSopenharmony_ci{
151370b324cSopenharmony_ci  bool ThereIsTail;
152370b324cSopenharmony_ci  bool UnexpecedEnd;
153370b324cSopenharmony_ci  bool IgnoreTail; // all are zeros
154370b324cSopenharmony_ci  // bool NonZerosTail;
155370b324cSopenharmony_ci  bool ErrorFlags_Defined;
156370b324cSopenharmony_ci  UInt32 ErrorFlags;
157370b324cSopenharmony_ci  UInt32 WarningFlags;
158370b324cSopenharmony_ci  int ErrorFormatIndex; // - 1 means no Error.
159370b324cSopenharmony_ci                        // if FormatIndex == ErrorFormatIndex, the archive is open with offset
160370b324cSopenharmony_ci  UInt64 TailSize;
161370b324cSopenharmony_ci
162370b324cSopenharmony_ci  /* if CArc is Open OK with some format:
163370b324cSopenharmony_ci        - ErrorFormatIndex shows error format index, if extension is incorrect
164370b324cSopenharmony_ci        - other variables show message and warnings of archive that is open */
165370b324cSopenharmony_ci
166370b324cSopenharmony_ci  UString ErrorMessage;
167370b324cSopenharmony_ci  UString WarningMessage;
168370b324cSopenharmony_ci
169370b324cSopenharmony_ci  // call IsArc_After_NonOpen only if Open returns S_FALSE
170370b324cSopenharmony_ci  bool IsArc_After_NonOpen() const
171370b324cSopenharmony_ci  {
172370b324cSopenharmony_ci    return (ErrorFlags_Defined && (ErrorFlags & kpv_ErrorFlags_IsNotArc) == 0);
173370b324cSopenharmony_ci  }
174370b324cSopenharmony_ci
175370b324cSopenharmony_ci
176370b324cSopenharmony_ci  CArcErrorInfo():
177370b324cSopenharmony_ci      ThereIsTail(false),
178370b324cSopenharmony_ci      UnexpecedEnd(false),
179370b324cSopenharmony_ci      IgnoreTail(false),
180370b324cSopenharmony_ci      // NonZerosTail(false),
181370b324cSopenharmony_ci      ErrorFlags_Defined(false),
182370b324cSopenharmony_ci      ErrorFlags(0),
183370b324cSopenharmony_ci      WarningFlags(0),
184370b324cSopenharmony_ci      ErrorFormatIndex(-1),
185370b324cSopenharmony_ci      TailSize(0)
186370b324cSopenharmony_ci    {}
187370b324cSopenharmony_ci
188370b324cSopenharmony_ci  void ClearErrors();
189370b324cSopenharmony_ci
190370b324cSopenharmony_ci  void ClearErrors_Full()
191370b324cSopenharmony_ci  {
192370b324cSopenharmony_ci    ErrorFormatIndex = -1;
193370b324cSopenharmony_ci    ClearErrors();
194370b324cSopenharmony_ci  }
195370b324cSopenharmony_ci
196370b324cSopenharmony_ci  bool IsThereErrorOrWarning() const
197370b324cSopenharmony_ci  {
198370b324cSopenharmony_ci    return ErrorFlags != 0
199370b324cSopenharmony_ci        || WarningFlags != 0
200370b324cSopenharmony_ci        || NeedTailWarning()
201370b324cSopenharmony_ci        || UnexpecedEnd
202370b324cSopenharmony_ci        || !ErrorMessage.IsEmpty()
203370b324cSopenharmony_ci        || !WarningMessage.IsEmpty();
204370b324cSopenharmony_ci  }
205370b324cSopenharmony_ci
206370b324cSopenharmony_ci  bool AreThereErrors() const { return ErrorFlags != 0 || UnexpecedEnd; }
207370b324cSopenharmony_ci  bool AreThereWarnings() const { return WarningFlags != 0 || NeedTailWarning(); }
208370b324cSopenharmony_ci
209370b324cSopenharmony_ci  bool NeedTailWarning() const { return !IgnoreTail && ThereIsTail; }
210370b324cSopenharmony_ci
211370b324cSopenharmony_ci  UInt32 GetWarningFlags() const
212370b324cSopenharmony_ci  {
213370b324cSopenharmony_ci    UInt32 a = WarningFlags;
214370b324cSopenharmony_ci    if (NeedTailWarning() && (ErrorFlags & kpv_ErrorFlags_DataAfterEnd) == 0)
215370b324cSopenharmony_ci      a |= kpv_ErrorFlags_DataAfterEnd;
216370b324cSopenharmony_ci    return a;
217370b324cSopenharmony_ci  }
218370b324cSopenharmony_ci
219370b324cSopenharmony_ci  UInt32 GetErrorFlags() const
220370b324cSopenharmony_ci  {
221370b324cSopenharmony_ci    UInt32 a = ErrorFlags;
222370b324cSopenharmony_ci    if (UnexpecedEnd)
223370b324cSopenharmony_ci      a |= kpv_ErrorFlags_UnexpectedEnd;
224370b324cSopenharmony_ci    return a;
225370b324cSopenharmony_ci  }
226370b324cSopenharmony_ci};
227370b324cSopenharmony_ci
228370b324cSopenharmony_cistruct CReadArcItem
229370b324cSopenharmony_ci{
230370b324cSopenharmony_ci  UString Path;            // Path from root (including alt stream name, if alt stream)
231370b324cSopenharmony_ci  UStringVector PathParts; // without altStream name, path from root or from _baseParentFolder, if _use_baseParentFolder_mode
232370b324cSopenharmony_ci
233370b324cSopenharmony_ci  #ifdef SUPPORT_ALT_STREAMS
234370b324cSopenharmony_ci  UString MainPath;
235370b324cSopenharmony_ci                /* MainPath = Path for non-AltStream,
236370b324cSopenharmony_ci                   MainPath = Path of parent, if there is parent for AltStream. */
237370b324cSopenharmony_ci  UString AltStreamName;
238370b324cSopenharmony_ci  bool IsAltStream;
239370b324cSopenharmony_ci  bool WriteToAltStreamIfColon;
240370b324cSopenharmony_ci  #endif
241370b324cSopenharmony_ci
242370b324cSopenharmony_ci  bool IsDir;
243370b324cSopenharmony_ci  bool MainIsDir;
244370b324cSopenharmony_ci  UInt32 ParentIndex; // use it, if IsAltStream
245370b324cSopenharmony_ci
246370b324cSopenharmony_ci  #ifndef Z7_SFX
247370b324cSopenharmony_ci  bool _use_baseParentFolder_mode;
248370b324cSopenharmony_ci  int _baseParentFolder;
249370b324cSopenharmony_ci  #endif
250370b324cSopenharmony_ci
251370b324cSopenharmony_ci  CReadArcItem()
252370b324cSopenharmony_ci  {
253370b324cSopenharmony_ci    #ifdef SUPPORT_ALT_STREAMS
254370b324cSopenharmony_ci    WriteToAltStreamIfColon = false;
255370b324cSopenharmony_ci    #endif
256370b324cSopenharmony_ci
257370b324cSopenharmony_ci    #ifndef Z7_SFX
258370b324cSopenharmony_ci    _use_baseParentFolder_mode = false;
259370b324cSopenharmony_ci    _baseParentFolder = -1;
260370b324cSopenharmony_ci    #endif
261370b324cSopenharmony_ci  }
262370b324cSopenharmony_ci};
263370b324cSopenharmony_ci
264370b324cSopenharmony_ci
265370b324cSopenharmony_ci
266370b324cSopenharmony_ci
267370b324cSopenharmony_ciclass CArc
268370b324cSopenharmony_ci{
269370b324cSopenharmony_ci  HRESULT PrepareToOpen(const COpenOptions &op, unsigned formatIndex, CMyComPtr<IInArchive> &archive);
270370b324cSopenharmony_ci  HRESULT CheckZerosTail(const COpenOptions &op, UInt64 offset);
271370b324cSopenharmony_ci  HRESULT OpenStream2(const COpenOptions &options);
272370b324cSopenharmony_ci
273370b324cSopenharmony_ci  #ifndef Z7_SFX
274370b324cSopenharmony_ci  // parts.Back() can contain alt stream name "nams:AltName"
275370b324cSopenharmony_ci  HRESULT GetItem_PathToParent(UInt32 index, UInt32 parent, UStringVector &parts) const;
276370b324cSopenharmony_ci  #endif
277370b324cSopenharmony_ci
278370b324cSopenharmony_cipublic:
279370b324cSopenharmony_ci  CMyComPtr<IInArchive> Archive;
280370b324cSopenharmony_ci  CMyComPtr<IInStream> InStream;
281370b324cSopenharmony_ci          // we use InStream in 2 cases (ArcStreamOffset != 0):
282370b324cSopenharmony_ci          // 1) if we use additional cache stream
283370b324cSopenharmony_ci          // 2) we reopen sfx archive with CTailInStream
284370b324cSopenharmony_ci
285370b324cSopenharmony_ci  CMyComPtr<IArchiveGetRawProps> GetRawProps;
286370b324cSopenharmony_ci  CMyComPtr<IArchiveGetRootProps> GetRootProps;
287370b324cSopenharmony_ci
288370b324cSopenharmony_ci  bool IsParseArc;
289370b324cSopenharmony_ci
290370b324cSopenharmony_ci  bool IsTree;
291370b324cSopenharmony_ci  bool IsReadOnly;
292370b324cSopenharmony_ci
293370b324cSopenharmony_ci  bool Ask_Deleted;
294370b324cSopenharmony_ci  bool Ask_AltStream;
295370b324cSopenharmony_ci  bool Ask_Aux;
296370b324cSopenharmony_ci  bool Ask_INode;
297370b324cSopenharmony_ci
298370b324cSopenharmony_ci  bool IgnoreSplit; // don't try split handler
299370b324cSopenharmony_ci
300370b324cSopenharmony_ci  UString Path;
301370b324cSopenharmony_ci  UString filePath;
302370b324cSopenharmony_ci  UString DefaultName;
303370b324cSopenharmony_ci  int FormatIndex;     // -1 means Parser
304370b324cSopenharmony_ci  UInt32 SubfileIndex; // (UInt32)(Int32)-1; means no subfile
305370b324cSopenharmony_ci
306370b324cSopenharmony_ci  // CFiTime MTime;
307370b324cSopenharmony_ci  // bool MTime_Defined;
308370b324cSopenharmony_ci  CArcTime MTime;
309370b324cSopenharmony_ci
310370b324cSopenharmony_ci  Int64 Offset; // it's offset of start of archive inside stream that is open by Archive Handler
311370b324cSopenharmony_ci  UInt64 PhySize;
312370b324cSopenharmony_ci  // UInt64 OkPhySize;
313370b324cSopenharmony_ci  bool PhySize_Defined;
314370b324cSopenharmony_ci  // bool OkPhySize_Defined;
315370b324cSopenharmony_ci  UInt64 FileSize;
316370b324cSopenharmony_ci  UInt64 AvailPhySize; // PhySize, but it's reduced if exceed end of file
317370b324cSopenharmony_ci
318370b324cSopenharmony_ci  CArcErrorInfo ErrorInfo; // for OK archives
319370b324cSopenharmony_ci  CArcErrorInfo NonOpen_ErrorInfo; // ErrorInfo for mainArchive (false OPEN)
320370b324cSopenharmony_ci
321370b324cSopenharmony_ci  UInt64 GetEstmatedPhySize() const { return PhySize_Defined ? PhySize : FileSize; }
322370b324cSopenharmony_ci
323370b324cSopenharmony_ci  UInt64 ArcStreamOffset; // offset of stream that is open by Archive Handler
324370b324cSopenharmony_ci  Int64 GetGlobalOffset() const { return (Int64)ArcStreamOffset + Offset; } // it's global offset of archive
325370b324cSopenharmony_ci
326370b324cSopenharmony_ci  // AString ErrorFlagsText;
327370b324cSopenharmony_ci
328370b324cSopenharmony_ci  // void Set_ErrorFlagsText();
329370b324cSopenharmony_ci
330370b324cSopenharmony_ci  CArc():
331370b324cSopenharmony_ci    // MTime_Defined(false),
332370b324cSopenharmony_ci    IsTree(false),
333370b324cSopenharmony_ci    IsReadOnly(false),
334370b324cSopenharmony_ci    Ask_Deleted(false),
335370b324cSopenharmony_ci    Ask_AltStream(false),
336370b324cSopenharmony_ci    Ask_Aux(false),
337370b324cSopenharmony_ci    Ask_INode(false),
338370b324cSopenharmony_ci    IgnoreSplit(false)
339370b324cSopenharmony_ci    {}
340370b324cSopenharmony_ci
341370b324cSopenharmony_ci  HRESULT ReadBasicProps(IInArchive *archive, UInt64 startPos, HRESULT openRes);
342370b324cSopenharmony_ci
343370b324cSopenharmony_ci  HRESULT Close()
344370b324cSopenharmony_ci  {
345370b324cSopenharmony_ci    InStream.Release();
346370b324cSopenharmony_ci    return Archive->Close();
347370b324cSopenharmony_ci  }
348370b324cSopenharmony_ci
349370b324cSopenharmony_ci  HRESULT GetItem_Path(UInt32 index, UString &result) const;
350370b324cSopenharmony_ci  HRESULT GetItem_DefaultPath(UInt32 index, UString &result) const;
351370b324cSopenharmony_ci
352370b324cSopenharmony_ci  // GetItemPath2 adds [DELETED] dir prefix for deleted items.
353370b324cSopenharmony_ci  HRESULT GetItem_Path2(UInt32 index, UString &result) const;
354370b324cSopenharmony_ci
355370b324cSopenharmony_ci  HRESULT GetItem(UInt32 index, CReadArcItem &item) const;
356370b324cSopenharmony_ci
357370b324cSopenharmony_ci  HRESULT GetItem_Size(UInt32 index, UInt64 &size, bool &defined) const;
358370b324cSopenharmony_ci
359370b324cSopenharmony_ci  /* if (GetProperty() returns vt==VT_EMPTY), this function sets
360370b324cSopenharmony_ci     timestamp from archive file timestamp (MTime).
361370b324cSopenharmony_ci     So (at) will be set in most cases (at.Def == true)
362370b324cSopenharmony_ci     if (at.Prec == 0)
363370b324cSopenharmony_ci     {
364370b324cSopenharmony_ci       it means that (Prec == 0) was returned for (kpidMTime),
365370b324cSopenharmony_ci       and no value was returned for (kpidTimeType).
366370b324cSopenharmony_ci       it can mean Windows precision or unknown precision.
367370b324cSopenharmony_ci     }
368370b324cSopenharmony_ci  */
369370b324cSopenharmony_ci  HRESULT GetItem_MTime(UInt32 index, CArcTime &at) const;
370370b324cSopenharmony_ci
371370b324cSopenharmony_ci  HRESULT IsItem_Anti(UInt32 index, bool &result) const
372370b324cSopenharmony_ci    { return Archive_GetItemBoolProp(Archive, index, kpidIsAnti, result); }
373370b324cSopenharmony_ci
374370b324cSopenharmony_ci
375370b324cSopenharmony_ci  HRESULT OpenStream(const COpenOptions &options);
376370b324cSopenharmony_ci  HRESULT OpenStreamOrFile(COpenOptions &options);
377370b324cSopenharmony_ci
378370b324cSopenharmony_ci  HRESULT ReOpen(const COpenOptions &options, IArchiveOpenCallback *openCallback_Additional);
379370b324cSopenharmony_ci
380370b324cSopenharmony_ci  HRESULT CreateNewTailStream(CMyComPtr<IInStream> &stream);
381370b324cSopenharmony_ci
382370b324cSopenharmony_ci  bool IsHashHandler(const COpenOptions &options) const
383370b324cSopenharmony_ci  {
384370b324cSopenharmony_ci    if (FormatIndex < 0)
385370b324cSopenharmony_ci      return false;
386370b324cSopenharmony_ci    return options.codecs->Formats[(unsigned)FormatIndex].Flags_HashHandler();
387370b324cSopenharmony_ci  }
388370b324cSopenharmony_ci};
389370b324cSopenharmony_ci
390370b324cSopenharmony_cistruct CArchiveLink
391370b324cSopenharmony_ci{
392370b324cSopenharmony_ci  CObjectVector<CArc> Arcs;
393370b324cSopenharmony_ci  UStringVector VolumePaths;
394370b324cSopenharmony_ci  UInt64 VolumesSize;
395370b324cSopenharmony_ci  bool IsOpen;
396370b324cSopenharmony_ci
397370b324cSopenharmony_ci  bool PasswordWasAsked;
398370b324cSopenharmony_ci  // UString Password;
399370b324cSopenharmony_ci
400370b324cSopenharmony_ci  // int NonOpenErrorFormatIndex; // - 1 means no Error.
401370b324cSopenharmony_ci  UString NonOpen_ArcPath;
402370b324cSopenharmony_ci
403370b324cSopenharmony_ci  CArcErrorInfo NonOpen_ErrorInfo;
404370b324cSopenharmony_ci
405370b324cSopenharmony_ci  // UString ErrorsText;
406370b324cSopenharmony_ci  // void Set_ErrorsText();
407370b324cSopenharmony_ci
408370b324cSopenharmony_ci  CArchiveLink():
409370b324cSopenharmony_ci      VolumesSize(0),
410370b324cSopenharmony_ci      IsOpen(false),
411370b324cSopenharmony_ci      PasswordWasAsked(false)
412370b324cSopenharmony_ci      {}
413370b324cSopenharmony_ci
414370b324cSopenharmony_ci  void KeepModeForNextOpen();
415370b324cSopenharmony_ci  HRESULT Close();
416370b324cSopenharmony_ci  void Release();
417370b324cSopenharmony_ci  ~CArchiveLink() { Release(); }
418370b324cSopenharmony_ci
419370b324cSopenharmony_ci  const CArc *GetArc() const { return &Arcs.Back(); }
420370b324cSopenharmony_ci  IInArchive *GetArchive() const { return Arcs.Back().Archive; }
421370b324cSopenharmony_ci  IArchiveGetRawProps *GetArchiveGetRawProps() const { return Arcs.Back().GetRawProps; }
422370b324cSopenharmony_ci  IArchiveGetRootProps *GetArchiveGetRootProps() const { return Arcs.Back().GetRootProps; }
423370b324cSopenharmony_ci
424370b324cSopenharmony_ci  /*
425370b324cSopenharmony_ci  Open() opens archive and COpenOptions::callback
426370b324cSopenharmony_ci  Open2() uses COpenCallbackImp that implements Volumes and password callback
427370b324cSopenharmony_ci  Open3() calls Open2() and callbackUI->Open_Finished();
428370b324cSopenharmony_ci  Open_Strict() returns S_FALSE also in case, if there is non-open expected nested archive.
429370b324cSopenharmony_ci  */
430370b324cSopenharmony_ci
431370b324cSopenharmony_ci  HRESULT Open(COpenOptions &options);
432370b324cSopenharmony_ci  HRESULT Open2(COpenOptions &options, IOpenCallbackUI *callbackUI);
433370b324cSopenharmony_ci  HRESULT Open3(COpenOptions &options, IOpenCallbackUI *callbackUI);
434370b324cSopenharmony_ci
435370b324cSopenharmony_ci  HRESULT Open_Strict(COpenOptions &options, IOpenCallbackUI *callbackUI)
436370b324cSopenharmony_ci  {
437370b324cSopenharmony_ci    HRESULT result = Open3(options, callbackUI);
438370b324cSopenharmony_ci    if (result == S_OK && NonOpen_ErrorInfo.ErrorFormatIndex >= 0)
439370b324cSopenharmony_ci      result = S_FALSE;
440370b324cSopenharmony_ci    return result;
441370b324cSopenharmony_ci  }
442370b324cSopenharmony_ci
443370b324cSopenharmony_ci  HRESULT ReOpen(COpenOptions &options);
444370b324cSopenharmony_ci};
445370b324cSopenharmony_ci
446370b324cSopenharmony_cibool ParseOpenTypes(CCodecs &codecs, const UString &s, CObjectVector<COpenType> &types);
447370b324cSopenharmony_ci
448370b324cSopenharmony_ci// bool IsHashType(const CObjectVector<COpenType> &types);
449370b324cSopenharmony_ci
450370b324cSopenharmony_ci
451370b324cSopenharmony_cistruct CDirPathSortPair
452370b324cSopenharmony_ci{
453370b324cSopenharmony_ci  unsigned Len;
454370b324cSopenharmony_ci  unsigned Index;
455370b324cSopenharmony_ci
456370b324cSopenharmony_ci  void SetNumSlashes(const FChar *s);
457370b324cSopenharmony_ci
458370b324cSopenharmony_ci  int Compare(const CDirPathSortPair &a) const
459370b324cSopenharmony_ci  {
460370b324cSopenharmony_ci    // We need sorting order where parent items will be after child items
461370b324cSopenharmony_ci    if (Len < a.Len) return 1;
462370b324cSopenharmony_ci    if (Len > a.Len) return -1;
463370b324cSopenharmony_ci    if (Index < a.Index) return -1;
464370b324cSopenharmony_ci    if (Index > a.Index) return 1;
465370b324cSopenharmony_ci    return 0;
466370b324cSopenharmony_ci  }
467370b324cSopenharmony_ci};
468370b324cSopenharmony_ci
469370b324cSopenharmony_ci#endif
470