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