1 // UpdateCallbackConsole.cpp
5 #include "UpdateCallbackConsole.h"
7 #include "Windows/Error.h"
9 #include "Windows/Synchronization.h"
12 #include "ConsoleClose.h"
13 #include "UserInputUtils.h"
15 using namespace NWindows;
18 static NSynchronization::CCriticalSection g_CriticalSection;
19 #define MT_LOCK NSynchronization::CCriticalSectionLock lock(g_CriticalSection);
24 static const wchar_t *kEmptyFileAlias = L"[Content]";
26 static const char *kCreatingArchiveMessage = "Creating archive ";
27 static const char *kUpdatingArchiveMessage = "Updating archive ";
28 static const char *kScanningMessage = "Scanning";
31 HRESULT CUpdateCallbackConsole::OpenResult(const wchar_t *name, HRESULT result)
35 (*OutStream) << "Error: " << name << " is not supported archive" << endl;
39 HRESULT CUpdateCallbackConsole::StartScanning()
41 (*OutStream) << kScanningMessage;
45 HRESULT CUpdateCallbackConsole::CanNotFindError(const wchar_t *name, DWORD systemError)
47 CantFindFiles.Add(name);
48 CantFindCodes.Add(systemError);
49 // m_PercentPrinter.ClosePrint();
52 (*OutStream) << endl << endl;
53 m_PercentPrinter.PrintNewLine();
54 m_WarningsMode = true;
56 m_PercentPrinter.PrintString(name);
57 m_PercentPrinter.PrintString(": WARNING: ");
58 m_PercentPrinter.PrintString(NError::MyFormatMessageW(systemError));
59 m_PercentPrinter.PrintNewLine();
63 HRESULT CUpdateCallbackConsole::FinishScanning()
65 (*OutStream) << endl << endl;
69 HRESULT CUpdateCallbackConsole::StartArchive(const wchar_t *name, bool updating)
72 (*OutStream) << kUpdatingArchiveMessage;
74 (*OutStream) << kCreatingArchiveMessage;
78 (*OutStream) << "StdOut";
79 (*OutStream) << endl << endl;
83 HRESULT CUpdateCallbackConsole::FinishArchive()
89 HRESULT CUpdateCallbackConsole::CheckBreak()
91 if (NConsoleClose::TestBreakSignal())
96 HRESULT CUpdateCallbackConsole::Finilize()
103 m_PercentPrinter.ClosePrint();
105 if (!StdOutMode && m_NeedNewLine)
107 m_PercentPrinter.PrintNewLine();
108 m_NeedNewLine = false;
110 m_NeedBeClosed = false;
115 HRESULT CUpdateCallbackConsole::SetNumFiles(UInt64 /* numFiles */)
120 HRESULT CUpdateCallbackConsole::SetTotal(UInt64 size)
124 m_PercentPrinter.SetTotal(size);
128 HRESULT CUpdateCallbackConsole::SetCompleted(const UInt64 *completeValue)
131 if (completeValue != NULL)
135 m_PercentPrinter.SetRatio(*completeValue);
136 m_PercentPrinter.PrintRatio();
137 m_NeedBeClosed = true;
140 if (NConsoleClose::TestBreakSignal())
145 HRESULT CUpdateCallbackConsole::SetRatioInfo(const UInt64 * /* inSize */, const UInt64 * /* outSize */)
148 if (NConsoleClose::TestBreakSignal())
154 HRESULT CUpdateCallbackConsole::GetStream(const wchar_t *name, bool isAnti)
160 m_PercentPrinter.PrintString("Anti item ");
162 m_PercentPrinter.PrintString("Compressing ");
164 name = kEmptyFileAlias;
165 m_PercentPrinter.PrintString(name);
167 m_PercentPrinter.RePrintRatio();
171 HRESULT CUpdateCallbackConsole::OpenFileError(const wchar_t *name, DWORD systemError)
174 FailedCodes.Add(systemError);
175 FailedFiles.Add(name);
176 // if (systemError == ERROR_SHARING_VIOLATION)
178 m_PercentPrinter.ClosePrint();
179 m_PercentPrinter.PrintNewLine();
180 m_PercentPrinter.PrintString("WARNING: ");
181 m_PercentPrinter.PrintString(NError::MyFormatMessageW(systemError));
184 // return systemError;
187 HRESULT CUpdateCallbackConsole::SetOperationResult(Int32 )
189 m_NeedBeClosed = true;
190 m_NeedNewLine = true;
194 HRESULT CUpdateCallbackConsole::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password)
196 if (!PasswordIsDefined)
200 Password = GetPassword(OutStream);
201 PasswordIsDefined = true;
204 *passwordIsDefined = BoolToInt(PasswordIsDefined);
205 CMyComBSTR tempName(Password);
206 *password = tempName.Detach();