xref: /aosp_15_r20/external/lzma/CPP/7zip/UI/Console/UpdateCallbackConsole.cpp (revision f6dc9357d832569d4d1f5d24eacdb3935a1ae8e6)
1 // UpdateCallbackConsole.cpp
2 
3 #include "StdAfx.h"
4 
5 #include "../../../Common/IntToString.h"
6 
7 #include "../../../Windows/ErrorMsg.h"
8 #include "../../../Windows/FileName.h"
9 
10 #ifndef Z7_ST
11 #include "../../../Windows/Synchronization.h"
12 #endif
13 
14 // #include "../Common/PropIDUtils.h"
15 
16 #include "ConsoleClose.h"
17 #include "UserInputUtils.h"
18 #include "UpdateCallbackConsole.h"
19 
20 using namespace NWindows;
21 
22 #ifndef Z7_ST
23 static NSynchronization::CCriticalSection g_CriticalSection;
24 #define MT_LOCK NSynchronization::CCriticalSectionLock lock(g_CriticalSection);
25 #else
26 #define MT_LOCK
27 #endif
28 
29 static const wchar_t * const kEmptyFileAlias = L"[Content]";
30 
31 static const char * const kOpenArchiveMessage = "Open archive: ";
32 static const char * const kCreatingArchiveMessage = "Creating archive: ";
33 static const char * const kUpdatingArchiveMessage = "Updating archive: ";
34 static const char * const kScanningMessage = "Scanning the drive:";
35 
36 static const char * const kError = "ERROR: ";
37 static const char * const kWarning = "WARNING: ";
38 
CheckBreak2()39 static HRESULT CheckBreak2()
40 {
41   return NConsoleClose::TestBreakSignal() ? E_ABORT : S_OK;
42 }
43 
44 HRESULT Print_OpenArchive_Props(CStdOutStream &so, const CCodecs *codecs, const CArchiveLink &arcLink);
45 HRESULT Print_OpenArchive_Error(CStdOutStream &so, const CCodecs *codecs, const CArchiveLink &arcLink);
46 
47 void PrintErrorFlags(CStdOutStream &so, const char *s, UInt32 errorFlags);
48 
49 void Print_ErrorFormatIndex_Warning(CStdOutStream *_so, const CCodecs *codecs, const CArc &arc);
50 
OpenResult(const CCodecs * codecs,const CArchiveLink & arcLink,const wchar_t * name,HRESULT result)51 HRESULT CUpdateCallbackConsole::OpenResult(
52     const CCodecs *codecs, const CArchiveLink &arcLink,
53     const wchar_t *name, HRESULT result)
54 {
55   ClosePercents2();
56 
57   FOR_VECTOR (level, arcLink.Arcs)
58   {
59     const CArc &arc = arcLink.Arcs[level];
60     const CArcErrorInfo &er = arc.ErrorInfo;
61 
62     UInt32 errorFlags = er.GetErrorFlags();
63 
64     if (errorFlags != 0 || !er.ErrorMessage.IsEmpty())
65     {
66       if (_se)
67       {
68         *_se << endl;
69         if (level != 0)
70           *_se << arc.Path << endl;
71       }
72 
73       if (errorFlags != 0)
74       {
75         if (_se)
76           PrintErrorFlags(*_se, "ERRORS:", errorFlags);
77       }
78 
79       if (!er.ErrorMessage.IsEmpty())
80       {
81         if (_se)
82           *_se << "ERRORS:" << endl << er.ErrorMessage << endl;
83       }
84 
85       if (_se)
86       {
87         *_se << endl;
88         _se->Flush();
89       }
90     }
91 
92     UInt32 warningFlags = er.GetWarningFlags();
93 
94     if (warningFlags != 0 || !er.WarningMessage.IsEmpty())
95     {
96       if (_so)
97       {
98         *_so << endl;
99         if (level != 0)
100           *_so << arc.Path << endl;
101       }
102 
103       if (warningFlags != 0)
104       {
105         if (_so)
106           PrintErrorFlags(*_so, "WARNINGS:", warningFlags);
107       }
108 
109       if (!er.WarningMessage.IsEmpty())
110       {
111         if (_so)
112           *_so << "WARNINGS:" << endl << er.WarningMessage << endl;
113       }
114 
115       if (_so)
116       {
117         *_so << endl;
118         if (NeedFlush)
119           _so->Flush();
120       }
121     }
122 
123 
124     if (er.ErrorFormatIndex >= 0)
125     {
126       if (_so)
127       {
128         Print_ErrorFormatIndex_Warning(_so, codecs, arc);
129         if (NeedFlush)
130           _so->Flush();
131       }
132     }
133   }
134 
135   if (result == S_OK)
136   {
137     if (_so)
138     {
139       RINOK(Print_OpenArchive_Props(*_so, codecs, arcLink))
140       *_so << endl;
141     }
142   }
143   else
144   {
145     if (_so)
146       _so->Flush();
147     if (_se)
148     {
149       *_se << kError;
150       _se->NormalizePrint_wstr_Path(name);
151       *_se << endl;
152       HRESULT res = Print_OpenArchive_Error(*_se, codecs, arcLink);
153       RINOK(res)
154       _se->Flush();
155     }
156   }
157 
158   return S_OK;
159 }
160 
StartScanning()161 HRESULT CUpdateCallbackConsole::StartScanning()
162 {
163   if (_so)
164     *_so << kScanningMessage << endl;
165   _percent.Command = "Scan ";
166   return S_OK;
167 }
168 
ScanProgress(const CDirItemsStat & st,const FString & path,bool)169 HRESULT CUpdateCallbackConsole::ScanProgress(const CDirItemsStat &st, const FString &path, bool /* isDir */)
170 {
171   if (NeedPercents())
172   {
173     _percent.Files = st.NumDirs + st.NumFiles + st.NumAltStreams;
174     _percent.Completed = st.GetTotalBytes();
175     _percent.FileName = fs2us(path);
176     _percent.Print();
177   }
178 
179   return CheckBreak();
180 }
181 
CommonError(const FString & path,DWORD systemError,bool isWarning)182 void CCallbackConsoleBase::CommonError(const FString &path, DWORD systemError, bool isWarning)
183 {
184   ClosePercents2();
185 
186   if (_se)
187   {
188     if (_so)
189       _so->Flush();
190 
191     *_se << endl << (isWarning ? kWarning : kError)
192         << NError::MyFormatMessage(systemError)
193         << endl;
194     _se->NormalizePrint_UString_Path(fs2us(path));
195     *_se << endl << endl;
196     _se->Flush();
197   }
198 }
199 
200 /*
201 void CCallbackConsoleBase::CommonError(const char *message)
202 {
203   ClosePercents2();
204 
205   if (_se)
206   {
207     if (_so)
208       _so->Flush();
209 
210     *_se << endl << kError << message << endl;
211     _se->Flush();
212   }
213 }
214 */
215 
216 
ScanError_Base(const FString & path,DWORD systemError)217 HRESULT CCallbackConsoleBase::ScanError_Base(const FString &path, DWORD systemError)
218 {
219   MT_LOCK
220 
221   ScanErrors.AddError(path, systemError);
222   CommonError(path, systemError, true);
223 
224   return S_OK;
225 }
226 
OpenFileError_Base(const FString & path,DWORD systemError)227 HRESULT CCallbackConsoleBase::OpenFileError_Base(const FString &path, DWORD systemError)
228 {
229   MT_LOCK
230   FailedFiles.AddError(path, systemError);
231   NumNonOpenFiles++;
232   /*
233   if (systemError == ERROR_SHARING_VIOLATION)
234   {
235   */
236     CommonError(path, systemError, true);
237     return S_FALSE;
238   /*
239   }
240   return systemError;
241   */
242 }
243 
ReadingFileError_Base(const FString & path,DWORD systemError)244 HRESULT CCallbackConsoleBase::ReadingFileError_Base(const FString &path, DWORD systemError)
245 {
246   MT_LOCK
247   CommonError(path, systemError, false);
248   return HRESULT_FROM_WIN32(systemError);
249 }
250 
ScanError(const FString & path,DWORD systemError)251 HRESULT CUpdateCallbackConsole::ScanError(const FString &path, DWORD systemError)
252 {
253   return ScanError_Base(path, systemError);
254 }
255 
256 
PrintPropPair(AString & s,const char * name,UInt64 val)257 static void PrintPropPair(AString &s, const char *name, UInt64 val)
258 {
259   char temp[32];
260   ConvertUInt64ToString(val, temp);
261   s += name;
262   s += ": ";
263   s += temp;
264 }
265 
266 void PrintSize_bytes_Smart(AString &s, UInt64 val);
267 void Print_DirItemsStat(AString &s, const CDirItemsStat &st);
268 void Print_DirItemsStat2(AString &s, const CDirItemsStat2 &st);
269 
FinishScanning(const CDirItemsStat & st)270 HRESULT CUpdateCallbackConsole::FinishScanning(const CDirItemsStat &st)
271 {
272   if (NeedPercents())
273   {
274     _percent.ClosePrint(true);
275     _percent.ClearCurState();
276   }
277 
278   if (_so)
279   {
280     AString s;
281     Print_DirItemsStat(s, st);
282     *_so << s << endl << endl;
283   }
284   return S_OK;
285 }
286 
287 static const char * const k_StdOut_ArcName = "StdOut";
288 
StartOpenArchive(const wchar_t * name)289 HRESULT CUpdateCallbackConsole::StartOpenArchive(const wchar_t *name)
290 {
291   if (_so)
292   {
293     *_so << kOpenArchiveMessage;
294     if (name)
295       *_so << name;
296     else
297       *_so << k_StdOut_ArcName;
298     *_so << endl;
299   }
300   return S_OK;
301 }
302 
StartArchive(const wchar_t * name,bool updating)303 HRESULT CUpdateCallbackConsole::StartArchive(const wchar_t *name, bool updating)
304 {
305   if (NeedPercents())
306     _percent.ClosePrint(true);
307 
308   _percent.ClearCurState();
309   NumNonOpenFiles = 0;
310 
311   if (_so)
312   {
313     *_so << (updating ? kUpdatingArchiveMessage : kCreatingArchiveMessage);
314     if (name)
315       _so->NormalizePrint_wstr_Path(name);
316     else
317       *_so << k_StdOut_ArcName;
318    *_so << endl << endl;
319   }
320   return S_OK;
321 }
322 
FinishArchive(const CFinishArchiveStat & st)323 HRESULT CUpdateCallbackConsole::FinishArchive(const CFinishArchiveStat &st)
324 {
325   ClosePercents2();
326 
327   if (_so)
328   {
329     AString s;
330     // Print_UInt64_and_String(s, _percent.Files == 1 ? "file" : "files", _percent.Files);
331     PrintPropPair(s, "Files read from disk", _percent.Files - NumNonOpenFiles);
332     s.Add_LF();
333     s += "Archive size: ";
334     PrintSize_bytes_Smart(s, st.OutArcFileSize);
335     s.Add_LF();
336     if (st.IsMultiVolMode)
337     {
338       s += "Volumes: ";
339       s.Add_UInt32(st.NumVolumes);
340       s.Add_LF();
341     }
342     *_so << endl;
343     *_so << s;
344     // *_so << endl;
345   }
346 
347   return S_OK;
348 }
349 
WriteSfx(const wchar_t * name,UInt64 size)350 HRESULT CUpdateCallbackConsole::WriteSfx(const wchar_t *name, UInt64 size)
351 {
352   if (_so)
353   {
354     *_so << "Write SFX: ";
355     *_so << name;
356     AString s (" : ");
357     PrintSize_bytes_Smart(s, size);
358     *_so << s << endl;
359   }
360   return S_OK;
361 }
362 
363 
364 
MoveArc_UpdateStatus()365 HRESULT CUpdateCallbackConsole::MoveArc_UpdateStatus()
366 {
367   if (NeedPercents())
368   {
369     AString &s = _percent.Command;
370     s = " : ";
371     s.Add_UInt64(_arcMoving_percents);
372     s.Add_Char('%');
373     const bool totalDefined = (_arcMoving_total != 0 && _arcMoving_total != (UInt64)(Int64)-1);
374     if (_arcMoving_current != 0 || totalDefined)
375     {
376       s += " : ";
377       s.Add_UInt64(_arcMoving_current >> 20);
378       s += " MiB";
379     }
380     if (totalDefined)
381     {
382       s += " / ";
383       s.Add_UInt64((_arcMoving_total + ((1 << 20) - 1)) >> 20);
384       s += " MiB";
385     }
386     s += " : temporary archive moving ...";
387     _percent.Print();
388   }
389 
390   // we ignore single Ctrl-C, if (_arcMoving_updateMode) mode
391   // because we want to get good final archive instead of temp archive.
392   if (NConsoleClose::g_BreakCounter == 1 && _arcMoving_updateMode)
393     return S_OK;
394   return CheckBreak();
395 }
396 
397 
MoveArc_Start(const wchar_t * srcTempPath,const wchar_t * destFinalPath,UInt64 size,Int32 updateMode)398 HRESULT CUpdateCallbackConsole::MoveArc_Start(
399     const wchar_t *srcTempPath, const wchar_t *destFinalPath,
400     UInt64 size, Int32 updateMode)
401 {
402 #if 0 // 1 : for debug
403   if (LogLevel > 0 && _so)
404   {
405     ClosePercents_for_so();
406     *_so << "Temporary archive moving:" << endl;
407     _tempU = srcTempPath;
408     _so->Normalize_UString_Path(_tempU);
409     _so->PrintUString(_tempU, _tempA);
410     *_so << endl;
411     _tempU = destFinalPath;
412     _so->Normalize_UString_Path(_tempU);
413     _so->PrintUString(_tempU, _tempA);
414     *_so << endl;
415   }
416 #else
417   UNUSED_VAR(srcTempPath)
418   UNUSED_VAR(destFinalPath)
419 #endif
420 
421   _arcMoving_updateMode = updateMode;
422   _arcMoving_total = size;
423   _arcMoving_current = 0;
424   _arcMoving_percents = 0;
425   return MoveArc_UpdateStatus();
426 }
427 
428 
MoveArc_Progress(UInt64 totalSize,UInt64 currentSize)429 HRESULT CUpdateCallbackConsole::MoveArc_Progress(UInt64 totalSize, UInt64 currentSize)
430 {
431 #if 0 // 1 : for debug
432   if (_so)
433   {
434     ClosePercents_for_so();
435     *_so << totalSize << " : " << currentSize << endl;
436   }
437 #endif
438 
439   UInt64 percents = 0;
440   if (totalSize != 0)
441   {
442     if (totalSize < ((UInt64)1 << 57))
443       percents = currentSize * 100 / totalSize;
444     else
445       percents = currentSize / (totalSize / 100);
446   }
447 
448 #ifdef _WIN32
449   // Sleep(300); // for debug
450 #endif
451   // totalSize = (UInt64)(Int64)-1; // for debug
452 
453   if (percents == _arcMoving_percents)
454     return CheckBreak();
455   _arcMoving_current = currentSize;
456   _arcMoving_total = totalSize;
457   _arcMoving_percents = percents;
458   return MoveArc_UpdateStatus();
459 }
460 
461 
MoveArc_Finish()462 HRESULT CUpdateCallbackConsole::MoveArc_Finish()
463 {
464   // _arcMoving_percents = 0;
465   if (NeedPercents())
466   {
467     _percent.Command.Empty();
468     _percent.Print();
469   }
470   // it can return delayed user break (E_ABORT) status,
471   // if it ignored single CTRL+C in MoveArc_Progress().
472   return CheckBreak();
473 }
474 
475 
476 
DeletingAfterArchiving(const FString & path,bool)477 HRESULT CUpdateCallbackConsole::DeletingAfterArchiving(const FString &path, bool /* isDir */)
478 {
479   if (LogLevel > 0 && _so)
480   {
481     ClosePercents_for_so();
482 
483     if (!DeleteMessageWasShown)
484     {
485       if (_so)
486         *_so << endl << ": Removing files after including to archive" << endl;
487     }
488 
489     {
490       {
491         _tempA = "Removing";
492         _tempA.Add_Space();
493         *_so << _tempA;
494         _tempU = fs2us(path);
495         _so->Normalize_UString_Path(_tempU);
496         _so->PrintUString(_tempU, _tempA);
497         *_so << endl;
498         if (NeedFlush)
499           _so->Flush();
500       }
501     }
502   }
503 
504   if (!DeleteMessageWasShown)
505   {
506     if (NeedPercents())
507     {
508       _percent.ClearCurState();
509     }
510     DeleteMessageWasShown = true;
511   }
512   else
513   {
514     _percent.Files++;
515   }
516 
517   if (NeedPercents())
518   {
519     // if (!FullLog)
520     {
521       _percent.Command = "Removing";
522       _percent.FileName = fs2us(path);
523     }
524     _percent.Print();
525   }
526 
527   return S_OK;
528 }
529 
530 
FinishDeletingAfterArchiving()531 HRESULT CUpdateCallbackConsole::FinishDeletingAfterArchiving()
532 {
533   ClosePercents2();
534   if (_so && DeleteMessageWasShown)
535     *_so << endl;
536   return S_OK;
537 }
538 
CheckBreak()539 HRESULT CUpdateCallbackConsole::CheckBreak()
540 {
541   return CheckBreak2();
542 }
543 
544 /*
545 HRESULT CUpdateCallbackConsole::Finalize()
546 {
547   // MT_LOCK
548   return S_OK;
549 }
550 */
551 
552 
PrintToDoStat(CStdOutStream * _so,const CDirItemsStat2 & stat,const char * name)553 void static PrintToDoStat(CStdOutStream *_so, const CDirItemsStat2 &stat, const char *name)
554 {
555   AString s;
556   Print_DirItemsStat2(s, stat);
557   *_so << name << ": " << s << endl;
558 }
559 
SetNumItems(const CArcToDoStat & stat)560 HRESULT CUpdateCallbackConsole::SetNumItems(const CArcToDoStat &stat)
561 {
562   if (_so)
563   {
564     ClosePercents_for_so();
565     if (!stat.DeleteData.IsEmpty())
566     {
567       *_so << endl;
568       PrintToDoStat(_so, stat.DeleteData, "Delete data from archive");
569     }
570     if (!stat.OldData.IsEmpty())
571       PrintToDoStat(_so, stat.OldData, "Keep old data in archive");
572     // if (!stat.NewData.IsEmpty())
573     {
574       PrintToDoStat(_so, stat.NewData, "Add new data to archive");
575     }
576     *_so << endl;
577   }
578   return S_OK;
579 }
580 
SetTotal(UInt64 size)581 HRESULT CUpdateCallbackConsole::SetTotal(UInt64 size)
582 {
583   MT_LOCK
584   if (NeedPercents())
585   {
586     _percent.Total = size;
587     _percent.Print();
588   }
589   return S_OK;
590 }
591 
SetCompleted(const UInt64 * completeValue)592 HRESULT CUpdateCallbackConsole::SetCompleted(const UInt64 *completeValue)
593 {
594   MT_LOCK
595   if (completeValue)
596   {
597     if (NeedPercents())
598     {
599       _percent.Completed = *completeValue;
600       _percent.Print();
601     }
602   }
603   return CheckBreak2();
604 }
605 
SetRatioInfo(const UInt64 *,const UInt64 *)606 HRESULT CUpdateCallbackConsole::SetRatioInfo(const UInt64 * /* inSize */, const UInt64 * /* outSize */)
607 {
608   return CheckBreak2();
609 }
610 
PrintProgress(const wchar_t * name,bool isDir,const char * command,bool showInLog)611 HRESULT CCallbackConsoleBase::PrintProgress(const wchar_t *name, bool isDir, const char *command, bool showInLog)
612 {
613   MT_LOCK
614 
615   bool show2 = (showInLog && _so);
616 
617   if (show2)
618   {
619     ClosePercents_for_so();
620 
621     _tempA = command;
622     if (name)
623       _tempA.Add_Space();
624     *_so << _tempA;
625 
626     _tempU.Empty();
627     if (name)
628     {
629       _tempU = name;
630       if (isDir)
631         NWindows::NFile::NName::NormalizeDirPathPrefix(_tempU);
632       _so->Normalize_UString_Path(_tempU);
633     }
634     _so->PrintUString(_tempU, _tempA);
635     *_so << endl;
636     if (NeedFlush)
637       _so->Flush();
638   }
639 
640   if (NeedPercents())
641   {
642     if (PercentsNameLevel >= 1)
643     {
644       _percent.FileName.Empty();
645       _percent.Command.Empty();
646       if (PercentsNameLevel > 1 || !show2)
647       {
648         _percent.Command = command;
649         if (name)
650           _percent.FileName = name;
651       }
652     }
653     _percent.Print();
654   }
655 
656   return CheckBreak2();
657 }
658 
659 
660 /*
661 void CCallbackConsoleBase::PrintInfoLine(const UString &s)
662 {
663   if (LogLevel < 1000)
664     return;
665 
666   MT_LOCK
667 
668   const bool show2 = (_so != NULL);
669 
670   if (show2)
671   {
672     ClosePercents_for_so();
673     _so->PrintUString(s, _tempA);
674     *_so << endl;
675     if (NeedFlush)
676       _so->Flush();
677   }
678 }
679 */
680 
GetStream(const wchar_t * name,bool isDir,bool isAnti,UInt32 mode)681 HRESULT CUpdateCallbackConsole::GetStream(const wchar_t *name, bool isDir, bool isAnti, UInt32 mode)
682 {
683   if (StdOutMode)
684     return S_OK;
685 
686   if (!name || name[0] == 0)
687     name = kEmptyFileAlias;
688 
689   unsigned requiredLevel = 1;
690 
691   const char *s;
692   if (mode == NUpdateNotifyOp::kAdd ||
693       mode == NUpdateNotifyOp::kUpdate)
694   {
695     if (isAnti)
696       s = "Anti";
697     else if (mode == NUpdateNotifyOp::kAdd)
698       s = "+";
699     else
700       s = "U";
701   }
702   else
703   {
704     requiredLevel = 3;
705     if (mode == NUpdateNotifyOp::kAnalyze)
706       s = "A";
707     else
708       s = "Reading";
709   }
710 
711   return PrintProgress(name, isDir, s, LogLevel >= requiredLevel);
712 }
713 
OpenFileError(const FString & path,DWORD systemError)714 HRESULT CUpdateCallbackConsole::OpenFileError(const FString &path, DWORD systemError)
715 {
716   return OpenFileError_Base(path, systemError);
717 }
718 
ReadingFileError(const FString & path,DWORD systemError)719 HRESULT CUpdateCallbackConsole::ReadingFileError(const FString &path, DWORD systemError)
720 {
721   return ReadingFileError_Base(path, systemError);
722 }
723 
SetOperationResult(Int32)724 HRESULT CUpdateCallbackConsole::SetOperationResult(Int32 /* opRes */)
725 {
726   MT_LOCK
727   _percent.Files++;
728   /*
729   if (opRes != NArchive::NUpdate::NOperationResult::kOK)
730   {
731     if (opRes == NArchive::NUpdate::NOperationResult::kError_FileChanged)
732     {
733       CommonError("Input file changed");
734     }
735   }
736   */
737   return S_OK;
738 }
739 
740 void SetExtractErrorMessage(Int32 opRes, Int32 encrypted, AString &dest);
741 
ReportExtractResult(Int32 opRes,Int32 isEncrypted,const wchar_t * name)742 HRESULT CUpdateCallbackConsole::ReportExtractResult(Int32 opRes, Int32 isEncrypted, const wchar_t *name)
743 {
744   // if (StdOutMode) return S_OK;
745 
746   if (opRes != NArchive::NExtract::NOperationResult::kOK)
747   {
748     ClosePercents2();
749 
750     if (_se)
751     {
752       if (_so)
753         _so->Flush();
754 
755       AString s;
756       SetExtractErrorMessage(opRes, isEncrypted, s);
757       *_se << s << " : " << endl;
758       _se->NormalizePrint_wstr_Path(name);
759       *_se << endl << endl;
760       _se->Flush();
761     }
762     return S_OK;
763   }
764   return S_OK;
765 }
766 
767 
ReportUpdateOperation(UInt32 op,const wchar_t * name,bool isDir)768 HRESULT CUpdateCallbackConsole::ReportUpdateOperation(UInt32 op, const wchar_t *name, bool isDir)
769 {
770   // if (StdOutMode) return S_OK;
771 
772   char temp[16];
773   const char *s;
774 
775   unsigned requiredLevel = 1;
776 
777   switch (op)
778   {
779     case NUpdateNotifyOp::kAdd:       s = "+"; break;
780     case NUpdateNotifyOp::kUpdate:    s = "U"; break;
781     case NUpdateNotifyOp::kAnalyze:   s = "A"; requiredLevel = 3; break;
782     case NUpdateNotifyOp::kReplicate: s = "="; requiredLevel = 3; break;
783     case NUpdateNotifyOp::kRepack:    s = "R"; requiredLevel = 2; break;
784     case NUpdateNotifyOp::kSkip:      s = "."; requiredLevel = 2; break;
785     case NUpdateNotifyOp::kDelete:    s = "D"; requiredLevel = 3; break;
786     case NUpdateNotifyOp::kHeader:    s = "Header creation"; requiredLevel = 100; break;
787     case NUpdateNotifyOp::kInFileChanged: s = "Size of input file was changed:"; requiredLevel = 10; break;
788     // case NUpdateNotifyOp::kOpFinished:  s = "Finished"; requiredLevel = 100; break;
789     default:
790     {
791       temp[0] = 'o';
792       temp[1] = 'p';
793       ConvertUInt64ToString(op, temp + 2);
794       s = temp;
795     }
796   }
797 
798   return PrintProgress(name, isDir, s, LogLevel >= requiredLevel);
799 }
800 
801 /*
802 HRESULT CUpdateCallbackConsole::SetPassword(const UString &
803     #ifndef Z7_NO_CRYPTO
804     password
805     #endif
806     )
807 {
808   #ifndef Z7_NO_CRYPTO
809   PasswordIsDefined = true;
810   Password = password;
811   #endif
812   return S_OK;
813 }
814 */
815 
CryptoGetTextPassword2(Int32 * passwordIsDefined,BSTR * password)816 HRESULT CUpdateCallbackConsole::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password)
817 {
818   COM_TRY_BEGIN
819 
820   *password = NULL;
821 
822   #ifdef Z7_NO_CRYPTO
823 
824   *passwordIsDefined = false;
825   return S_OK;
826 
827   #else
828 
829   if (!PasswordIsDefined)
830   {
831     if (AskPassword)
832     {
833       RINOK(GetPassword_HRESULT(_so, Password))
834       PasswordIsDefined = true;
835     }
836   }
837   *passwordIsDefined = BoolToInt(PasswordIsDefined);
838   return StringToBstr(Password, password);
839 
840   #endif
841 
842   COM_TRY_END
843 }
844 
CryptoGetTextPassword(BSTR * password)845 HRESULT CUpdateCallbackConsole::CryptoGetTextPassword(BSTR *password)
846 {
847   COM_TRY_BEGIN
848 
849   *password = NULL;
850 
851   #ifdef Z7_NO_CRYPTO
852 
853   return E_NOTIMPL;
854 
855   #else
856 
857   if (!PasswordIsDefined)
858   {
859     {
860       RINOK(GetPassword_HRESULT(_so, Password))
861       PasswordIsDefined = true;
862     }
863   }
864   return StringToBstr(Password, password);
865 
866   #endif
867   COM_TRY_END
868 }
869 
ShowDeleteFile(const wchar_t * name,bool isDir)870 HRESULT CUpdateCallbackConsole::ShowDeleteFile(const wchar_t *name, bool isDir)
871 {
872   if (StdOutMode)
873     return S_OK;
874 
875   if (LogLevel > 7)
876   {
877     if (!name || name[0] == 0)
878       name = kEmptyFileAlias;
879     return PrintProgress(name, isDir, "D", true);
880   }
881   return S_OK;
882 }
883 
884 /*
885 void GetPropName(PROPID propID, const wchar_t *name, AString &nameA, UString &nameU);
886 
887 static void GetPropName(PROPID propID, UString &nameU)
888 {
889   AString nameA;
890   GetPropName(propID, NULL, nameA, nameU);
891   // if (!nameA.IsEmpty())
892     nameU = nameA;
893 }
894 
895 
896 static void AddPropNamePrefix(UString &s, PROPID propID)
897 {
898   UString name;
899   GetPropName(propID, name);
900   s += name;
901   s += " = ";
902 }
903 
904 void CCallbackConsoleBase::PrintPropInfo(UString &s, PROPID propID, const PROPVARIANT *value)
905 {
906   AddPropNamePrefix(s, propID);
907   {
908     UString dest;
909     const int level = 9; // we show up to ns precision level
910     ConvertPropertyToString2(dest, *value, propID, level);
911     s += dest;
912   }
913   PrintInfoLine(s);
914 }
915 
916 static void Add_IndexType_Index(UString &s, UInt32 indexType, UInt32 index)
917 {
918   if (indexType == NArchive::NEventIndexType::kArcProp)
919   {
920   }
921   else
922   {
923     if (indexType == NArchive::NEventIndexType::kBlockIndex)
924     {
925       s += "#";
926     }
927     else if (indexType == NArchive::NEventIndexType::kOutArcIndex)
928     {
929     }
930     else
931     {
932       s += "indexType_";
933       s.Add_UInt32(indexType);
934       s.Add_Space();
935     }
936     s.Add_UInt32(index);
937   }
938   s += ": ";
939 }
940 
941 HRESULT CUpdateCallbackConsole::ReportProp(UInt32 indexType, UInt32 index, PROPID propID, const PROPVARIANT *value)
942 {
943   UString s;
944   Add_IndexType_Index(s, indexType, index);
945   PrintPropInfo(s, propID, value);
946   return S_OK;
947 }
948 
949 static inline char GetHex(Byte value)
950 {
951   return (char)((value < 10) ? ('0' + value) : ('a' + (value - 10)));
952 }
953 
954 static void AddHexToString(UString &dest, const Byte *data, UInt32 size)
955 {
956   for (UInt32 i = 0; i < size; i++)
957   {
958     Byte b = data[i];
959     dest += GetHex((Byte)((b >> 4) & 0xF));
960     dest += GetHex((Byte)(b & 0xF));
961   }
962 }
963 
964 void HashHexToString(char *dest, const Byte *data, UInt32 size);
965 
966 HRESULT CUpdateCallbackConsole::ReportRawProp(UInt32 indexType, UInt32 index,
967     PROPID propID, const void *data, UInt32 dataSize, UInt32 propType)
968 {
969   UString s;
970   propType = propType;
971   Add_IndexType_Index(s, indexType, index);
972   AddPropNamePrefix(s, propID);
973   if (propID == kpidChecksum)
974   {
975     char temp[k_HashCalc_DigestSize_Max + 8];
976     HashHexToString(temp, (const Byte *)data, dataSize);
977     s += temp;
978   }
979   else
980     AddHexToString(s, (const Byte *)data, dataSize);
981   PrintInfoLine(s);
982   return S_OK;
983 }
984 
985 HRESULT CUpdateCallbackConsole::ReportFinished(UInt32 indexType, UInt32 index, Int32 opRes)
986 {
987   UString s;
988   Add_IndexType_Index(s, indexType, index);
989   s += "finished";
990   if (opRes != NArchive::NUpdate::NOperationResult::kOK)
991   {
992     s += ": ";
993     s.Add_UInt32(opRes);
994   }
995   PrintInfoLine(s);
996   return S_OK;
997 }
998 */
999