• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // UpdateCallback.h
2 
3 #ifndef ZIP7_INC_UPDATE_CALLBACK_H
4 #define ZIP7_INC_UPDATE_CALLBACK_H
5 
6 #include "../../../Common/MyCom.h"
7 
8 #include "../../Common/FileStreams.h"
9 
10 #include "../../IPassword.h"
11 #include "../../ICoder.h"
12 
13 #include "../Common/UpdatePair.h"
14 #include "../Common/UpdateProduce.h"
15 
16 #include "OpenArchive.h"
17 
18 struct CArcToDoStat
19 {
20   CDirItemsStat2 NewData;
21   CDirItemsStat2 OldData;
22   CDirItemsStat2 DeleteData;
23 
Get_NumDataItems_TotalCArcToDoStat24   UInt64 Get_NumDataItems_Total() const
25   {
26     return NewData.Get_NumDataItems2() + OldData.Get_NumDataItems2();
27   }
28 };
29 
30 
31 Z7_PURE_INTERFACES_BEGIN
32 
33 #define Z7_IFACEN_IUpdateCallbackUI(x) \
34   virtual HRESULT WriteSfx(const wchar_t *name, UInt64 size) x \
35   virtual HRESULT SetTotal(UInt64 size) x \
36   virtual HRESULT SetCompleted(const UInt64 *completeValue) x \
37   virtual HRESULT SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize) x \
38   virtual HRESULT CheckBreak() x \
39   /* virtual HRESULT Finalize() x */ \
40   virtual HRESULT SetNumItems(const CArcToDoStat &stat) x \
41   virtual HRESULT GetStream(const wchar_t *name, bool isDir, bool isAnti, UInt32 mode) x \
42   virtual HRESULT OpenFileError(const FString &path, DWORD systemError) x \
43   virtual HRESULT ReadingFileError(const FString &path, DWORD systemError) x \
44   virtual HRESULT SetOperationResult(Int32 opRes) x \
45   virtual HRESULT ReportExtractResult(Int32 opRes, Int32 isEncrypted, const wchar_t *name) x \
46   virtual HRESULT ReportUpdateOperation(UInt32 op, const wchar_t *name, bool isDir) x \
47   /* virtual HRESULT SetPassword(const UString &password) x */ \
48   virtual HRESULT CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password) x \
49   virtual HRESULT CryptoGetTextPassword(BSTR *password) x \
50   virtual HRESULT ShowDeleteFile(const wchar_t *name, bool isDir) x \
51 
52   /*
53   virtual HRESULT ReportProp(UInt32 indexType, UInt32 index, PROPID propID, const PROPVARIANT *value) x \
54   virtual HRESULT ReportRawProp(UInt32 indexType, UInt32 index, PROPID propID, const void *data, UInt32 dataSize, UInt32 propType) x \
55   virtual HRESULT ReportFinished(UInt32 indexType, UInt32 index, Int32 opRes) x \
56   */
57 
58   /* virtual HRESULT CloseProgress() { return S_OK; } */
59 
60 Z7_IFACE_DECL_PURE(IUpdateCallbackUI)
61 Z7_PURE_INTERFACES_END
62 
63 struct CKeyKeyValPair
64 {
65   UInt64 Key1;
66   UInt64 Key2;
67   unsigned Value;
68 
CompareCKeyKeyValPair69   int Compare(const CKeyKeyValPair &a) const
70   {
71     if (Key1 < a.Key1) return -1;
72     if (Key1 > a.Key1) return 1;
73     return MyCompare(Key2, a.Key2);
74   }
75 };
76 
77 
78 class CArchiveUpdateCallback Z7_final:
79   public IArchiveUpdateCallback2,
80   public IArchiveUpdateCallbackFile,
81   // public IArchiveUpdateCallbackArcProp,
82   public IArchiveExtractCallbackMessage2,
83   public IArchiveGetRawProps,
84   public IArchiveGetRootProps,
85   public ICryptoGetTextPassword2,
86   public ICryptoGetTextPassword,
87   public ICompressProgressInfo,
88   public IInFileStream_Callback,
89   public CMyUnknownImp
90 {
91   Z7_COM_QI_BEGIN2(IArchiveUpdateCallback2)
92     Z7_COM_QI_ENTRY(IArchiveUpdateCallbackFile)
93     // Z7_COM_QI_ENTRY(IArchiveUpdateCallbackArcProp)
94     Z7_COM_QI_ENTRY(IArchiveExtractCallbackMessage2)
95     Z7_COM_QI_ENTRY(IArchiveGetRawProps)
96     Z7_COM_QI_ENTRY(IArchiveGetRootProps)
97     Z7_COM_QI_ENTRY(ICryptoGetTextPassword2)
98     Z7_COM_QI_ENTRY(ICryptoGetTextPassword)
99     Z7_COM_QI_ENTRY(ICompressProgressInfo)
100   Z7_COM_QI_END
101   Z7_COM_ADDREF_RELEASE
102 
103   Z7_IFACE_COM7_IMP(ICompressProgressInfo)
104 
105   Z7_IFACE_COM7_IMP(IProgress)
106   Z7_IFACE_COM7_IMP(IArchiveUpdateCallback)
107   Z7_IFACE_COM7_IMP(IArchiveUpdateCallback2)
108   Z7_IFACE_COM7_IMP(IArchiveUpdateCallbackFile)
109   // Z7_IFACE_COM7_IMP(IArchiveUpdateCallbackArcProp)
110   Z7_IFACE_COM7_IMP(IArchiveExtractCallbackMessage2)
111   Z7_IFACE_COM7_IMP(IArchiveGetRawProps)
112   Z7_IFACE_COM7_IMP(IArchiveGetRootProps)
113   Z7_IFACE_COM7_IMP(ICryptoGetTextPassword2)
114   Z7_IFACE_COM7_IMP(ICryptoGetTextPassword)
115 
116 
117   void UpdateProcessedItemStatus(unsigned dirIndex);
118 
119 public:
120   bool PreserveATime;
121   bool ShareForWrite;
122   bool StopAfterOpenError;
123   bool StdInMode;
124 
125   bool KeepOriginalItemNames;
126   bool StoreNtSecurity;
127   bool StoreHardLinks;
128   bool StoreSymLinks;
129 
130   bool StoreOwnerId;
131   bool StoreOwnerName;
132 
133   bool Need_LatestMTime;
134   bool LatestMTime_Defined;
135 
136   /*
137   bool Need_ArcMTime_Report;
138   bool ArcMTime_WasReported;
139   */
140 
141   CRecordVector<UInt32> _openFiles_Indexes;
142   FStringVector _openFiles_Paths;
143   // CRecordVector< CInFileStream* > _openFiles_Streams;
144 
AreAllFilesClosed()145   bool AreAllFilesClosed() const { return _openFiles_Indexes.IsEmpty(); }
146   virtual HRESULT InFileStream_On_Error(UINT_PTR val, DWORD error) Z7_override;
147   virtual void InFileStream_On_Destroy(CInFileStream *stream, UINT_PTR val) Z7_override;
148 
149   IUpdateCallbackUI *Callback;
150 
151   const CDirItems *DirItems;
152   const CDirItem *ParentDirItem;
153 
154   const CArc *Arc;
155   CMyComPtr<IInArchive> Archive;
156   const CObjectVector<CArcItem> *ArcItems;
157   const CRecordVector<CUpdatePair2> *UpdatePairs;
158 
159   CRecordVector<UInt64> VolumesSizes;
160   FString VolName;
161   FString VolExt;
162   UString ArcFileName; // without path prefix
163 
164   const UStringVector *NewNames;
165   const UString *Comment;
166   int CommentIndex;
167 
168   /*
169   CArcTime Reported_ArcMTime;
170   */
171   CFiTime LatestMTime;
172 
173   Byte *ProcessedItemsStatuses;
174 
175 
176   CArchiveUpdateCallback();
177 
IsDir(const CUpdatePair2 & up)178   bool IsDir(const CUpdatePair2 &up) const
179   {
180     if (up.DirIndex >= 0)
181       return DirItems->Items[(unsigned)up.DirIndex].IsDir();
182     else if (up.ArcIndex >= 0)
183       return (*ArcItems)[(unsigned)up.ArcIndex].IsDir;
184     return false;
185   }
186 
187 private:
188   #if defined(_WIN32) && !defined(UNDER_CE)
189   bool _saclEnabled;
190   #endif
191   CRecordVector<CKeyKeyValPair> _map;
192 
193   UInt32 _hardIndex_From;
194   UInt32 _hardIndex_To;
195 };
196 
197 #endif
198