xref: /aosp_15_r20/external/lzma/CPP/7zip/UI/Console/UpdateCallbackConsole.h (revision f6dc9357d832569d4d1f5d24eacdb3935a1ae8e6)
1 // UpdateCallbackConsole.h
2 
3 #ifndef ZIP7_INC_UPDATE_CALLBACK_CONSOLE_H
4 #define ZIP7_INC_UPDATE_CALLBACK_CONSOLE_H
5 
6 #include "../../../Common/StdOutStream.h"
7 
8 #include "../Common/Update.h"
9 
10 #include "PercentPrinter.h"
11 
12 struct CErrorPathCodes
13 {
14   FStringVector Paths;
15   CRecordVector<DWORD> Codes;
16 
AddErrorCErrorPathCodes17   void AddError(const FString &path, DWORD systemError)
18   {
19     Paths.Add(path);
20     Codes.Add(systemError);
21   }
ClearCErrorPathCodes22   void Clear()
23   {
24     Paths.Clear();
25     Codes.Clear();
26   }
27 };
28 
29 
30 class CCallbackConsoleBase
31 {
32   void CommonError(const FString &path, DWORD systemError, bool isWarning);
33 
34 protected:
35   CStdOutStream *_so;
36   CStdOutStream *_se;
37 
38   HRESULT ScanError_Base(const FString &path, DWORD systemError);
39   HRESULT OpenFileError_Base(const FString &name, DWORD systemError);
40   HRESULT ReadingFileError_Base(const FString &name, DWORD systemError);
41 
42 public:
43   bool StdOutMode;
44   bool NeedFlush;
45   unsigned PercentsNameLevel;
46   unsigned LogLevel;
47 
48 protected:
49   AString _tempA;
50   UString _tempU;
51   CPercentPrinter _percent;
52 
53 public:
54   CErrorPathCodes FailedFiles;
55   CErrorPathCodes ScanErrors;
56   UInt64 NumNonOpenFiles;
57 
CCallbackConsoleBase()58   CCallbackConsoleBase():
59       StdOutMode(false),
60       NeedFlush(false),
61       PercentsNameLevel(1),
62       LogLevel(0),
63       NumNonOpenFiles(0)
64       {}
65 
NeedPercents()66   bool NeedPercents() const { return _percent._so != NULL; }
SetWindowWidth(unsigned width)67   void SetWindowWidth(unsigned width) { _percent.MaxLen = width - 1; }
68 
Init(CStdOutStream * outStream,CStdOutStream * errorStream,CStdOutStream * percentStream,bool disablePercents)69   void Init(
70       CStdOutStream *outStream,
71       CStdOutStream *errorStream,
72       CStdOutStream *percentStream,
73       bool disablePercents)
74   {
75     FailedFiles.Clear();
76 
77     _so = outStream;
78     _se = errorStream;
79     _percent._so = percentStream;
80     _percent.DisablePrint = disablePercents;
81   }
82 
ClosePercents2()83   void ClosePercents2()
84   {
85     if (NeedPercents())
86       _percent.ClosePrint(true);
87   }
88 
ClosePercents_for_so()89   void ClosePercents_for_so()
90   {
91     if (NeedPercents() && _so == _percent._so)
92       _percent.ClosePrint(false);
93   }
94 
95   HRESULT PrintProgress(const wchar_t *name, bool isDir, const char *command, bool showInLog);
96 
97   // void PrintInfoLine(const UString &s);
98   // void PrintPropInfo(UString &s, PROPID propID, const PROPVARIANT *value);
99 };
100 
101 
102 class CUpdateCallbackConsole Z7_final:
103   public IUpdateCallbackUI2,
104   public CCallbackConsoleBase
105 {
106   // void PrintPropPair(const char *name, const wchar_t *val);
107   Z7_IFACE_IMP(IUpdateCallbackUI)
108   Z7_IFACE_IMP(IDirItemsCallback)
109   Z7_IFACE_IMP(IUpdateCallbackUI2)
110 
111   HRESULT MoveArc_UpdateStatus();
112 
113   UInt64 _arcMoving_total;
114   UInt64 _arcMoving_current;
115   UInt64 _arcMoving_percents;
116   Int32  _arcMoving_updateMode;
117 
118 public:
119   bool DeleteMessageWasShown;
120 
121   #ifndef Z7_NO_CRYPTO
122   bool PasswordIsDefined;
123   bool AskPassword;
124   UString Password;
125   #endif
126 
CUpdateCallbackConsole()127   CUpdateCallbackConsole():
128         _arcMoving_total(0)
129       , _arcMoving_current(0)
130       , _arcMoving_percents(0)
131       , _arcMoving_updateMode(0)
132       , DeleteMessageWasShown(false)
133       #ifndef Z7_NO_CRYPTO
134       , PasswordIsDefined(false)
135       , AskPassword(false)
136       #endif
137       {}
138 
139   /*
140   void Init(CStdOutStream *outStream)
141   {
142     CCallbackConsoleBase::Init(outStream);
143   }
144   */
145   // ~CUpdateCallbackConsole() { if (NeedPercents()) _percent.ClosePrint(); }
146 };
147 
148 #endif
149