1370b324cSopenharmony_ci// UpdateCallback.h
2370b324cSopenharmony_ci
3370b324cSopenharmony_ci#ifndef ZIP7_INC_UPDATE_CALLBACK_H
4370b324cSopenharmony_ci#define ZIP7_INC_UPDATE_CALLBACK_H
5370b324cSopenharmony_ci
6370b324cSopenharmony_ci#include "../../../Common/MyCom.h"
7370b324cSopenharmony_ci
8370b324cSopenharmony_ci#include "../../Common/FileStreams.h"
9370b324cSopenharmony_ci
10370b324cSopenharmony_ci#include "../../IPassword.h"
11370b324cSopenharmony_ci#include "../../ICoder.h"
12370b324cSopenharmony_ci
13370b324cSopenharmony_ci#include "../Common/UpdatePair.h"
14370b324cSopenharmony_ci#include "../Common/UpdateProduce.h"
15370b324cSopenharmony_ci
16370b324cSopenharmony_ci#include "OpenArchive.h"
17370b324cSopenharmony_ci
18370b324cSopenharmony_cistruct CArcToDoStat
19370b324cSopenharmony_ci{
20370b324cSopenharmony_ci  CDirItemsStat2 NewData;
21370b324cSopenharmony_ci  CDirItemsStat2 OldData;
22370b324cSopenharmony_ci  CDirItemsStat2 DeleteData;
23370b324cSopenharmony_ci
24370b324cSopenharmony_ci  UInt64 Get_NumDataItems_Total() const
25370b324cSopenharmony_ci  {
26370b324cSopenharmony_ci    return NewData.Get_NumDataItems2() + OldData.Get_NumDataItems2();
27370b324cSopenharmony_ci  }
28370b324cSopenharmony_ci};
29370b324cSopenharmony_ci
30370b324cSopenharmony_ci
31370b324cSopenharmony_ciZ7_PURE_INTERFACES_BEGIN
32370b324cSopenharmony_ci
33370b324cSopenharmony_ci#define Z7_IFACEN_IUpdateCallbackUI(x) \
34370b324cSopenharmony_ci  virtual HRESULT WriteSfx(const wchar_t *name, UInt64 size) x \
35370b324cSopenharmony_ci  virtual HRESULT SetTotal(UInt64 size) x \
36370b324cSopenharmony_ci  virtual HRESULT SetCompleted(const UInt64 *completeValue) x \
37370b324cSopenharmony_ci  virtual HRESULT SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize) x \
38370b324cSopenharmony_ci  virtual HRESULT CheckBreak() x \
39370b324cSopenharmony_ci  /* virtual HRESULT Finalize() x */ \
40370b324cSopenharmony_ci  virtual HRESULT SetNumItems(const CArcToDoStat &stat) x \
41370b324cSopenharmony_ci  virtual HRESULT GetStream(const wchar_t *name, bool isDir, bool isAnti, UInt32 mode) x \
42370b324cSopenharmony_ci  virtual HRESULT OpenFileError(const FString &path, DWORD systemError) x \
43370b324cSopenharmony_ci  virtual HRESULT ReadingFileError(const FString &path, DWORD systemError) x \
44370b324cSopenharmony_ci  virtual HRESULT SetOperationResult(Int32 opRes) x \
45370b324cSopenharmony_ci  virtual HRESULT ReportExtractResult(Int32 opRes, Int32 isEncrypted, const wchar_t *name) x \
46370b324cSopenharmony_ci  virtual HRESULT ReportUpdateOperation(UInt32 op, const wchar_t *name, bool isDir) x \
47370b324cSopenharmony_ci  /* virtual HRESULT SetPassword(const UString &password) x */ \
48370b324cSopenharmony_ci  virtual HRESULT CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password) x \
49370b324cSopenharmony_ci  virtual HRESULT CryptoGetTextPassword(BSTR *password) x \
50370b324cSopenharmony_ci  virtual HRESULT ShowDeleteFile(const wchar_t *name, bool isDir) x \
51370b324cSopenharmony_ci
52370b324cSopenharmony_ci  /*
53370b324cSopenharmony_ci  virtual HRESULT ReportProp(UInt32 indexType, UInt32 index, PROPID propID, const PROPVARIANT *value) x \
54370b324cSopenharmony_ci  virtual HRESULT ReportRawProp(UInt32 indexType, UInt32 index, PROPID propID, const void *data, UInt32 dataSize, UInt32 propType) x \
55370b324cSopenharmony_ci  virtual HRESULT ReportFinished(UInt32 indexType, UInt32 index, Int32 opRes) x \
56370b324cSopenharmony_ci  */
57370b324cSopenharmony_ci
58370b324cSopenharmony_ci  /* virtual HRESULT CloseProgress() { return S_OK; } */
59370b324cSopenharmony_ci
60370b324cSopenharmony_ciZ7_IFACE_DECL_PURE(IUpdateCallbackUI)
61370b324cSopenharmony_ciZ7_PURE_INTERFACES_END
62370b324cSopenharmony_ci
63370b324cSopenharmony_cistruct CKeyKeyValPair
64370b324cSopenharmony_ci{
65370b324cSopenharmony_ci  UInt64 Key1;
66370b324cSopenharmony_ci  UInt64 Key2;
67370b324cSopenharmony_ci  unsigned Value;
68370b324cSopenharmony_ci
69370b324cSopenharmony_ci  int Compare(const CKeyKeyValPair &a) const
70370b324cSopenharmony_ci  {
71370b324cSopenharmony_ci    if (Key1 < a.Key1) return -1;
72370b324cSopenharmony_ci    if (Key1 > a.Key1) return 1;
73370b324cSopenharmony_ci    return MyCompare(Key2, a.Key2);
74370b324cSopenharmony_ci  }
75370b324cSopenharmony_ci};
76370b324cSopenharmony_ci
77370b324cSopenharmony_ci
78370b324cSopenharmony_ciclass CArchiveUpdateCallback Z7_final:
79370b324cSopenharmony_ci  public IArchiveUpdateCallback2,
80370b324cSopenharmony_ci  public IArchiveUpdateCallbackFile,
81370b324cSopenharmony_ci  // public IArchiveUpdateCallbackArcProp,
82370b324cSopenharmony_ci  public IArchiveExtractCallbackMessage2,
83370b324cSopenharmony_ci  public IArchiveGetRawProps,
84370b324cSopenharmony_ci  public IArchiveGetRootProps,
85370b324cSopenharmony_ci  public ICryptoGetTextPassword2,
86370b324cSopenharmony_ci  public ICryptoGetTextPassword,
87370b324cSopenharmony_ci  public ICompressProgressInfo,
88370b324cSopenharmony_ci  public IInFileStream_Callback,
89370b324cSopenharmony_ci  public CMyUnknownImp
90370b324cSopenharmony_ci{
91370b324cSopenharmony_ci  Z7_COM_QI_BEGIN2(IArchiveUpdateCallback2)
92370b324cSopenharmony_ci    Z7_COM_QI_ENTRY(IArchiveUpdateCallbackFile)
93370b324cSopenharmony_ci    // Z7_COM_QI_ENTRY(IArchiveUpdateCallbackArcProp)
94370b324cSopenharmony_ci    Z7_COM_QI_ENTRY(IArchiveExtractCallbackMessage2)
95370b324cSopenharmony_ci    Z7_COM_QI_ENTRY(IArchiveGetRawProps)
96370b324cSopenharmony_ci    Z7_COM_QI_ENTRY(IArchiveGetRootProps)
97370b324cSopenharmony_ci    Z7_COM_QI_ENTRY(ICryptoGetTextPassword2)
98370b324cSopenharmony_ci    Z7_COM_QI_ENTRY(ICryptoGetTextPassword)
99370b324cSopenharmony_ci    Z7_COM_QI_ENTRY(ICompressProgressInfo)
100370b324cSopenharmony_ci  Z7_COM_QI_END
101370b324cSopenharmony_ci  Z7_COM_ADDREF_RELEASE
102370b324cSopenharmony_ci
103370b324cSopenharmony_ci  Z7_IFACE_COM7_IMP(ICompressProgressInfo)
104370b324cSopenharmony_ci
105370b324cSopenharmony_ci  Z7_IFACE_COM7_IMP(IProgress)
106370b324cSopenharmony_ci  Z7_IFACE_COM7_IMP(IArchiveUpdateCallback)
107370b324cSopenharmony_ci  Z7_IFACE_COM7_IMP(IArchiveUpdateCallback2)
108370b324cSopenharmony_ci  Z7_IFACE_COM7_IMP(IArchiveUpdateCallbackFile)
109370b324cSopenharmony_ci  // Z7_IFACE_COM7_IMP(IArchiveUpdateCallbackArcProp)
110370b324cSopenharmony_ci  Z7_IFACE_COM7_IMP(IArchiveExtractCallbackMessage2)
111370b324cSopenharmony_ci  Z7_IFACE_COM7_IMP(IArchiveGetRawProps)
112370b324cSopenharmony_ci  Z7_IFACE_COM7_IMP(IArchiveGetRootProps)
113370b324cSopenharmony_ci  Z7_IFACE_COM7_IMP(ICryptoGetTextPassword2)
114370b324cSopenharmony_ci  Z7_IFACE_COM7_IMP(ICryptoGetTextPassword)
115370b324cSopenharmony_ci
116370b324cSopenharmony_ci
117370b324cSopenharmony_ci  void UpdateProcessedItemStatus(unsigned dirIndex);
118370b324cSopenharmony_ci
119370b324cSopenharmony_cipublic:
120370b324cSopenharmony_ci  bool PreserveATime;
121370b324cSopenharmony_ci  bool ShareForWrite;
122370b324cSopenharmony_ci  bool StopAfterOpenError;
123370b324cSopenharmony_ci  bool StdInMode;
124370b324cSopenharmony_ci
125370b324cSopenharmony_ci  bool KeepOriginalItemNames;
126370b324cSopenharmony_ci  bool StoreNtSecurity;
127370b324cSopenharmony_ci  bool StoreHardLinks;
128370b324cSopenharmony_ci  bool StoreSymLinks;
129370b324cSopenharmony_ci
130370b324cSopenharmony_ci  bool StoreOwnerId;
131370b324cSopenharmony_ci  bool StoreOwnerName;
132370b324cSopenharmony_ci
133370b324cSopenharmony_ci  bool Need_LatestMTime;
134370b324cSopenharmony_ci  bool LatestMTime_Defined;
135370b324cSopenharmony_ci
136370b324cSopenharmony_ci  /*
137370b324cSopenharmony_ci  bool Need_ArcMTime_Report;
138370b324cSopenharmony_ci  bool ArcMTime_WasReported;
139370b324cSopenharmony_ci  */
140370b324cSopenharmony_ci
141370b324cSopenharmony_ci  CRecordVector<UInt32> _openFiles_Indexes;
142370b324cSopenharmony_ci  FStringVector _openFiles_Paths;
143370b324cSopenharmony_ci  // CRecordVector< CInFileStream* > _openFiles_Streams;
144370b324cSopenharmony_ci
145370b324cSopenharmony_ci  bool AreAllFilesClosed() const { return _openFiles_Indexes.IsEmpty(); }
146370b324cSopenharmony_ci  virtual HRESULT InFileStream_On_Error(UINT_PTR val, DWORD error) Z7_override;
147370b324cSopenharmony_ci  virtual void InFileStream_On_Destroy(CInFileStream *stream, UINT_PTR val) Z7_override;
148370b324cSopenharmony_ci
149370b324cSopenharmony_ci  IUpdateCallbackUI *Callback;
150370b324cSopenharmony_ci
151370b324cSopenharmony_ci  const CDirItems *DirItems;
152370b324cSopenharmony_ci  const CDirItem *ParentDirItem;
153370b324cSopenharmony_ci
154370b324cSopenharmony_ci  const CArc *Arc;
155370b324cSopenharmony_ci  CMyComPtr<IInArchive> Archive;
156370b324cSopenharmony_ci  const CObjectVector<CArcItem> *ArcItems;
157370b324cSopenharmony_ci  const CRecordVector<CUpdatePair2> *UpdatePairs;
158370b324cSopenharmony_ci
159370b324cSopenharmony_ci  CRecordVector<UInt64> VolumesSizes;
160370b324cSopenharmony_ci  FString VolName;
161370b324cSopenharmony_ci  FString VolExt;
162370b324cSopenharmony_ci  UString ArcFileName; // without path prefix
163370b324cSopenharmony_ci
164370b324cSopenharmony_ci  const UStringVector *NewNames;
165370b324cSopenharmony_ci  const UString *Comment;
166370b324cSopenharmony_ci  int CommentIndex;
167370b324cSopenharmony_ci
168370b324cSopenharmony_ci  /*
169370b324cSopenharmony_ci  CArcTime Reported_ArcMTime;
170370b324cSopenharmony_ci  */
171370b324cSopenharmony_ci  CFiTime LatestMTime;
172370b324cSopenharmony_ci
173370b324cSopenharmony_ci  Byte *ProcessedItemsStatuses;
174370b324cSopenharmony_ci
175370b324cSopenharmony_ci
176370b324cSopenharmony_ci  CArchiveUpdateCallback();
177370b324cSopenharmony_ci
178370b324cSopenharmony_ci  bool IsDir(const CUpdatePair2 &up) const
179370b324cSopenharmony_ci  {
180370b324cSopenharmony_ci    if (up.DirIndex >= 0)
181370b324cSopenharmony_ci      return DirItems->Items[(unsigned)up.DirIndex].IsDir();
182370b324cSopenharmony_ci    else if (up.ArcIndex >= 0)
183370b324cSopenharmony_ci      return (*ArcItems)[(unsigned)up.ArcIndex].IsDir;
184370b324cSopenharmony_ci    return false;
185370b324cSopenharmony_ci  }
186370b324cSopenharmony_ci
187370b324cSopenharmony_ciprivate:
188370b324cSopenharmony_ci  #if defined(_WIN32) && !defined(UNDER_CE)
189370b324cSopenharmony_ci  bool _saclEnabled;
190370b324cSopenharmony_ci  #endif
191370b324cSopenharmony_ci  CRecordVector<CKeyKeyValPair> _map;
192370b324cSopenharmony_ci
193370b324cSopenharmony_ci  UInt32 _hardIndex_From;
194370b324cSopenharmony_ci  UInt32 _hardIndex_To;
195370b324cSopenharmony_ci};
196370b324cSopenharmony_ci
197370b324cSopenharmony_ci#endif
198