xref: /aosp_15_r20/external/lzma/CPP/7zip/UI/Agent/UpdateCallbackAgent.cpp (revision f6dc9357d832569d4d1f5d24eacdb3935a1ae8e6)
1 // UpdateCallbackAgent.h
2 
3 #include "StdAfx.h"
4 
5 #include "../../../Common/IntToString.h"
6 
7 #include "../../../Windows/ErrorMsg.h"
8 
9 #include "UpdateCallbackAgent.h"
10 
11 using namespace NWindows;
12 
SetCallback(IFolderArchiveUpdateCallback * callback)13 void CUpdateCallbackAgent::SetCallback(IFolderArchiveUpdateCallback *callback)
14 {
15   Callback = callback;
16   _compressProgress.Release();
17   Callback2.Release();
18   if (Callback)
19   {
20     Callback.QueryInterface(IID_ICompressProgressInfo, &_compressProgress);
21     Callback.QueryInterface(IID_IFolderArchiveUpdateCallback2, &Callback2);
22   }
23 }
24 
SetNumItems(const CArcToDoStat & stat)25 HRESULT CUpdateCallbackAgent::SetNumItems(const CArcToDoStat &stat)
26 {
27   if (Callback)
28     return Callback->SetNumFiles(stat.Get_NumDataItems_Total());
29   return S_OK;
30 }
31 
32 
WriteSfx(const wchar_t *,UInt64)33 HRESULT CUpdateCallbackAgent::WriteSfx(const wchar_t * /* name */, UInt64 /* size */)
34 {
35   return S_OK;
36 }
37 
38 
SetTotal(UINT64 size)39 HRESULT CUpdateCallbackAgent::SetTotal(UINT64 size)
40 {
41   if (Callback)
42     return Callback->SetTotal(size);
43   return S_OK;
44 }
45 
SetCompleted(const UINT64 * completeValue)46 HRESULT CUpdateCallbackAgent::SetCompleted(const UINT64 *completeValue)
47 {
48   if (Callback)
49     return Callback->SetCompleted(completeValue);
50   return S_OK;
51 }
52 
SetRatioInfo(const UInt64 * inSize,const UInt64 * outSize)53 HRESULT CUpdateCallbackAgent::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)
54 {
55   if (_compressProgress)
56     return _compressProgress->SetRatioInfo(inSize, outSize);
57   return S_OK;
58 }
59 
CheckBreak()60 HRESULT CUpdateCallbackAgent::CheckBreak()
61 {
62   return S_OK;
63 }
64 
65 /*
66 HRESULT CUpdateCallbackAgent::Finalize()
67 {
68   return S_OK;
69 }
70 */
71 
OpenFileError(const FString & path,DWORD systemError)72 HRESULT CUpdateCallbackAgent::OpenFileError(const FString &path, DWORD systemError)
73 {
74   const HRESULT hres = HRESULT_FROM_WIN32(systemError);
75   // if (systemError == ERROR_SHARING_VIOLATION)
76   {
77     if (Callback2)
78     {
79       RINOK(Callback2->OpenFileError(fs2us(path), hres))
80       return S_FALSE;
81     }
82 
83     if (Callback)
84     {
85       UString s ("WARNING: ");
86       s += NError::MyFormatMessage(systemError);
87       s += ": ";
88       s += fs2us(path);
89       RINOK(Callback->UpdateErrorMessage(s))
90       return S_FALSE;
91     }
92   }
93   // FailedFiles.Add(name);
94   return hres;
95 }
96 
ReadingFileError(const FString & path,DWORD systemError)97 HRESULT CUpdateCallbackAgent::ReadingFileError(const FString &path, DWORD systemError)
98 {
99   const HRESULT hres = HRESULT_FROM_WIN32(systemError);
100 
101   // if (systemError == ERROR_SHARING_VIOLATION)
102   {
103     if (Callback2)
104     {
105       RINOK(Callback2->ReadingFileError(fs2us(path), hres))
106     }
107     else if (Callback)
108     {
109       UString s ("ERROR: ");
110       s += NError::MyFormatMessage(systemError);
111       s += ": ";
112       s += fs2us(path);
113       RINOK(Callback->UpdateErrorMessage(s))
114     }
115   }
116   // FailedFiles.Add(name);
117   return hres;
118 }
119 
GetStream(const wchar_t * name,bool isDir,bool,UInt32 mode)120 HRESULT CUpdateCallbackAgent::GetStream(const wchar_t *name, bool isDir, bool /* isAnti */, UInt32 mode)
121 {
122   if (Callback2)
123     return Callback2->ReportUpdateOperation(mode, name, BoolToInt(isDir));
124   if (Callback)
125     return Callback->CompressOperation(name);
126   return S_OK;
127 }
128 
SetOperationResult(Int32 operationResult)129 HRESULT CUpdateCallbackAgent::SetOperationResult(Int32 operationResult)
130 {
131   if (Callback)
132     return Callback->OperationResult(operationResult);
133   return S_OK;
134 }
135 
136 void SetExtractErrorMessage(Int32 opRes, Int32 encrypted, const wchar_t *fileName, UString &s);
137 
ReportExtractResult(Int32 opRes,Int32 isEncrypted,const wchar_t * name)138 HRESULT CUpdateCallbackAgent::ReportExtractResult(Int32 opRes, Int32 isEncrypted, const wchar_t *name)
139 {
140   if (Callback2)
141   {
142     return Callback2->ReportExtractResult(opRes, isEncrypted, name);
143   }
144   /*
145   if (mode != NArchive::NExtract::NOperationResult::kOK)
146   {
147     Int32 encrypted = 0;
148     UString s;
149     SetExtractErrorMessage(mode, encrypted, name, s);
150     // ProgressDialog->Sync.AddError_Message(s);
151   }
152   */
153   return S_OK;
154 }
155 
ReportUpdateOperation(UInt32 op,const wchar_t * name,bool isDir)156 HRESULT CUpdateCallbackAgent::ReportUpdateOperation(UInt32 op, const wchar_t *name, bool isDir)
157 {
158   if (Callback2)
159   {
160     return Callback2->ReportUpdateOperation(op, name, BoolToInt(isDir));
161   }
162   return S_OK;
163 }
164 
165 /*
166 HRESULT CUpdateCallbackAgent::SetPassword(const UString &
167     #ifndef Z7_NO_CRYPTO
168     password
169     #endif
170     )
171 {
172   #ifndef Z7_NO_CRYPTO
173   PasswordIsDefined = true;
174   Password = password;
175   #endif
176   return S_OK;
177 }
178 */
179 
CryptoGetTextPassword2(Int32 * passwordIsDefined,BSTR * password)180 HRESULT CUpdateCallbackAgent::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password)
181 {
182   *password = NULL;
183   *passwordIsDefined = BoolToInt(false);
184   if (!_cryptoGetTextPassword)
185   {
186     if (!Callback)
187       return S_OK;
188     Callback.QueryInterface(IID_ICryptoGetTextPassword2, &_cryptoGetTextPassword);
189     if (!_cryptoGetTextPassword)
190       return S_OK;
191   }
192   return _cryptoGetTextPassword->CryptoGetTextPassword2(passwordIsDefined, password);
193 }
194 
CryptoGetTextPassword(BSTR * password)195 HRESULT CUpdateCallbackAgent::CryptoGetTextPassword(BSTR *password)
196 {
197   *password = NULL;
198   CMyComPtr<ICryptoGetTextPassword> getTextPassword;
199   Callback.QueryInterface(IID_ICryptoGetTextPassword, &getTextPassword);
200   if (!getTextPassword)
201     return E_NOTIMPL;
202   return getTextPassword->CryptoGetTextPassword(password);
203 }
204 
ShowDeleteFile(const wchar_t * name,bool)205 HRESULT CUpdateCallbackAgent::ShowDeleteFile(const wchar_t *name, bool /* isDir */)
206 {
207   return Callback->DeleteOperation(name);
208 }
209