1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
|
// ProgressDialog2.h
#ifndef __PROGRESS_DIALOG2_H
#define __PROGRESS_DIALOG2_H
#include "Windows/Synchronization.h"
#include "Windows/Thread.h"
#include "Windows/Control/Dialog.h"
#include "Windows/Control/ListView.h"
#include "Windows/Control/ProgressBar.h"
class CProgressSync
{
bool _stopped;
bool _paused;
bool _bytesProgressMode;
UInt64 _totalBytes;
UInt64 _curBytes;
UInt64 _totalFiles;
UInt64 _curFiles;
UInt64 _inSize;
UInt64 _outSize;
UString _titleFileName;
UString _currentFileName;
public:
UStringVector Messages;
UString ErrorMessage;
UString ErrorMessageTitle;
UString OkMessage;
UString OkMessageTitle;
NWindows::NSynchronization::CCriticalSection _cs;
CProgressSync():
_stopped(false), _paused(false),
_totalBytes((UInt64)(Int64)-1), _curBytes(0),
_totalFiles((UInt64)(Int64)-1), _curFiles(0),
_inSize((UInt64)(Int64)-1),
_outSize((UInt64)(Int64)-1),
_bytesProgressMode(true)
{}
bool GetStopped()
{
NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
return _stopped;
}
void SetStopped(bool value)
{
NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
_stopped = value;
}
bool GetPaused()
{
NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
return _paused;
}
void SetPaused(bool value)
{
NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
_paused = value;
}
void SetBytesProgressMode(bool bytesProgressMode)
{
NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
_bytesProgressMode = bytesProgressMode;
}
void SetProgress(UInt64 total, UInt64 completed)
{
NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
_totalBytes = total;
_curBytes = completed;
}
void SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)
{
NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
if (inSize)
_inSize = *inSize;
if (outSize)
_outSize = *outSize;
}
void SetPos(UInt64 completed)
{
NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
_curBytes = completed;
}
void SetNumBytesTotal(UInt64 value)
{
NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
_totalBytes = value;
}
void SetNumFilesTotal(UInt64 value)
{
NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
_totalFiles = value;
}
void SetNumFilesCur(UInt64 value)
{
NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
_curFiles = value;
}
HRESULT ProcessStopAndPause();
HRESULT SetPosAndCheckPaused(UInt64 completed);
void GetProgress(UInt64 &total, UInt64 &completed,
UInt64 &totalFiles, UInt64 &curFiles,
UInt64 &inSize, UInt64 &outSize,
bool &bytesProgressMode)
{
NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
total = _totalBytes;
completed = _curBytes;
totalFiles = _totalFiles;
curFiles = _curFiles;
inSize = _inSize;
outSize = _outSize;
bytesProgressMode = _bytesProgressMode;
}
void SetTitleFileName(const UString &fileName)
{
NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
_titleFileName = fileName;
}
void GetTitleFileName(UString &fileName)
{
NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
fileName = _titleFileName;
}
void SetCurrentFileName(const UString &fileName)
{
NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
_currentFileName = fileName;
}
void GetCurrentFileName(UString &fileName)
{
NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
fileName = _currentFileName;
}
void AddErrorMessage(LPCWSTR message)
{
NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
Messages.Add(message);
}
void SetErrorMessage(const UString &message)
{
NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
ErrorMessage = message;
}
void SetOkMessage(const UString &message)
{
NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
OkMessage = message;
}
void SetOkMessageTitle(const UString &title)
{
NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
OkMessageTitle = title;
}
void SetErrorMessageTitle(const UString &title)
{
NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
ErrorMessageTitle = title;
}
bool ThereIsMessage() const
{
return !Messages.IsEmpty() || !ErrorMessage.IsEmpty() || !OkMessage.IsEmpty();
}
};
class CU64ToI32Converter
{
UInt64 _numShiftBits;
public:
void Init(UInt64 range)
{
// Windows CE doesn't like big number here.
for (_numShiftBits = 0; range > (1 << 15); _numShiftBits++)
range >>= 1;
}
int Count(UInt64 value) { return int(value >> _numShiftBits); }
};
enum ESpeedMode
{
kSpeedBytes,
kSpeedKBytes,
kSpeedMBytes
};
class CProgressDialog: public NWindows::NControl::CModalDialog
{
UString _prevFileName;
UString _prevTitleName;
private:
UString backgroundString;
UString backgroundedString;
UString foregroundString;
UString pauseString;
UString continueString;
UString pausedString;
int buttonSizeX;
int buttonSizeY;
UINT_PTR _timer;
UString _title;
CU64ToI32Converter _converter;
UInt64 _previousPos;
UInt64 _range;
NWindows::NControl::CProgressBar m_ProgressBar;
// FIXME NWindows::NControl::CListView _messageList;
UInt32 _prevPercentValue;
UInt32 _prevTime;
UInt32 _elapsedTime;
UInt32 _prevElapsedSec;
UInt64 _prevRemainingSec;
ESpeedMode _prevMode;
UInt64 _prevSpeed;
bool _foreground;
int _numReduceSymbols;
bool _wasCreated;
bool _needClose;
UInt32 _numPostedMessages;
UInt32 _numAutoSizeMessages;
bool _errorsWereDisplayed;
bool _waitCloseByCancelButton;
bool _cancelWasPressed;
bool _inCancelMessageBox;
bool _externalCloseMessageWasReceived;
void UpdateStatInfo(bool showAll);
bool OnTimer(WPARAM timerID, LPARAM callback);
void SetRange(UInt64 range);
void SetPos(UInt64 pos);
virtual bool OnInit();
virtual bool OnSize(WPARAM wParam, int xSize, int ySize);
virtual void OnCancel();
virtual void OnOK();
NWindows::NSynchronization::CManualResetEvent _createDialogEvent;
NWindows::NSynchronization::CManualResetEvent _dialogCreatedEvent;
#ifndef _SFX
void AddToTitle(LPCWSTR string);
#endif
void SetPauseText();
void SetPriorityText();
void OnPauseButton();
void OnPriorityButton();
bool OnButtonClicked(int buttonID, HWND buttonHWND);
void SetTitleText();
void ShowSize(int id, UInt64 value);
void UpdateMessagesDialog();
void AddMessageDirect(LPCWSTR message);
void AddMessage(LPCWSTR message);
bool OnExternalCloseMessage();
void EnableErrorsControls(bool enable);
void ShowAfterMessages(HWND wndParent);
void CheckNeedClose();
public:
CProgressSync Sync;
bool CompressingMode;
// FIXME - not supported bool WaitMode;
bool ShowCompressionInfo;
bool MessagesDisplayed; // = true if user pressed OK on all messages or there are no messages.
int IconID;
#ifndef _SFX
HWND MainWindow;
UString MainTitle;
UString MainAddTitle;
~CProgressDialog();
#endif
CProgressDialog();
void WaitCreating()
{
_createDialogEvent.Set();
_dialogCreatedEvent.Lock();
}
INT_PTR Create(const UString &title, NWindows::CThread &thread, HWND wndParent = 0);
virtual bool OnMessage(UINT message, WPARAM wParam, LPARAM lParam);
void ProcessWasFinished();
};
class CProgressCloser
{
CProgressDialog *_p;
public:
CProgressCloser(CProgressDialog &p) : _p(&p) {}
~CProgressCloser() { _p->ProcessWasFinished(); }
};
class CProgressThreadVirt
{
protected:
UString ErrorMessage;
UString ErrorPath1;
UString ErrorPath2;
UString OkMessage;
UString OkMessageTitle;
// error if any of HRESULT, ErrorMessage, ErrorPath
virtual HRESULT ProcessVirt() = 0;
void Process();
public:
HRESULT Result;
bool ThreadFinishedOK; // if there is no fatal exception
CProgressDialog ProgressDialog;
static THREAD_FUNC_DECL MyThreadFunction(void *param)
{
CProgressThreadVirt *p = (CProgressThreadVirt *)param;
try
{
p->Process();
p->ThreadFinishedOK = true;
}
catch (...) { p->Result = E_FAIL; }
return 0;
}
HRESULT Create(const UString &title, HWND parentWindow = 0);
CProgressThreadVirt(): Result(E_FAIL), ThreadFinishedOK(false) {}
};
UString HResultToMessage(HRESULT errorCode);
#endif
|