OLD | NEW |
| (Empty) |
1 // UpdateCallbackConsole.cpp | |
2 | |
3 #include "StdAfx.h" | |
4 | |
5 #include "UpdateCallbackConsole.h" | |
6 | |
7 #include "Windows/Error.h" | |
8 #ifdef COMPRESS_MT | |
9 #include "Windows/Synchronization.h" | |
10 #endif | |
11 | |
12 #include "ConsoleClose.h" | |
13 #include "UserInputUtils.h" | |
14 | |
15 using namespace NWindows; | |
16 | |
17 #ifdef COMPRESS_MT | |
18 static NSynchronization::CCriticalSection g_CriticalSection; | |
19 #define MT_LOCK NSynchronization::CCriticalSectionLock lock(g_CriticalSection); | |
20 #else | |
21 #define MT_LOCK | |
22 #endif | |
23 | |
24 static const wchar_t *kEmptyFileAlias = L"[Content]"; | |
25 | |
26 static const char *kCreatingArchiveMessage = "Creating archive "; | |
27 static const char *kUpdatingArchiveMessage = "Updating archive "; | |
28 static const char *kScanningMessage = "Scanning"; | |
29 | |
30 | |
31 HRESULT CUpdateCallbackConsole::OpenResult(const wchar_t *name, HRESULT result) | |
32 { | |
33 (*OutStream) << endl; | |
34 if (result != S_OK) | |
35 (*OutStream) << "Error: " << name << " is not supported archive" << endl; | |
36 return S_OK; | |
37 } | |
38 | |
39 HRESULT CUpdateCallbackConsole::StartScanning() | |
40 { | |
41 (*OutStream) << kScanningMessage; | |
42 return S_OK; | |
43 } | |
44 | |
45 HRESULT CUpdateCallbackConsole::ScanProgress(UInt64 /* numFolders */, UInt64 /*
numFiles */, const wchar_t * /* path */) | |
46 { | |
47 return CheckBreak(); | |
48 } | |
49 | |
50 HRESULT CUpdateCallbackConsole::CanNotFindError(const wchar_t *name, DWORD syste
mError) | |
51 { | |
52 CantFindFiles.Add(name); | |
53 CantFindCodes.Add(systemError); | |
54 // m_PercentPrinter.ClosePrint(); | |
55 if (!m_WarningsMode) | |
56 { | |
57 (*OutStream) << endl << endl; | |
58 m_PercentPrinter.PrintNewLine(); | |
59 m_WarningsMode = true; | |
60 } | |
61 m_PercentPrinter.PrintString(name); | |
62 m_PercentPrinter.PrintString(": WARNING: "); | |
63 m_PercentPrinter.PrintString(NError::MyFormatMessageW(systemError)); | |
64 m_PercentPrinter.PrintNewLine(); | |
65 return S_OK; | |
66 } | |
67 | |
68 HRESULT CUpdateCallbackConsole::FinishScanning() | |
69 { | |
70 (*OutStream) << endl << endl; | |
71 return S_OK; | |
72 } | |
73 | |
74 HRESULT CUpdateCallbackConsole::StartArchive(const wchar_t *name, bool updating) | |
75 { | |
76 if(updating) | |
77 (*OutStream) << kUpdatingArchiveMessage; | |
78 else | |
79 (*OutStream) << kCreatingArchiveMessage; | |
80 if (name != 0) | |
81 (*OutStream) << name; | |
82 else | |
83 (*OutStream) << "StdOut"; | |
84 (*OutStream) << endl << endl; | |
85 return S_OK; | |
86 } | |
87 | |
88 HRESULT CUpdateCallbackConsole::FinishArchive() | |
89 { | |
90 (*OutStream) << endl; | |
91 return S_OK; | |
92 } | |
93 | |
94 HRESULT CUpdateCallbackConsole::CheckBreak() | |
95 { | |
96 if (NConsoleClose::TestBreakSignal()) | |
97 return E_ABORT; | |
98 return S_OK; | |
99 } | |
100 | |
101 HRESULT CUpdateCallbackConsole::Finilize() | |
102 { | |
103 MT_LOCK | |
104 if (m_NeedBeClosed) | |
105 { | |
106 if (EnablePercents) | |
107 { | |
108 m_PercentPrinter.ClosePrint(); | |
109 } | |
110 if (!StdOutMode && m_NeedNewLine) | |
111 { | |
112 m_PercentPrinter.PrintNewLine(); | |
113 m_NeedNewLine = false; | |
114 } | |
115 m_NeedBeClosed = false; | |
116 } | |
117 return S_OK; | |
118 } | |
119 | |
120 HRESULT CUpdateCallbackConsole::SetNumFiles(UInt64 /* numFiles */) | |
121 { | |
122 return S_OK; | |
123 } | |
124 | |
125 HRESULT CUpdateCallbackConsole::SetTotal(UInt64 size) | |
126 { | |
127 MT_LOCK | |
128 if (EnablePercents) | |
129 m_PercentPrinter.SetTotal(size); | |
130 return S_OK; | |
131 } | |
132 | |
133 HRESULT CUpdateCallbackConsole::SetCompleted(const UInt64 *completeValue) | |
134 { | |
135 MT_LOCK | |
136 if (completeValue != NULL) | |
137 { | |
138 if (EnablePercents) | |
139 { | |
140 m_PercentPrinter.SetRatio(*completeValue); | |
141 m_PercentPrinter.PrintRatio(); | |
142 m_NeedBeClosed = true; | |
143 } | |
144 } | |
145 if (NConsoleClose::TestBreakSignal()) | |
146 return E_ABORT; | |
147 return S_OK; | |
148 } | |
149 | |
150 HRESULT CUpdateCallbackConsole::SetRatioInfo(const UInt64 * /* inSize */, const
UInt64 * /* outSize */) | |
151 { | |
152 if (NConsoleClose::TestBreakSignal()) | |
153 return E_ABORT; | |
154 return S_OK; | |
155 } | |
156 | |
157 HRESULT CUpdateCallbackConsole::GetStream(const wchar_t *name, bool isAnti) | |
158 { | |
159 MT_LOCK | |
160 if (StdOutMode) | |
161 return S_OK; | |
162 if(isAnti) | |
163 m_PercentPrinter.PrintString("Anti item "); | |
164 else | |
165 m_PercentPrinter.PrintString("Compressing "); | |
166 if (name[0] == 0) | |
167 name = kEmptyFileAlias; | |
168 m_PercentPrinter.PrintString(name); | |
169 if (EnablePercents) | |
170 m_PercentPrinter.RePrintRatio(); | |
171 return S_OK; | |
172 } | |
173 | |
174 HRESULT CUpdateCallbackConsole::OpenFileError(const wchar_t *name, DWORD systemE
rror) | |
175 { | |
176 MT_LOCK | |
177 FailedCodes.Add(systemError); | |
178 FailedFiles.Add(name); | |
179 // if (systemError == ERROR_SHARING_VIOLATION) | |
180 { | |
181 m_PercentPrinter.ClosePrint(); | |
182 m_PercentPrinter.PrintNewLine(); | |
183 m_PercentPrinter.PrintString("WARNING: "); | |
184 m_PercentPrinter.PrintString(NError::MyFormatMessageW(systemError)); | |
185 return S_FALSE; | |
186 } | |
187 // return systemError; | |
188 } | |
189 | |
190 HRESULT CUpdateCallbackConsole::SetOperationResult(Int32 ) | |
191 { | |
192 m_NeedBeClosed = true; | |
193 m_NeedNewLine = true; | |
194 return S_OK; | |
195 } | |
196 | |
197 HRESULT CUpdateCallbackConsole::CryptoGetTextPassword2(Int32 *passwordIsDefined,
BSTR *password) | |
198 { | |
199 #ifdef _NO_CRYPTO | |
200 | |
201 *passwordIsDefined = false; | |
202 return StringToBstr(L"", password); | |
203 | |
204 #else | |
205 | |
206 if (!PasswordIsDefined) | |
207 { | |
208 if (AskPassword) | |
209 { | |
210 Password = GetPassword(OutStream); | |
211 PasswordIsDefined = true; | |
212 } | |
213 } | |
214 *passwordIsDefined = BoolToInt(PasswordIsDefined); | |
215 return StringToBstr(Password, password); | |
216 | |
217 #endif | |
218 | |
219 } | |
220 | |
221 /* | |
222 HRESULT CUpdateCallbackConsole::ShowDeleteFile(const wchar_t *name) | |
223 { | |
224 // MT_LOCK | |
225 if (StdOutMode) | |
226 return S_OK; | |
227 RINOK(Finilize()); | |
228 m_PercentPrinter.PrintString("Deleting "); | |
229 if (name[0] == 0) | |
230 name = kEmptyFileAlias; | |
231 m_PercentPrinter.PrintString(name); | |
232 if (EnablePercents) | |
233 m_PercentPrinter.RePrintRatio(); | |
234 m_NeedBeClosed = true; | |
235 m_NeedNewLine = true; | |
236 return S_OK; | |
237 } | |
238 */ | |
OLD | NEW |