1370b324cSopenharmony_ci// ExtractCallbackConsole.cpp
2370b324cSopenharmony_ci
3370b324cSopenharmony_ci#include "StdAfx.h"
4370b324cSopenharmony_ci
5370b324cSopenharmony_ci#include "../../../Common/IntToString.h"
6370b324cSopenharmony_ci#include "../../../Common/Wildcard.h"
7370b324cSopenharmony_ci
8370b324cSopenharmony_ci#include "../../../Windows/FileDir.h"
9370b324cSopenharmony_ci#include "../../../Windows/FileFind.h"
10370b324cSopenharmony_ci#include "../../../Windows/TimeUtils.h"
11370b324cSopenharmony_ci#include "../../../Windows/ErrorMsg.h"
12370b324cSopenharmony_ci#include "../../../Windows/PropVariantConv.h"
13370b324cSopenharmony_ci
14370b324cSopenharmony_ci#ifndef Z7_ST
15370b324cSopenharmony_ci#include "../../../Windows/Synchronization.h"
16370b324cSopenharmony_ci#endif
17370b324cSopenharmony_ci
18370b324cSopenharmony_ci#include "../../Common/FilePathAutoRename.h"
19370b324cSopenharmony_ci
20370b324cSopenharmony_ci#include "../Common/ExtractingFilePath.h"
21370b324cSopenharmony_ci
22370b324cSopenharmony_ci#include "ConsoleClose.h"
23370b324cSopenharmony_ci#include "ExtractCallbackConsole.h"
24370b324cSopenharmony_ci#include "UserInputUtils.h"
25370b324cSopenharmony_ci
26370b324cSopenharmony_ciusing namespace NWindows;
27370b324cSopenharmony_ciusing namespace NFile;
28370b324cSopenharmony_ciusing namespace NDir;
29370b324cSopenharmony_ci
30370b324cSopenharmony_cistatic HRESULT CheckBreak2()
31370b324cSopenharmony_ci{
32370b324cSopenharmony_ci  return NConsoleClose::TestBreakSignal() ? E_ABORT : S_OK;
33370b324cSopenharmony_ci}
34370b324cSopenharmony_ci
35370b324cSopenharmony_cistatic const char * const kError = "ERROR: ";
36370b324cSopenharmony_ci
37370b324cSopenharmony_ci
38370b324cSopenharmony_civoid CExtractScanConsole::StartScanning()
39370b324cSopenharmony_ci{
40370b324cSopenharmony_ci  if (NeedPercents())
41370b324cSopenharmony_ci    _percent.Command = "Scan";
42370b324cSopenharmony_ci}
43370b324cSopenharmony_ci
44370b324cSopenharmony_ciHRESULT CExtractScanConsole::ScanProgress(const CDirItemsStat &st, const FString &path, bool /* isDir */)
45370b324cSopenharmony_ci{
46370b324cSopenharmony_ci  if (NeedPercents())
47370b324cSopenharmony_ci  {
48370b324cSopenharmony_ci    _percent.Files = st.NumDirs + st.NumFiles;
49370b324cSopenharmony_ci    _percent.Completed = st.GetTotalBytes();
50370b324cSopenharmony_ci    _percent.FileName = fs2us(path);
51370b324cSopenharmony_ci    _percent.Print();
52370b324cSopenharmony_ci  }
53370b324cSopenharmony_ci
54370b324cSopenharmony_ci  return CheckBreak2();
55370b324cSopenharmony_ci}
56370b324cSopenharmony_ci
57370b324cSopenharmony_ciHRESULT CExtractScanConsole::ScanError(const FString &path, DWORD systemError)
58370b324cSopenharmony_ci{
59370b324cSopenharmony_ci  // 22.00:
60370b324cSopenharmony_ci  // ScanErrors.AddError(path, systemError);
61370b324cSopenharmony_ci
62370b324cSopenharmony_ci  ClosePercentsAndFlush();
63370b324cSopenharmony_ci
64370b324cSopenharmony_ci  if (_se)
65370b324cSopenharmony_ci  {
66370b324cSopenharmony_ci    *_se << endl << kError << NError::MyFormatMessage(systemError) << endl;
67370b324cSopenharmony_ci    _se->NormalizePrint_UString(fs2us(path));
68370b324cSopenharmony_ci    *_se << endl << endl;
69370b324cSopenharmony_ci    _se->Flush();
70370b324cSopenharmony_ci  }
71370b324cSopenharmony_ci  return HRESULT_FROM_WIN32(systemError);
72370b324cSopenharmony_ci
73370b324cSopenharmony_ci  // 22.00: commented
74370b324cSopenharmony_ci  // CommonError(path, systemError, true);
75370b324cSopenharmony_ci  // return S_OK;
76370b324cSopenharmony_ci}
77370b324cSopenharmony_ci
78370b324cSopenharmony_ci
79370b324cSopenharmony_civoid Print_UInt64_and_String(AString &s, UInt64 val, const char *name);
80370b324cSopenharmony_civoid Print_UInt64_and_String(AString &s, UInt64 val, const char *name)
81370b324cSopenharmony_ci{
82370b324cSopenharmony_ci  char temp[32];
83370b324cSopenharmony_ci  ConvertUInt64ToString(val, temp);
84370b324cSopenharmony_ci  s += temp;
85370b324cSopenharmony_ci  s.Add_Space();
86370b324cSopenharmony_ci  s += name;
87370b324cSopenharmony_ci}
88370b324cSopenharmony_ci
89370b324cSopenharmony_civoid PrintSize_bytes_Smart(AString &s, UInt64 val);
90370b324cSopenharmony_civoid PrintSize_bytes_Smart(AString &s, UInt64 val)
91370b324cSopenharmony_ci{
92370b324cSopenharmony_ci  Print_UInt64_and_String(s, val, "bytes");
93370b324cSopenharmony_ci
94370b324cSopenharmony_ci  if (val == 0)
95370b324cSopenharmony_ci    return;
96370b324cSopenharmony_ci
97370b324cSopenharmony_ci  unsigned numBits = 10;
98370b324cSopenharmony_ci  char c = 'K';
99370b324cSopenharmony_ci  char temp[4] = { 'K', 'i', 'B', 0 };
100370b324cSopenharmony_ci       if (val >= ((UInt64)10 << 30)) { numBits = 30; c = 'G'; }
101370b324cSopenharmony_ci  else if (val >= ((UInt64)10 << 20)) { numBits = 20; c = 'M'; }
102370b324cSopenharmony_ci  temp[0] = c;
103370b324cSopenharmony_ci  s += " (";
104370b324cSopenharmony_ci  Print_UInt64_and_String(s, ((val + ((UInt64)1 << numBits) - 1) >> numBits), temp);
105370b324cSopenharmony_ci  s += ')';
106370b324cSopenharmony_ci}
107370b324cSopenharmony_ci
108370b324cSopenharmony_cistatic void PrintSize_bytes_Smart_comma(AString &s, UInt64 val)
109370b324cSopenharmony_ci{
110370b324cSopenharmony_ci  if (val == (UInt64)(Int64)-1)
111370b324cSopenharmony_ci    return;
112370b324cSopenharmony_ci  s += ", ";
113370b324cSopenharmony_ci  PrintSize_bytes_Smart(s, val);
114370b324cSopenharmony_ci}
115370b324cSopenharmony_ci
116370b324cSopenharmony_ci
117370b324cSopenharmony_ci
118370b324cSopenharmony_civoid Print_DirItemsStat(AString &s, const CDirItemsStat &st);
119370b324cSopenharmony_civoid Print_DirItemsStat(AString &s, const CDirItemsStat &st)
120370b324cSopenharmony_ci{
121370b324cSopenharmony_ci  if (st.NumDirs != 0)
122370b324cSopenharmony_ci  {
123370b324cSopenharmony_ci    Print_UInt64_and_String(s, st.NumDirs, st.NumDirs == 1 ? "folder" : "folders");
124370b324cSopenharmony_ci    s += ", ";
125370b324cSopenharmony_ci  }
126370b324cSopenharmony_ci  Print_UInt64_and_String(s, st.NumFiles, st.NumFiles == 1 ? "file" : "files");
127370b324cSopenharmony_ci  PrintSize_bytes_Smart_comma(s, st.FilesSize);
128370b324cSopenharmony_ci  if (st.NumAltStreams != 0)
129370b324cSopenharmony_ci  {
130370b324cSopenharmony_ci    s.Add_LF();
131370b324cSopenharmony_ci    Print_UInt64_and_String(s, st.NumAltStreams, "alternate streams");
132370b324cSopenharmony_ci    PrintSize_bytes_Smart_comma(s, st.AltStreamsSize);
133370b324cSopenharmony_ci  }
134370b324cSopenharmony_ci}
135370b324cSopenharmony_ci
136370b324cSopenharmony_ci
137370b324cSopenharmony_civoid Print_DirItemsStat2(AString &s, const CDirItemsStat2 &st);
138370b324cSopenharmony_civoid Print_DirItemsStat2(AString &s, const CDirItemsStat2 &st)
139370b324cSopenharmony_ci{
140370b324cSopenharmony_ci  Print_DirItemsStat(s, (CDirItemsStat &)st);
141370b324cSopenharmony_ci  bool needLF = true;
142370b324cSopenharmony_ci  if (st.Anti_NumDirs != 0)
143370b324cSopenharmony_ci  {
144370b324cSopenharmony_ci    if (needLF)
145370b324cSopenharmony_ci      s.Add_LF();
146370b324cSopenharmony_ci    needLF = false;
147370b324cSopenharmony_ci    Print_UInt64_and_String(s, st.Anti_NumDirs, st.Anti_NumDirs == 1 ? "anti-folder" : "anti-folders");
148370b324cSopenharmony_ci  }
149370b324cSopenharmony_ci  if (st.Anti_NumFiles != 0)
150370b324cSopenharmony_ci  {
151370b324cSopenharmony_ci    if (needLF)
152370b324cSopenharmony_ci      s.Add_LF();
153370b324cSopenharmony_ci    else
154370b324cSopenharmony_ci      s += ", ";
155370b324cSopenharmony_ci    needLF = false;
156370b324cSopenharmony_ci    Print_UInt64_and_String(s, st.Anti_NumFiles, st.Anti_NumFiles == 1 ? "anti-file" : "anti-files");
157370b324cSopenharmony_ci  }
158370b324cSopenharmony_ci  if (st.Anti_NumAltStreams != 0)
159370b324cSopenharmony_ci  {
160370b324cSopenharmony_ci    if (needLF)
161370b324cSopenharmony_ci      s.Add_LF();
162370b324cSopenharmony_ci    else
163370b324cSopenharmony_ci      s += ", ";
164370b324cSopenharmony_ci    needLF = false;
165370b324cSopenharmony_ci    Print_UInt64_and_String(s, st.Anti_NumAltStreams, "anti-alternate-streams");
166370b324cSopenharmony_ci  }
167370b324cSopenharmony_ci}
168370b324cSopenharmony_ci
169370b324cSopenharmony_ci
170370b324cSopenharmony_civoid CExtractScanConsole::PrintStat(const CDirItemsStat &st)
171370b324cSopenharmony_ci{
172370b324cSopenharmony_ci  if (_so)
173370b324cSopenharmony_ci  {
174370b324cSopenharmony_ci    AString s;
175370b324cSopenharmony_ci    Print_DirItemsStat(s, st);
176370b324cSopenharmony_ci    *_so << s << endl;
177370b324cSopenharmony_ci  }
178370b324cSopenharmony_ci}
179370b324cSopenharmony_ci
180370b324cSopenharmony_ci
181370b324cSopenharmony_ci
182370b324cSopenharmony_ci
183370b324cSopenharmony_ci
184370b324cSopenharmony_ci
185370b324cSopenharmony_ci
186370b324cSopenharmony_ci#ifndef Z7_ST
187370b324cSopenharmony_cistatic NSynchronization::CCriticalSection g_CriticalSection;
188370b324cSopenharmony_ci#define MT_LOCK NSynchronization::CCriticalSectionLock lock(g_CriticalSection);
189370b324cSopenharmony_ci#else
190370b324cSopenharmony_ci#define MT_LOCK
191370b324cSopenharmony_ci#endif
192370b324cSopenharmony_ci
193370b324cSopenharmony_ci
194370b324cSopenharmony_cistatic const char * const kTestString    =  "T";
195370b324cSopenharmony_cistatic const char * const kExtractString =  "-";
196370b324cSopenharmony_cistatic const char * const kSkipString    =  ".";
197370b324cSopenharmony_cistatic const char * const kReadString    =  "H";
198370b324cSopenharmony_ci
199370b324cSopenharmony_ci// static const char * const kCantAutoRename = "cannot create file with auto name\n";
200370b324cSopenharmony_ci// static const char * const kCantRenameFile = "cannot rename existing file\n";
201370b324cSopenharmony_ci// static const char * const kCantDeleteOutputFile = "cannot delete output file ";
202370b324cSopenharmony_ci
203370b324cSopenharmony_cistatic const char * const kMemoryExceptionMessage = "Can't allocate required memory!";
204370b324cSopenharmony_ci
205370b324cSopenharmony_cistatic const char * const kExtracting = "Extracting archive: ";
206370b324cSopenharmony_cistatic const char * const kTesting = "Testing archive: ";
207370b324cSopenharmony_ci
208370b324cSopenharmony_cistatic const char * const kEverythingIsOk = "Everything is Ok";
209370b324cSopenharmony_cistatic const char * const kNoFiles = "No files to process";
210370b324cSopenharmony_ci
211370b324cSopenharmony_cistatic const char * const kUnsupportedMethod = "Unsupported Method";
212370b324cSopenharmony_cistatic const char * const kCrcFailed = "CRC Failed";
213370b324cSopenharmony_cistatic const char * const kCrcFailedEncrypted = "CRC Failed in encrypted file. Wrong password?";
214370b324cSopenharmony_cistatic const char * const kDataError = "Data Error";
215370b324cSopenharmony_cistatic const char * const kDataErrorEncrypted = "Data Error in encrypted file. Wrong password?";
216370b324cSopenharmony_cistatic const char * const kUnavailableData = "Unavailable data";
217370b324cSopenharmony_cistatic const char * const kUnexpectedEnd = "Unexpected end of data";
218370b324cSopenharmony_cistatic const char * const kDataAfterEnd = "There are some data after the end of the payload data";
219370b324cSopenharmony_cistatic const char * const kIsNotArc = "Is not archive";
220370b324cSopenharmony_cistatic const char * const kHeadersError = "Headers Error";
221370b324cSopenharmony_cistatic const char * const kWrongPassword = "Wrong password";
222370b324cSopenharmony_ci
223370b324cSopenharmony_cistatic const char * const k_ErrorFlagsMessages[] =
224370b324cSopenharmony_ci{
225370b324cSopenharmony_ci    "Is not archive"
226370b324cSopenharmony_ci  , "Headers Error"
227370b324cSopenharmony_ci  , "Headers Error in encrypted archive. Wrong password?"
228370b324cSopenharmony_ci  , "Unavailable start of archive"
229370b324cSopenharmony_ci  , "Unconfirmed start of archive"
230370b324cSopenharmony_ci  , "Unexpected end of archive"
231370b324cSopenharmony_ci  , "There are data after the end of archive"
232370b324cSopenharmony_ci  , "Unsupported method"
233370b324cSopenharmony_ci  , "Unsupported feature"
234370b324cSopenharmony_ci  , "Data Error"
235370b324cSopenharmony_ci  , "CRC Error"
236370b324cSopenharmony_ci};
237370b324cSopenharmony_ci
238370b324cSopenharmony_ciZ7_COM7F_IMF(CExtractCallbackConsole::SetTotal(UInt64 size))
239370b324cSopenharmony_ci{
240370b324cSopenharmony_ci  MT_LOCK
241370b324cSopenharmony_ci
242370b324cSopenharmony_ci  if (NeedPercents())
243370b324cSopenharmony_ci  {
244370b324cSopenharmony_ci    _percent.Total = size;
245370b324cSopenharmony_ci    _percent.Print();
246370b324cSopenharmony_ci  }
247370b324cSopenharmony_ci  return CheckBreak2();
248370b324cSopenharmony_ci}
249370b324cSopenharmony_ci
250370b324cSopenharmony_ciZ7_COM7F_IMF(CExtractCallbackConsole::SetCompleted(const UInt64 *completeValue))
251370b324cSopenharmony_ci{
252370b324cSopenharmony_ci  MT_LOCK
253370b324cSopenharmony_ci
254370b324cSopenharmony_ci  if (NeedPercents())
255370b324cSopenharmony_ci  {
256370b324cSopenharmony_ci    if (completeValue)
257370b324cSopenharmony_ci      _percent.Completed = *completeValue;
258370b324cSopenharmony_ci    _percent.Print();
259370b324cSopenharmony_ci  }
260370b324cSopenharmony_ci  return CheckBreak2();
261370b324cSopenharmony_ci}
262370b324cSopenharmony_ci
263370b324cSopenharmony_cistatic const char * const kTab = "  ";
264370b324cSopenharmony_ci
265370b324cSopenharmony_cistatic void PrintFileInfo(CStdOutStream *_so, const wchar_t *path, const FILETIME *ft, const UInt64 *size)
266370b324cSopenharmony_ci{
267370b324cSopenharmony_ci  *_so << kTab << "Path:     ";
268370b324cSopenharmony_ci  _so->NormalizePrint_wstr(path);
269370b324cSopenharmony_ci  *_so << endl;
270370b324cSopenharmony_ci  if (size && *size != (UInt64)(Int64)-1)
271370b324cSopenharmony_ci  {
272370b324cSopenharmony_ci    AString s;
273370b324cSopenharmony_ci    PrintSize_bytes_Smart(s, *size);
274370b324cSopenharmony_ci    *_so << kTab << "Size:     " << s << endl;
275370b324cSopenharmony_ci  }
276370b324cSopenharmony_ci  if (ft)
277370b324cSopenharmony_ci  {
278370b324cSopenharmony_ci    char temp[64];
279370b324cSopenharmony_ci    if (ConvertUtcFileTimeToString(*ft, temp, kTimestampPrintLevel_SEC))
280370b324cSopenharmony_ci      *_so << kTab << "Modified: " << temp << endl;
281370b324cSopenharmony_ci  }
282370b324cSopenharmony_ci}
283370b324cSopenharmony_ci
284370b324cSopenharmony_ciZ7_COM7F_IMF(CExtractCallbackConsole::AskOverwrite(
285370b324cSopenharmony_ci    const wchar_t *existName, const FILETIME *existTime, const UInt64 *existSize,
286370b324cSopenharmony_ci    const wchar_t *newName, const FILETIME *newTime, const UInt64 *newSize,
287370b324cSopenharmony_ci    Int32 *answer))
288370b324cSopenharmony_ci{
289370b324cSopenharmony_ci  MT_LOCK
290370b324cSopenharmony_ci
291370b324cSopenharmony_ci  RINOK(CheckBreak2())
292370b324cSopenharmony_ci
293370b324cSopenharmony_ci  ClosePercentsAndFlush();
294370b324cSopenharmony_ci
295370b324cSopenharmony_ci  if (_so)
296370b324cSopenharmony_ci  {
297370b324cSopenharmony_ci    *_so << endl << "Would you like to replace the existing file:\n";
298370b324cSopenharmony_ci    PrintFileInfo(_so, existName, existTime, existSize);
299370b324cSopenharmony_ci    *_so << "with the file from archive:\n";
300370b324cSopenharmony_ci    PrintFileInfo(_so, newName, newTime, newSize);
301370b324cSopenharmony_ci  }
302370b324cSopenharmony_ci
303370b324cSopenharmony_ci  NUserAnswerMode::EEnum overwriteAnswer = ScanUserYesNoAllQuit(_so);
304370b324cSopenharmony_ci
305370b324cSopenharmony_ci  switch ((int)overwriteAnswer)
306370b324cSopenharmony_ci  {
307370b324cSopenharmony_ci    case NUserAnswerMode::kQuit:  return E_ABORT;
308370b324cSopenharmony_ci    case NUserAnswerMode::kNo:     *answer = NOverwriteAnswer::kNo; break;
309370b324cSopenharmony_ci    case NUserAnswerMode::kNoAll:  *answer = NOverwriteAnswer::kNoToAll; break;
310370b324cSopenharmony_ci    case NUserAnswerMode::kYesAll: *answer = NOverwriteAnswer::kYesToAll; break;
311370b324cSopenharmony_ci    case NUserAnswerMode::kYes:    *answer = NOverwriteAnswer::kYes; break;
312370b324cSopenharmony_ci    case NUserAnswerMode::kAutoRenameAll: *answer = NOverwriteAnswer::kAutoRename; break;
313370b324cSopenharmony_ci    case NUserAnswerMode::kEof:  return E_ABORT;
314370b324cSopenharmony_ci    case NUserAnswerMode::kError:  return E_FAIL;
315370b324cSopenharmony_ci    default: return E_FAIL;
316370b324cSopenharmony_ci  }
317370b324cSopenharmony_ci
318370b324cSopenharmony_ci  if (_so)
319370b324cSopenharmony_ci  {
320370b324cSopenharmony_ci    *_so << endl;
321370b324cSopenharmony_ci    if (NeedFlush)
322370b324cSopenharmony_ci      _so->Flush();
323370b324cSopenharmony_ci  }
324370b324cSopenharmony_ci
325370b324cSopenharmony_ci  return CheckBreak2();
326370b324cSopenharmony_ci}
327370b324cSopenharmony_ci
328370b324cSopenharmony_ciZ7_COM7F_IMF(CExtractCallbackConsole::PrepareOperation(const wchar_t *name, Int32 isFolder, Int32 askExtractMode, const UInt64 *position))
329370b324cSopenharmony_ci{
330370b324cSopenharmony_ci  MT_LOCK
331370b324cSopenharmony_ci
332370b324cSopenharmony_ci  _currentName = name;
333370b324cSopenharmony_ci
334370b324cSopenharmony_ci  const char *s;
335370b324cSopenharmony_ci  unsigned requiredLevel = 1;
336370b324cSopenharmony_ci
337370b324cSopenharmony_ci  switch (askExtractMode)
338370b324cSopenharmony_ci  {
339370b324cSopenharmony_ci    case NArchive::NExtract::NAskMode::kExtract: s = kExtractString; break;
340370b324cSopenharmony_ci    case NArchive::NExtract::NAskMode::kTest:    s = kTestString; break;
341370b324cSopenharmony_ci    case NArchive::NExtract::NAskMode::kSkip:    s = kSkipString; requiredLevel = 2; break;
342370b324cSopenharmony_ci    case NArchive::NExtract::NAskMode::kReadExternal: s = kReadString; requiredLevel = 0; break;
343370b324cSopenharmony_ci    default: s = "???"; requiredLevel = 2;
344370b324cSopenharmony_ci  }
345370b324cSopenharmony_ci
346370b324cSopenharmony_ci  bool show2 = (LogLevel >= requiredLevel && _so);
347370b324cSopenharmony_ci
348370b324cSopenharmony_ci  if (show2)
349370b324cSopenharmony_ci  {
350370b324cSopenharmony_ci    ClosePercents_for_so();
351370b324cSopenharmony_ci
352370b324cSopenharmony_ci    _tempA = s;
353370b324cSopenharmony_ci    if (name)
354370b324cSopenharmony_ci      _tempA.Add_Space();
355370b324cSopenharmony_ci    *_so << _tempA;
356370b324cSopenharmony_ci
357370b324cSopenharmony_ci    _tempU.Empty();
358370b324cSopenharmony_ci    if (name)
359370b324cSopenharmony_ci    {
360370b324cSopenharmony_ci      _tempU = name;
361370b324cSopenharmony_ci      _so->Normalize_UString(_tempU);
362370b324cSopenharmony_ci      // 21.04
363370b324cSopenharmony_ci      if (isFolder)
364370b324cSopenharmony_ci      {
365370b324cSopenharmony_ci        if (!_tempU.IsEmpty() && _tempU.Back() != WCHAR_PATH_SEPARATOR)
366370b324cSopenharmony_ci          _tempU.Add_PathSepar();
367370b324cSopenharmony_ci      }
368370b324cSopenharmony_ci    }
369370b324cSopenharmony_ci    _so->PrintUString(_tempU, _tempA);
370370b324cSopenharmony_ci    if (position)
371370b324cSopenharmony_ci      *_so << " <" << *position << ">";
372370b324cSopenharmony_ci    *_so << endl;
373370b324cSopenharmony_ci
374370b324cSopenharmony_ci    if (NeedFlush)
375370b324cSopenharmony_ci      _so->Flush();
376370b324cSopenharmony_ci  }
377370b324cSopenharmony_ci
378370b324cSopenharmony_ci  if (NeedPercents())
379370b324cSopenharmony_ci  {
380370b324cSopenharmony_ci    if (PercentsNameLevel >= 1)
381370b324cSopenharmony_ci    {
382370b324cSopenharmony_ci      _percent.FileName.Empty();
383370b324cSopenharmony_ci      _percent.Command.Empty();
384370b324cSopenharmony_ci      if (PercentsNameLevel > 1 || !show2)
385370b324cSopenharmony_ci      {
386370b324cSopenharmony_ci        _percent.Command = s;
387370b324cSopenharmony_ci        if (name)
388370b324cSopenharmony_ci          _percent.FileName = name;
389370b324cSopenharmony_ci      }
390370b324cSopenharmony_ci    }
391370b324cSopenharmony_ci    _percent.Print();
392370b324cSopenharmony_ci  }
393370b324cSopenharmony_ci
394370b324cSopenharmony_ci  return CheckBreak2();
395370b324cSopenharmony_ci}
396370b324cSopenharmony_ci
397370b324cSopenharmony_ciZ7_COM7F_IMF(CExtractCallbackConsole::MessageError(const wchar_t *message))
398370b324cSopenharmony_ci{
399370b324cSopenharmony_ci  MT_LOCK
400370b324cSopenharmony_ci
401370b324cSopenharmony_ci  RINOK(CheckBreak2())
402370b324cSopenharmony_ci
403370b324cSopenharmony_ci  NumFileErrors_in_Current++;
404370b324cSopenharmony_ci  NumFileErrors++;
405370b324cSopenharmony_ci
406370b324cSopenharmony_ci  ClosePercentsAndFlush();
407370b324cSopenharmony_ci  if (_se)
408370b324cSopenharmony_ci  {
409370b324cSopenharmony_ci    *_se << kError << message << endl;
410370b324cSopenharmony_ci    _se->Flush();
411370b324cSopenharmony_ci  }
412370b324cSopenharmony_ci
413370b324cSopenharmony_ci  return CheckBreak2();
414370b324cSopenharmony_ci}
415370b324cSopenharmony_ci
416370b324cSopenharmony_civoid SetExtractErrorMessage(Int32 opRes, Int32 encrypted, AString &dest);
417370b324cSopenharmony_civoid SetExtractErrorMessage(Int32 opRes, Int32 encrypted, AString &dest)
418370b324cSopenharmony_ci{
419370b324cSopenharmony_ci  dest.Empty();
420370b324cSopenharmony_ci    const char *s = NULL;
421370b324cSopenharmony_ci
422370b324cSopenharmony_ci    switch (opRes)
423370b324cSopenharmony_ci    {
424370b324cSopenharmony_ci      case NArchive::NExtract::NOperationResult::kUnsupportedMethod:
425370b324cSopenharmony_ci        s = kUnsupportedMethod;
426370b324cSopenharmony_ci        break;
427370b324cSopenharmony_ci      case NArchive::NExtract::NOperationResult::kCRCError:
428370b324cSopenharmony_ci        s = (encrypted ? kCrcFailedEncrypted : kCrcFailed);
429370b324cSopenharmony_ci        break;
430370b324cSopenharmony_ci      case NArchive::NExtract::NOperationResult::kDataError:
431370b324cSopenharmony_ci        s = (encrypted ? kDataErrorEncrypted : kDataError);
432370b324cSopenharmony_ci        break;
433370b324cSopenharmony_ci      case NArchive::NExtract::NOperationResult::kUnavailable:
434370b324cSopenharmony_ci        s = kUnavailableData;
435370b324cSopenharmony_ci        break;
436370b324cSopenharmony_ci      case NArchive::NExtract::NOperationResult::kUnexpectedEnd:
437370b324cSopenharmony_ci        s = kUnexpectedEnd;
438370b324cSopenharmony_ci        break;
439370b324cSopenharmony_ci      case NArchive::NExtract::NOperationResult::kDataAfterEnd:
440370b324cSopenharmony_ci        s = kDataAfterEnd;
441370b324cSopenharmony_ci        break;
442370b324cSopenharmony_ci      case NArchive::NExtract::NOperationResult::kIsNotArc:
443370b324cSopenharmony_ci        s = kIsNotArc;
444370b324cSopenharmony_ci        break;
445370b324cSopenharmony_ci      case NArchive::NExtract::NOperationResult::kHeadersError:
446370b324cSopenharmony_ci        s = kHeadersError;
447370b324cSopenharmony_ci        break;
448370b324cSopenharmony_ci      case NArchive::NExtract::NOperationResult::kWrongPassword:
449370b324cSopenharmony_ci        s = kWrongPassword;
450370b324cSopenharmony_ci        break;
451370b324cSopenharmony_ci    }
452370b324cSopenharmony_ci
453370b324cSopenharmony_ci    dest += kError;
454370b324cSopenharmony_ci    if (s)
455370b324cSopenharmony_ci      dest += s;
456370b324cSopenharmony_ci    else
457370b324cSopenharmony_ci    {
458370b324cSopenharmony_ci      dest += "Error #";
459370b324cSopenharmony_ci      dest.Add_UInt32((UInt32)opRes);
460370b324cSopenharmony_ci    }
461370b324cSopenharmony_ci}
462370b324cSopenharmony_ci
463370b324cSopenharmony_ciZ7_COM7F_IMF(CExtractCallbackConsole::SetOperationResult(Int32 opRes, Int32 encrypted))
464370b324cSopenharmony_ci{
465370b324cSopenharmony_ci  MT_LOCK
466370b324cSopenharmony_ci
467370b324cSopenharmony_ci  if (opRes == NArchive::NExtract::NOperationResult::kOK)
468370b324cSopenharmony_ci  {
469370b324cSopenharmony_ci    if (NeedPercents())
470370b324cSopenharmony_ci    {
471370b324cSopenharmony_ci      _percent.Command.Empty();
472370b324cSopenharmony_ci      _percent.FileName.Empty();
473370b324cSopenharmony_ci      _percent.Files++;
474370b324cSopenharmony_ci    }
475370b324cSopenharmony_ci  }
476370b324cSopenharmony_ci  else
477370b324cSopenharmony_ci  {
478370b324cSopenharmony_ci    NumFileErrors_in_Current++;
479370b324cSopenharmony_ci    NumFileErrors++;
480370b324cSopenharmony_ci
481370b324cSopenharmony_ci    if (_se)
482370b324cSopenharmony_ci    {
483370b324cSopenharmony_ci      ClosePercentsAndFlush();
484370b324cSopenharmony_ci
485370b324cSopenharmony_ci      AString s;
486370b324cSopenharmony_ci      SetExtractErrorMessage(opRes, encrypted, s);
487370b324cSopenharmony_ci
488370b324cSopenharmony_ci      *_se << s;
489370b324cSopenharmony_ci      if (!_currentName.IsEmpty())
490370b324cSopenharmony_ci      {
491370b324cSopenharmony_ci        *_se << " : ";
492370b324cSopenharmony_ci        _se->NormalizePrint_UString(_currentName);
493370b324cSopenharmony_ci      }
494370b324cSopenharmony_ci      *_se << endl;
495370b324cSopenharmony_ci      _se->Flush();
496370b324cSopenharmony_ci    }
497370b324cSopenharmony_ci  }
498370b324cSopenharmony_ci
499370b324cSopenharmony_ci  return CheckBreak2();
500370b324cSopenharmony_ci}
501370b324cSopenharmony_ci
502370b324cSopenharmony_ciZ7_COM7F_IMF(CExtractCallbackConsole::ReportExtractResult(Int32 opRes, Int32 encrypted, const wchar_t *name))
503370b324cSopenharmony_ci{
504370b324cSopenharmony_ci  if (opRes != NArchive::NExtract::NOperationResult::kOK)
505370b324cSopenharmony_ci  {
506370b324cSopenharmony_ci    _currentName = name;
507370b324cSopenharmony_ci    return SetOperationResult(opRes, encrypted);
508370b324cSopenharmony_ci  }
509370b324cSopenharmony_ci
510370b324cSopenharmony_ci  return CheckBreak2();
511370b324cSopenharmony_ci}
512370b324cSopenharmony_ci
513370b324cSopenharmony_ci
514370b324cSopenharmony_ci
515370b324cSopenharmony_ci#ifndef Z7_NO_CRYPTO
516370b324cSopenharmony_ci
517370b324cSopenharmony_ciHRESULT CExtractCallbackConsole::SetPassword(const UString &password)
518370b324cSopenharmony_ci{
519370b324cSopenharmony_ci  PasswordIsDefined = true;
520370b324cSopenharmony_ci  Password = password;
521370b324cSopenharmony_ci  return S_OK;
522370b324cSopenharmony_ci}
523370b324cSopenharmony_ci
524370b324cSopenharmony_ciZ7_COM7F_IMF(CExtractCallbackConsole::CryptoGetTextPassword(BSTR *password))
525370b324cSopenharmony_ci{
526370b324cSopenharmony_ci  COM_TRY_BEGIN
527370b324cSopenharmony_ci  MT_LOCK
528370b324cSopenharmony_ci  return Open_CryptoGetTextPassword(password);
529370b324cSopenharmony_ci  COM_TRY_END
530370b324cSopenharmony_ci}
531370b324cSopenharmony_ci
532370b324cSopenharmony_ci#endif
533370b324cSopenharmony_ci
534370b324cSopenharmony_ciHRESULT CExtractCallbackConsole::BeforeOpen(const wchar_t *name, bool testMode)
535370b324cSopenharmony_ci{
536370b324cSopenharmony_ci  RINOK(CheckBreak2())
537370b324cSopenharmony_ci
538370b324cSopenharmony_ci  NumTryArcs++;
539370b324cSopenharmony_ci  ThereIsError_in_Current = false;
540370b324cSopenharmony_ci  ThereIsWarning_in_Current = false;
541370b324cSopenharmony_ci  NumFileErrors_in_Current = 0;
542370b324cSopenharmony_ci
543370b324cSopenharmony_ci  ClosePercents_for_so();
544370b324cSopenharmony_ci  if (_so)
545370b324cSopenharmony_ci  {
546370b324cSopenharmony_ci    *_so << endl << (testMode ? kTesting : kExtracting);
547370b324cSopenharmony_ci    _so->NormalizePrint_wstr(name);
548370b324cSopenharmony_ci    *_so << endl;
549370b324cSopenharmony_ci  }
550370b324cSopenharmony_ci
551370b324cSopenharmony_ci  if (NeedPercents())
552370b324cSopenharmony_ci    _percent.Command = "Open";
553370b324cSopenharmony_ci  return S_OK;
554370b324cSopenharmony_ci}
555370b324cSopenharmony_ci
556370b324cSopenharmony_ciHRESULT Print_OpenArchive_Props(CStdOutStream &so, const CCodecs *codecs, const CArchiveLink &arcLink);
557370b324cSopenharmony_ciHRESULT Print_OpenArchive_Error(CStdOutStream &so, const CCodecs *codecs, const CArchiveLink &arcLink);
558370b324cSopenharmony_ci
559370b324cSopenharmony_cistatic AString GetOpenArcErrorMessage(UInt32 errorFlags)
560370b324cSopenharmony_ci{
561370b324cSopenharmony_ci  AString s;
562370b324cSopenharmony_ci
563370b324cSopenharmony_ci  for (unsigned i = 0; i < Z7_ARRAY_SIZE(k_ErrorFlagsMessages); i++)
564370b324cSopenharmony_ci  {
565370b324cSopenharmony_ci    UInt32 f = (1 << i);
566370b324cSopenharmony_ci    if ((errorFlags & f) == 0)
567370b324cSopenharmony_ci      continue;
568370b324cSopenharmony_ci    const char *m = k_ErrorFlagsMessages[i];
569370b324cSopenharmony_ci    if (!s.IsEmpty())
570370b324cSopenharmony_ci      s.Add_LF();
571370b324cSopenharmony_ci    s += m;
572370b324cSopenharmony_ci    errorFlags &= ~f;
573370b324cSopenharmony_ci  }
574370b324cSopenharmony_ci
575370b324cSopenharmony_ci  if (errorFlags != 0)
576370b324cSopenharmony_ci  {
577370b324cSopenharmony_ci    char sz[16];
578370b324cSopenharmony_ci    sz[0] = '0';
579370b324cSopenharmony_ci    sz[1] = 'x';
580370b324cSopenharmony_ci    ConvertUInt32ToHex(errorFlags, sz + 2);
581370b324cSopenharmony_ci    if (!s.IsEmpty())
582370b324cSopenharmony_ci      s.Add_LF();
583370b324cSopenharmony_ci    s += sz;
584370b324cSopenharmony_ci  }
585370b324cSopenharmony_ci
586370b324cSopenharmony_ci  return s;
587370b324cSopenharmony_ci}
588370b324cSopenharmony_ci
589370b324cSopenharmony_civoid PrintErrorFlags(CStdOutStream &so, const char *s, UInt32 errorFlags);
590370b324cSopenharmony_civoid PrintErrorFlags(CStdOutStream &so, const char *s, UInt32 errorFlags)
591370b324cSopenharmony_ci{
592370b324cSopenharmony_ci  if (errorFlags == 0)
593370b324cSopenharmony_ci    return;
594370b324cSopenharmony_ci  so << s << endl << GetOpenArcErrorMessage(errorFlags) << endl;
595370b324cSopenharmony_ci}
596370b324cSopenharmony_ci
597370b324cSopenharmony_cistatic void Add_Messsage_Pre_ArcType(UString &s, const char *pre, const wchar_t *arcType)
598370b324cSopenharmony_ci{
599370b324cSopenharmony_ci  s.Add_LF();
600370b324cSopenharmony_ci  s += pre;
601370b324cSopenharmony_ci  s += " as [";
602370b324cSopenharmony_ci  s += arcType;
603370b324cSopenharmony_ci  s += "] archive";
604370b324cSopenharmony_ci}
605370b324cSopenharmony_ci
606370b324cSopenharmony_civoid Print_ErrorFormatIndex_Warning(CStdOutStream *_so, const CCodecs *codecs, const CArc &arc);
607370b324cSopenharmony_civoid Print_ErrorFormatIndex_Warning(CStdOutStream *_so, const CCodecs *codecs, const CArc &arc)
608370b324cSopenharmony_ci{
609370b324cSopenharmony_ci  const CArcErrorInfo &er = arc.ErrorInfo;
610370b324cSopenharmony_ci
611370b324cSopenharmony_ci  *_so << "WARNING:\n";
612370b324cSopenharmony_ci  _so->NormalizePrint_UString(arc.Path);
613370b324cSopenharmony_ci  UString s;
614370b324cSopenharmony_ci  if (arc.FormatIndex == er.ErrorFormatIndex)
615370b324cSopenharmony_ci  {
616370b324cSopenharmony_ci    s.Add_LF();
617370b324cSopenharmony_ci    s += "The archive is open with offset";
618370b324cSopenharmony_ci  }
619370b324cSopenharmony_ci  else
620370b324cSopenharmony_ci  {
621370b324cSopenharmony_ci    Add_Messsage_Pre_ArcType(s, "Cannot open the file", codecs->GetFormatNamePtr(er.ErrorFormatIndex));
622370b324cSopenharmony_ci    Add_Messsage_Pre_ArcType(s, "The file is open", codecs->GetFormatNamePtr(arc.FormatIndex));
623370b324cSopenharmony_ci  }
624370b324cSopenharmony_ci
625370b324cSopenharmony_ci  *_so << s << endl << endl;
626370b324cSopenharmony_ci}
627370b324cSopenharmony_ci
628370b324cSopenharmony_ci
629370b324cSopenharmony_ciHRESULT CExtractCallbackConsole::OpenResult(
630370b324cSopenharmony_ci    const CCodecs *codecs, const CArchiveLink &arcLink,
631370b324cSopenharmony_ci    const wchar_t *name, HRESULT result)
632370b324cSopenharmony_ci{
633370b324cSopenharmony_ci  ClosePercents();
634370b324cSopenharmony_ci
635370b324cSopenharmony_ci  if (NeedPercents())
636370b324cSopenharmony_ci  {
637370b324cSopenharmony_ci    _percent.Files = 0;
638370b324cSopenharmony_ci    _percent.Command.Empty();
639370b324cSopenharmony_ci    _percent.FileName.Empty();
640370b324cSopenharmony_ci  }
641370b324cSopenharmony_ci
642370b324cSopenharmony_ci
643370b324cSopenharmony_ci  ClosePercentsAndFlush();
644370b324cSopenharmony_ci
645370b324cSopenharmony_ci  FOR_VECTOR (level, arcLink.Arcs)
646370b324cSopenharmony_ci  {
647370b324cSopenharmony_ci    const CArc &arc = arcLink.Arcs[level];
648370b324cSopenharmony_ci    const CArcErrorInfo &er = arc.ErrorInfo;
649370b324cSopenharmony_ci
650370b324cSopenharmony_ci    UInt32 errorFlags = er.GetErrorFlags();
651370b324cSopenharmony_ci
652370b324cSopenharmony_ci    if (errorFlags != 0 || !er.ErrorMessage.IsEmpty())
653370b324cSopenharmony_ci    {
654370b324cSopenharmony_ci      if (_se)
655370b324cSopenharmony_ci      {
656370b324cSopenharmony_ci        *_se << endl;
657370b324cSopenharmony_ci        if (level != 0)
658370b324cSopenharmony_ci        {
659370b324cSopenharmony_ci          _se->NormalizePrint_UString(arc.Path);
660370b324cSopenharmony_ci          *_se << endl;
661370b324cSopenharmony_ci        }
662370b324cSopenharmony_ci      }
663370b324cSopenharmony_ci
664370b324cSopenharmony_ci      if (errorFlags != 0)
665370b324cSopenharmony_ci      {
666370b324cSopenharmony_ci        if (_se)
667370b324cSopenharmony_ci          PrintErrorFlags(*_se, "ERRORS:", errorFlags);
668370b324cSopenharmony_ci        NumOpenArcErrors++;
669370b324cSopenharmony_ci        ThereIsError_in_Current = true;
670370b324cSopenharmony_ci      }
671370b324cSopenharmony_ci
672370b324cSopenharmony_ci      if (!er.ErrorMessage.IsEmpty())
673370b324cSopenharmony_ci      {
674370b324cSopenharmony_ci        if (_se)
675370b324cSopenharmony_ci          *_se << "ERRORS:" << endl << er.ErrorMessage << endl;
676370b324cSopenharmony_ci        NumOpenArcErrors++;
677370b324cSopenharmony_ci        ThereIsError_in_Current = true;
678370b324cSopenharmony_ci      }
679370b324cSopenharmony_ci
680370b324cSopenharmony_ci      if (_se)
681370b324cSopenharmony_ci      {
682370b324cSopenharmony_ci        *_se << endl;
683370b324cSopenharmony_ci        _se->Flush();
684370b324cSopenharmony_ci      }
685370b324cSopenharmony_ci    }
686370b324cSopenharmony_ci
687370b324cSopenharmony_ci    UInt32 warningFlags = er.GetWarningFlags();
688370b324cSopenharmony_ci
689370b324cSopenharmony_ci    if (warningFlags != 0 || !er.WarningMessage.IsEmpty())
690370b324cSopenharmony_ci    {
691370b324cSopenharmony_ci      if (_so)
692370b324cSopenharmony_ci      {
693370b324cSopenharmony_ci        *_so << endl;
694370b324cSopenharmony_ci        if (level != 0)
695370b324cSopenharmony_ci        {
696370b324cSopenharmony_ci          _so->NormalizePrint_UString(arc.Path);
697370b324cSopenharmony_ci          *_so << endl;
698370b324cSopenharmony_ci        }
699370b324cSopenharmony_ci      }
700370b324cSopenharmony_ci
701370b324cSopenharmony_ci      if (warningFlags != 0)
702370b324cSopenharmony_ci      {
703370b324cSopenharmony_ci        if (_so)
704370b324cSopenharmony_ci          PrintErrorFlags(*_so, "WARNINGS:", warningFlags);
705370b324cSopenharmony_ci        NumOpenArcWarnings++;
706370b324cSopenharmony_ci        ThereIsWarning_in_Current = true;
707370b324cSopenharmony_ci      }
708370b324cSopenharmony_ci
709370b324cSopenharmony_ci      if (!er.WarningMessage.IsEmpty())
710370b324cSopenharmony_ci      {
711370b324cSopenharmony_ci        if (_so)
712370b324cSopenharmony_ci          *_so << "WARNINGS:" << endl << er.WarningMessage << endl;
713370b324cSopenharmony_ci        NumOpenArcWarnings++;
714370b324cSopenharmony_ci        ThereIsWarning_in_Current = true;
715370b324cSopenharmony_ci      }
716370b324cSopenharmony_ci
717370b324cSopenharmony_ci      if (_so)
718370b324cSopenharmony_ci      {
719370b324cSopenharmony_ci        *_so << endl;
720370b324cSopenharmony_ci        if (NeedFlush)
721370b324cSopenharmony_ci          _so->Flush();
722370b324cSopenharmony_ci      }
723370b324cSopenharmony_ci    }
724370b324cSopenharmony_ci
725370b324cSopenharmony_ci
726370b324cSopenharmony_ci    if (er.ErrorFormatIndex >= 0)
727370b324cSopenharmony_ci    {
728370b324cSopenharmony_ci      if (_so)
729370b324cSopenharmony_ci      {
730370b324cSopenharmony_ci        Print_ErrorFormatIndex_Warning(_so, codecs, arc);
731370b324cSopenharmony_ci        if (NeedFlush)
732370b324cSopenharmony_ci          _so->Flush();
733370b324cSopenharmony_ci      }
734370b324cSopenharmony_ci      ThereIsWarning_in_Current = true;
735370b324cSopenharmony_ci    }
736370b324cSopenharmony_ci  }
737370b324cSopenharmony_ci
738370b324cSopenharmony_ci  if (result == S_OK)
739370b324cSopenharmony_ci  {
740370b324cSopenharmony_ci    if (_so)
741370b324cSopenharmony_ci    {
742370b324cSopenharmony_ci      RINOK(Print_OpenArchive_Props(*_so, codecs, arcLink))
743370b324cSopenharmony_ci      *_so << endl;
744370b324cSopenharmony_ci    }
745370b324cSopenharmony_ci  }
746370b324cSopenharmony_ci  else
747370b324cSopenharmony_ci  {
748370b324cSopenharmony_ci    NumCantOpenArcs++;
749370b324cSopenharmony_ci    if (_so)
750370b324cSopenharmony_ci      _so->Flush();
751370b324cSopenharmony_ci    if (_se)
752370b324cSopenharmony_ci    {
753370b324cSopenharmony_ci      *_se << kError;
754370b324cSopenharmony_ci      _se->NormalizePrint_wstr(name);
755370b324cSopenharmony_ci      *_se << endl;
756370b324cSopenharmony_ci      const HRESULT res = Print_OpenArchive_Error(*_se, codecs, arcLink);
757370b324cSopenharmony_ci      RINOK(res)
758370b324cSopenharmony_ci      if (result == S_FALSE)
759370b324cSopenharmony_ci      {
760370b324cSopenharmony_ci      }
761370b324cSopenharmony_ci      else
762370b324cSopenharmony_ci      {
763370b324cSopenharmony_ci        if (result == E_OUTOFMEMORY)
764370b324cSopenharmony_ci          *_se << "Can't allocate required memory";
765370b324cSopenharmony_ci        else
766370b324cSopenharmony_ci          *_se << NError::MyFormatMessage(result);
767370b324cSopenharmony_ci        *_se << endl;
768370b324cSopenharmony_ci      }
769370b324cSopenharmony_ci      _se->Flush();
770370b324cSopenharmony_ci    }
771370b324cSopenharmony_ci  }
772370b324cSopenharmony_ci
773370b324cSopenharmony_ci
774370b324cSopenharmony_ci  return CheckBreak2();
775370b324cSopenharmony_ci}
776370b324cSopenharmony_ci
777370b324cSopenharmony_ciHRESULT CExtractCallbackConsole::ThereAreNoFiles()
778370b324cSopenharmony_ci{
779370b324cSopenharmony_ci  ClosePercents_for_so();
780370b324cSopenharmony_ci
781370b324cSopenharmony_ci  if (_so)
782370b324cSopenharmony_ci  {
783370b324cSopenharmony_ci    *_so << endl << kNoFiles << endl;
784370b324cSopenharmony_ci    if (NeedFlush)
785370b324cSopenharmony_ci      _so->Flush();
786370b324cSopenharmony_ci  }
787370b324cSopenharmony_ci  return CheckBreak2();
788370b324cSopenharmony_ci}
789370b324cSopenharmony_ci
790370b324cSopenharmony_ciHRESULT CExtractCallbackConsole::ExtractResult(HRESULT result)
791370b324cSopenharmony_ci{
792370b324cSopenharmony_ci  MT_LOCK
793370b324cSopenharmony_ci
794370b324cSopenharmony_ci  if (NeedPercents())
795370b324cSopenharmony_ci  {
796370b324cSopenharmony_ci    _percent.ClosePrint(true);
797370b324cSopenharmony_ci    _percent.Command.Empty();
798370b324cSopenharmony_ci    _percent.FileName.Empty();
799370b324cSopenharmony_ci  }
800370b324cSopenharmony_ci
801370b324cSopenharmony_ci  if (_so)
802370b324cSopenharmony_ci    _so->Flush();
803370b324cSopenharmony_ci
804370b324cSopenharmony_ci  if (result == S_OK)
805370b324cSopenharmony_ci  {
806370b324cSopenharmony_ci    if (NumFileErrors_in_Current == 0 && !ThereIsError_in_Current)
807370b324cSopenharmony_ci    {
808370b324cSopenharmony_ci      if (ThereIsWarning_in_Current)
809370b324cSopenharmony_ci        NumArcsWithWarnings++;
810370b324cSopenharmony_ci      else
811370b324cSopenharmony_ci        NumOkArcs++;
812370b324cSopenharmony_ci      if (_so)
813370b324cSopenharmony_ci        *_so << kEverythingIsOk << endl;
814370b324cSopenharmony_ci    }
815370b324cSopenharmony_ci    else
816370b324cSopenharmony_ci    {
817370b324cSopenharmony_ci      NumArcsWithError++;
818370b324cSopenharmony_ci      if (_so)
819370b324cSopenharmony_ci      {
820370b324cSopenharmony_ci        *_so << endl;
821370b324cSopenharmony_ci        if (NumFileErrors_in_Current != 0)
822370b324cSopenharmony_ci          *_so << "Sub items Errors: " << NumFileErrors_in_Current << endl;
823370b324cSopenharmony_ci      }
824370b324cSopenharmony_ci    }
825370b324cSopenharmony_ci    if (_so && NeedFlush)
826370b324cSopenharmony_ci      _so->Flush();
827370b324cSopenharmony_ci  }
828370b324cSopenharmony_ci  else
829370b324cSopenharmony_ci  {
830370b324cSopenharmony_ci    NumArcsWithError++;
831370b324cSopenharmony_ci    if (result == E_ABORT
832370b324cSopenharmony_ci        || result == HRESULT_FROM_WIN32(ERROR_DISK_FULL)
833370b324cSopenharmony_ci        )
834370b324cSopenharmony_ci      return result;
835370b324cSopenharmony_ci
836370b324cSopenharmony_ci    if (_se)
837370b324cSopenharmony_ci    {
838370b324cSopenharmony_ci      *_se << endl << kError;
839370b324cSopenharmony_ci      if (result == E_OUTOFMEMORY)
840370b324cSopenharmony_ci        *_se << kMemoryExceptionMessage;
841370b324cSopenharmony_ci      else
842370b324cSopenharmony_ci        *_se << NError::MyFormatMessage(result);
843370b324cSopenharmony_ci      *_se << endl;
844370b324cSopenharmony_ci      _se->Flush();
845370b324cSopenharmony_ci    }
846370b324cSopenharmony_ci  }
847370b324cSopenharmony_ci
848370b324cSopenharmony_ci  return CheckBreak2();
849370b324cSopenharmony_ci}
850