3 #ifndef __PROGRESS_DIALOG2_H
\r
4 #define __PROGRESS_DIALOG2_H
\r
6 #include "Windows/Synchronization.h"
\r
7 #include "Windows/Thread.h"
\r
9 #include "Windows/Control/Dialog.h"
\r
10 #include "Windows/Control/ListView.h"
\r
11 #include "Windows/Control/ProgressBar.h"
\r
17 bool _bytesProgressMode;
\r
26 UString _titleFileName;
\r
27 UString _currentFileName;
\r
30 UStringVector Messages;
\r
31 UString ErrorMessage;
\r
32 UString ErrorMessageTitle;
\r
35 UString OkMessageTitle;
\r
37 NWindows::NSynchronization::CCriticalSection _cs;
\r
40 _stopped(false), _paused(false),
\r
41 _totalBytes((UInt64)(Int64)-1), _curBytes(0),
\r
42 _totalFiles((UInt64)(Int64)-1), _curFiles(0),
\r
43 _inSize((UInt64)(Int64)-1),
\r
44 _outSize((UInt64)(Int64)-1),
\r
45 _bytesProgressMode(true)
\r
50 NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
\r
53 void SetStopped(bool value)
\r
55 NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
\r
60 NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
\r
63 void SetPaused(bool value)
\r
65 NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
\r
68 void SetBytesProgressMode(bool bytesProgressMode)
\r
70 NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
\r
71 _bytesProgressMode = bytesProgressMode;
\r
73 void SetProgress(UInt64 total, UInt64 completed)
\r
75 NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
\r
76 _totalBytes = total;
\r
77 _curBytes = completed;
\r
79 void SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)
\r
81 NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
\r
85 _outSize = *outSize;
\r
87 void SetPos(UInt64 completed)
\r
89 NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
\r
90 _curBytes = completed;
\r
92 void SetNumBytesTotal(UInt64 value)
\r
94 NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
\r
95 _totalBytes = value;
\r
97 void SetNumFilesTotal(UInt64 value)
\r
99 NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
\r
100 _totalFiles = value;
\r
102 void SetNumFilesCur(UInt64 value)
\r
104 NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
\r
107 HRESULT ProcessStopAndPause();
\r
108 HRESULT SetPosAndCheckPaused(UInt64 completed);
\r
109 void GetProgress(UInt64 &total, UInt64 &completed,
\r
110 UInt64 &totalFiles, UInt64 &curFiles,
\r
111 UInt64 &inSize, UInt64 &outSize,
\r
112 bool &bytesProgressMode)
\r
114 NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
\r
115 total = _totalBytes;
\r
116 completed = _curBytes;
\r
117 totalFiles = _totalFiles;
\r
118 curFiles = _curFiles;
\r
120 outSize = _outSize;
\r
121 bytesProgressMode = _bytesProgressMode;
\r
123 void SetTitleFileName(const UString &fileName)
\r
125 NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
\r
126 _titleFileName = fileName;
\r
128 void GetTitleFileName(UString &fileName)
\r
130 NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
\r
131 fileName = _titleFileName;
\r
133 void SetCurrentFileName(const UString &fileName)
\r
135 NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
\r
136 _currentFileName = fileName;
\r
138 void GetCurrentFileName(UString &fileName)
\r
140 NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
\r
141 fileName = _currentFileName;
\r
144 void AddErrorMessage(LPCWSTR message)
\r
146 NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
\r
147 Messages.Add(message);
\r
150 void SetErrorMessage(const UString &message)
\r
152 NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
\r
153 ErrorMessage = message;
\r
156 void SetOkMessage(const UString &message)
\r
158 NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
\r
159 OkMessage = message;
\r
162 void SetOkMessageTitle(const UString &title)
\r
164 NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
\r
165 OkMessageTitle = title;
\r
168 void SetErrorMessageTitle(const UString &title)
\r
170 NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
\r
171 ErrorMessageTitle = title;
\r
174 bool ThereIsMessage() const
\r
176 return !Messages.IsEmpty() || !ErrorMessage.IsEmpty() || !OkMessage.IsEmpty();
\r
180 class CU64ToI32Converter
\r
182 UInt64 _numShiftBits;
\r
184 void Init(UInt64 range)
\r
186 // Windows CE doesn't like big number here.
\r
187 for (_numShiftBits = 0; range > (1 << 15); _numShiftBits++)
\r
190 int Count(UInt64 value) { return int(value >> _numShiftBits); }
\r
200 class CProgressDialog: public NWindows::NControl::CModalDialog
\r
202 UString _prevFileName;
\r
203 UString _prevTitleName;
\r
205 UString backgroundString;
\r
206 UString backgroundedString;
\r
207 UString foregroundString;
\r
208 UString pauseString;
\r
209 UString continueString;
\r
210 UString pausedString;
\r
218 CU64ToI32Converter _converter;
\r
219 UInt64 _previousPos;
\r
221 NWindows::NControl::CProgressBar m_ProgressBar;
\r
222 NWindows::NControl::CListView _messageList;
\r
224 UInt32 _prevPercentValue;
\r
226 UInt32 _elapsedTime;
\r
227 UInt32 _prevElapsedSec;
\r
228 UInt64 _prevRemainingSec;
\r
229 ESpeedMode _prevMode;
\r
234 int _numReduceSymbols;
\r
239 UInt32 _numPostedMessages;
\r
240 UInt32 _numAutoSizeMessages;
\r
242 bool _errorsWereDisplayed;
\r
244 bool _waitCloseByCancelButton;
\r
245 bool _cancelWasPressed;
\r
247 bool _inCancelMessageBox;
\r
248 bool _externalCloseMessageWasReceived;
\r
250 void UpdateStatInfo(bool showAll);
\r
251 bool OnTimer(WPARAM timerID, LPARAM callback);
\r
252 void SetRange(UInt64 range);
\r
253 void SetPos(UInt64 pos);
\r
254 virtual bool OnInit();
\r
255 virtual bool OnSize(WPARAM wParam, int xSize, int ySize);
\r
256 virtual void OnCancel();
\r
257 virtual void OnOK();
\r
258 NWindows::NSynchronization::CManualResetEvent _createDialogEvent;
\r
259 NWindows::NSynchronization::CManualResetEvent _dialogCreatedEvent;
\r
261 void AddToTitle(LPCWSTR string);
\r
264 void SetPauseText();
\r
265 void SetPriorityText();
\r
266 void OnPauseButton();
\r
267 void OnPriorityButton();
\r
268 bool OnButtonClicked(int buttonID, HWND buttonHWND);
\r
270 void SetTitleText();
\r
271 void ShowSize(int id, UInt64 value);
\r
273 void UpdateMessagesDialog();
\r
275 void AddMessageDirect(LPCWSTR message);
\r
276 void AddMessage(LPCWSTR message);
\r
278 bool OnExternalCloseMessage();
\r
279 void EnableErrorsControls(bool enable);
\r
281 void ShowAfterMessages(HWND wndParent);
\r
283 void CheckNeedClose();
\r
285 CProgressSync Sync;
\r
286 bool CompressingMode;
\r
288 bool ShowCompressionInfo;
\r
289 bool MessagesDisplayed; // = true if user pressed OK on all messages or there are no messages.
\r
295 UString MainAddTitle;
\r
296 ~CProgressDialog();
\r
300 void WaitCreating()
\r
302 _createDialogEvent.Set();
\r
303 _dialogCreatedEvent.Lock();
\r
307 INT_PTR Create(const UString &title, NWindows::CThread &thread, HWND wndParent = 0);
\r
310 virtual bool OnMessage(UINT message, WPARAM wParam, LPARAM lParam);
\r
312 void ProcessWasFinished();
\r
316 class CProgressCloser
\r
318 CProgressDialog *_p;
\r
320 CProgressCloser(CProgressDialog &p) : _p(&p) {}
\r
321 ~CProgressCloser() { _p->ProcessWasFinished(); }
\r
324 class CProgressThreadVirt
\r
327 UString ErrorMessage;
\r
328 UString ErrorPath1;
\r
329 UString ErrorPath2;
\r
331 UString OkMessageTitle;
\r
333 // error if any of HRESULT, ErrorMessage, ErrorPath
\r
334 virtual HRESULT ProcessVirt() = 0;
\r
338 bool ThreadFinishedOK; // if there is no fatal exception
\r
339 CProgressDialog ProgressDialog;
\r
341 static THREAD_FUNC_DECL MyThreadFunction(void *param)
\r
343 CProgressThreadVirt *p = (CProgressThreadVirt *)param;
\r
347 p->ThreadFinishedOK = true;
\r
349 catch (...) { p->Result = E_FAIL; }
\r
353 HRESULT Create(const UString &title, HWND parentWindow = 0);
\r
354 CProgressThreadVirt(): Result(E_FAIL), ThreadFinishedOK(false) {}
\r
357 UString HResultToMessage(HRESULT errorCode);
\r