This commit is contained in:
Igor Pavlov
2005-05-30 00:00:00 +00:00
committed by Kornel Lesiński
parent 8c1b5c7b7e
commit 3c510ba80b
926 changed files with 40559 additions and 23519 deletions

View File

@@ -29,6 +29,20 @@ static CIDLangPair kIDLangPairs[] =
};
#endif
HRESULT CProgressSynch::SetPosAndCheckPaused(UInt64 completed)
{
while(true)
{
if(GetStopped())
return E_ABORT;
if(!GetPaused())
break;
::Sleep(100);
}
SetPos(completed);
return S_OK;
}
#ifndef _SFX
CProgressDialog::~CProgressDialog()
{
@@ -42,17 +56,26 @@ void CProgressDialog::AddToTitle(LPCWSTR s)
window.SetText(s + UString(MainTitle));
}
}
static const int kTitleFileNameSizeLimit = 36;
static const int kCurrentFileNameSizeLimit = 68;
static void ReduceString(UString &s, int size)
{
if (s.Length() > size)
s = s.Left(size / 2) + UString(L" ... ") + s.Right(size / 2);
}
#endif
bool CProgressDialog::OnInit()
{
_range = UINT64(-1);
_prevPercentValue = UINT32(-1);
_prevElapsedSec = UINT32(-1);
_prevRemainingSec = UINT32(-1);
_prevSpeed = UINT32(-1);
_range = UInt64(-1);
_prevPercentValue = UInt32(-1);
_prevElapsedSec = UInt32(-1);
_prevRemainingSec = UInt32(-1);
_prevSpeed = UInt32(-1);
_prevMode = kSpeedBytes;
_pevTime = ::GetTickCount();
_prevTime = ::GetTickCount();
_elapsedTime = 0;
_foreground = true;
@@ -88,35 +111,35 @@ void CProgressDialog::OnCancel()
ProgressSynch.SetStopped(true);
}
static void ConvertSizeToString(UINT64 value, wchar_t *s)
static void ConvertSizeToString(UInt64 value, wchar_t *s)
{
if (value < (UINT64(10000) << 0))
if (value < (UInt64(10000) << 0))
{
ConvertUINT64ToString(value, s);
ConvertUInt64ToString(value, s);
lstrcatW(s, L" B");
return;
}
if (value < (UINT64(10000) << 10))
if (value < (UInt64(10000) << 10))
{
ConvertUINT64ToString((value >> 10), s);
ConvertUInt64ToString((value >> 10), s);
lstrcatW(s, L" KB");
return;
}
if (value < (UINT64(10000) << 20))
if (value < (UInt64(10000) << 20))
{
ConvertUINT64ToString((value >> 20), s);
ConvertUInt64ToString((value >> 20), s);
lstrcatW(s, L" MB");
return;
}
ConvertUINT64ToString((value >> 30), s);
ConvertUInt64ToString((value >> 30), s);
lstrcatW(s, L" GB");
return;
}
void CProgressDialog::SetRange(UINT64 range)
void CProgressDialog::SetRange(UInt64 range)
{
_range = range;
_previousPos = _UI64_MAX;
_previousPos = (UInt64)(Int64)-1;
_converter.Init(range);
m_ProgressBar.SetRange32(0 , _converter.Count(range)); // Test it for 100%
@@ -125,7 +148,7 @@ void CProgressDialog::SetRange(UINT64 range)
SetItemText(IDC_PROGRESS_SPEED_TOTAL_VALUE, s);
}
void CProgressDialog::SetPos(UINT64 pos)
void CProgressDialog::SetPos(UInt64 pos)
{
bool redraw = true;
if (pos < _range && pos > _previousPos)
@@ -140,31 +163,31 @@ void CProgressDialog::SetPos(UINT64 pos)
}
}
static void GetTimeString(UINT64 timeValue, TCHAR *s)
static void GetTimeString(UInt64 timeValue, TCHAR *s)
{
wsprintf(s, TEXT("%02d:%02d:%02d"),
UINT32(timeValue / 3600),
UINT32((timeValue / 60) % 60),
UINT32(timeValue % 60));
UInt32(timeValue / 3600),
UInt32((timeValue / 60) % 60),
UInt32(timeValue % 60));
}
bool CProgressDialog::OnTimer(WPARAM timerID, LPARAM callback)
{
if (ProgressSynch.GetPaused())
return true;
UINT64 total, completed;
UInt64 total, completed;
ProgressSynch.GetProgress(total, completed);
UINT32 curTime = ::GetTickCount();
UInt32 curTime = ::GetTickCount();
if (total != _range)
SetRange(total);
SetPos(completed);
_elapsedTime += (curTime - _pevTime);
_pevTime = curTime;
_elapsedTime += (curTime - _prevTime);
_prevTime = curTime;
UINT32 elapsedSec = _elapsedTime / 1000;
UInt32 elapsedSec = _elapsedTime / 1000;
bool elapsedChanged = false;
if (elapsedSec != _prevElapsedSec)
@@ -178,10 +201,10 @@ bool CProgressDialog::OnTimer(WPARAM timerID, LPARAM callback)
if (completed != 0 && elapsedChanged)
{
UINT64 remainingTime = 0;
UInt64 remainingTime = 0;
if (completed < total)
remainingTime = _elapsedTime * (total - completed) / completed;
UINT64 remainingSec = remainingTime / 1000;
UInt64 remainingSec = remainingTime / 1000;
if (remainingSec != _prevRemainingSec)
{
TCHAR s[40];
@@ -191,17 +214,17 @@ bool CProgressDialog::OnTimer(WPARAM timerID, LPARAM callback)
}
// if (elapsedChanged)
{
UINT64 speedB = (completed * 1000) / _elapsedTime;
UINT64 speedKB = speedB / 1024;
UINT64 speedMB = speedKB / 1024;
const UINT32 kLimit1 = 10;
UInt64 speedB = (completed * 1000) / _elapsedTime;
UInt64 speedKB = speedB / 1024;
UInt64 speedMB = speedKB / 1024;
const UInt32 kLimit1 = 10;
TCHAR s[40];
bool needRedraw = false;
if (speedMB >= kLimit1)
{
if (_prevMode != kSpeedMBytes || speedMB != _prevSpeed)
{
ConvertUINT64ToString(speedMB, s);
ConvertUInt64ToString(speedMB, s);
lstrcat(s, TEXT(" MB/s"));
_prevMode = kSpeedMBytes;
_prevSpeed = speedMB;
@@ -212,7 +235,7 @@ bool CProgressDialog::OnTimer(WPARAM timerID, LPARAM callback)
{
if (_prevMode != kSpeedKBytes || speedKB != _prevSpeed)
{
ConvertUINT64ToString(speedKB, s);
ConvertUInt64ToString(speedKB, s);
lstrcat(s, TEXT(" KB/s"));
_prevMode = kSpeedKBytes;
_prevSpeed = speedKB;
@@ -223,7 +246,7 @@ bool CProgressDialog::OnTimer(WPARAM timerID, LPARAM callback)
{
if (_prevMode != kSpeedBytes || speedB != _prevSpeed)
{
ConvertUINT64ToString(speedB, s);
ConvertUInt64ToString(speedB, s);
lstrcat(s, TEXT(" B/s"));
_prevMode = kSpeedBytes;
_prevSpeed = speedB;
@@ -237,24 +260,24 @@ bool CProgressDialog::OnTimer(WPARAM timerID, LPARAM callback)
if (total == 0)
total = 1;
UINT32 percentValue = (UINT32)(completed * 100 / total);
if (percentValue != _prevPercentValue)
UInt32 percentValue = (UInt32)(completed * 100 / total);
UString titleName;
ProgressSynch.GetTitleFileName(titleName);
if (percentValue != _prevPercentValue || _prevTitleName != titleName)
{
wchar_t s[64];
ConvertUINT64ToString(percentValue, s);
UString title = s;
title += L"% ";
if (!_foreground)
{
title += backgroundedString;
title += L" ";
}
SetText(title + _title);
#ifndef _SFX
AddToTitle(title + MainAddTitle);
#endif
_prevPercentValue = percentValue;
SetTitleText();
_prevTitleName = titleName;
}
UString fileName;
ProgressSynch.GetCurrentFileName(fileName);
if (_prevFileName != fileName)
{
ReduceString(fileName, kCurrentFileNameSizeLimit);
SetItemText(IDC_PROGRESS_FILE_NAME, fileName);
_prevFileName == fileName;
}
return true;
}
@@ -262,9 +285,9 @@ bool CProgressDialog::OnTimer(WPARAM timerID, LPARAM callback)
////////////////////
// CU64ToI32Converter
static const UINT64 kMaxIntValue = 0x7FFFFFFF;
static const UInt64 kMaxIntValue = 0x7FFFFFFF;
void CU64ToI32Converter::Init(UINT64 range)
void CU64ToI32Converter::Init(UInt64 range)
{
_numShiftBits = 0;
while(range > kMaxIntValue)
@@ -274,7 +297,7 @@ void CU64ToI32Converter::Init(UINT64 range)
}
}
int CU64ToI32Converter::Count(UINT64 aValue)
int CU64ToI32Converter::Count(UInt64 aValue)
{
return int(aValue >> _numShiftBits);
}
@@ -301,23 +324,54 @@ bool CProgressDialog::OnMessage(UINT message, WPARAM wParam, LPARAM lParam)
return CModalDialog::OnMessage(message, wParam, lParam);
}
void CProgressDialog::SetTitleText()
{
UString title;
if (ProgressSynch.GetPaused())
{
title = pausedString;
title += L" ";
}
wchar_t s[64];
ConvertUInt64ToString(_prevPercentValue, s);
title += s;
title += L"%";
if (!_foreground)
{
title += L" ";
title += backgroundedString;
}
title += L" ";
UString totalTitle = title + _title;
UString fileName;
ProgressSynch.GetTitleFileName(fileName);
if (!fileName.IsEmpty())
{
ReduceString(fileName, kTitleFileNameSizeLimit);
totalTitle += L" ";
totalTitle += fileName;
}
SetText(totalTitle);
#ifndef _SFX
AddToTitle(title + MainAddTitle);
#endif
}
void CProgressDialog::SetPauseText()
{
SetItemText(IDC_BUTTON_PAUSE, ProgressSynch.GetPaused() ?
continueString : pauseString);
SetText(LangLoadStringW(IDS_PROGRESS_PAUSED, 0x02000C20) +
UString(L" ") + _title);
SetTitleText();
}
void CProgressDialog::OnPauseButton()
{
bool paused = !ProgressSynch.GetPaused();
ProgressSynch.SetPaused(paused);
UINT32 curTime = ::GetTickCount();
UInt32 curTime = ::GetTickCount();
if (paused)
_elapsedTime += (curTime - _pevTime);
_pevTime = curTime;
_elapsedTime += (curTime - _prevTime);
_prevTime = curTime;
SetPauseText();
}
@@ -326,6 +380,7 @@ void CProgressDialog::SetPriorityText()
SetItemText(IDC_BUTTON_PROGRESS_PRIORITY, _foreground ?
backgroundString :
foregroundString);
SetTitleText();
}
void CProgressDialog::OnPriorityButton()

View File

@@ -1,12 +1,12 @@
// ProgressDialog.h
#pragma once
#ifndef __PROGRESSDIALOG_H
#define __PROGRESSDIALOG_H
#include "resource.h"
#include "Common/Types.h"
#include "Windows/Control/Dialog.h"
#include "Windows/Control/ProgressBar.h"
#include "Windows/Synchronization.h"
@@ -16,8 +16,10 @@ class CProgressSynch
NWindows::NSynchronization::CCriticalSection _criticalSection;
bool _stopped;
bool _paused;
UINT64 _total;
UINT64 _completed;
UInt64 _total;
UInt64 _completed;
UString TitleFileName;
UString CurrentFileName;
public:
CProgressSynch(): _stopped(false), _paused(false), _total(1), _completed(0) {}
@@ -41,31 +43,52 @@ public:
NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection);
_paused = value;
}
void SetProgress(UINT64 total, UINT64 completed)
void SetProgress(UInt64 total, UInt64 completed)
{
NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection);
_total = total;
_completed = completed;
}
void SetPos(UINT64 completed)
void SetPos(UInt64 completed)
{
NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection);
_completed = completed;
}
void GetProgress(UINT64 &total, UINT64 &completed)
HRESULT SetPosAndCheckPaused(UInt64 completed);
void GetProgress(UInt64 &total, UInt64 &completed)
{
NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection);
total = _total;
completed = _completed;
}
void SetTitleFileName(const UString &fileName)
{
NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection);
TitleFileName = fileName;
}
void GetTitleFileName(UString &fileName)
{
NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection);
fileName = TitleFileName;
}
void SetCurrentFileName(const UString &fileName)
{
NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection);
CurrentFileName = fileName;
}
void GetCurrentFileName(UString &fileName)
{
NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection);
fileName = CurrentFileName;
}
};
class CU64ToI32Converter
{
UINT64 _numShiftBits;
UInt64 _numShiftBits;
public:
void Init(UINT64 _range);
int Count(UINT64 aValue);
void Init(UInt64 _range);
int Count(UInt64 aValue);
};
// class CProgressDialog: public NWindows::NControl::CModelessDialog
@@ -79,6 +102,8 @@ enum ESpeedMode
class CProgressDialog: public NWindows::NControl::CModalDialog
{
UString _prevFileName;
UString _prevTitleName;
private:
UString backgroundString;
UString backgroundedString;
@@ -93,23 +118,23 @@ private:
UString _title;
CU64ToI32Converter _converter;
UINT64 _previousPos;
UINT64 _range;
UInt64 _previousPos;
UInt64 _range;
NWindows::NControl::CProgressBar m_ProgressBar;
UINT32 _prevPercentValue;
UINT32 _pevTime;
UINT32 _elapsedTime;
UINT32 _prevElapsedSec;
UINT64 _prevRemainingSec;
UInt32 _prevPercentValue;
UInt32 _prevTime;
UInt32 _elapsedTime;
UInt32 _prevElapsedSec;
UInt64 _prevRemainingSec;
ESpeedMode _prevMode;
UINT64 _prevSpeed;
UInt64 _prevSpeed;
bool _foreground;
bool OnTimer(WPARAM timerID, LPARAM callback);
void SetRange(UINT64 range);
void SetPos(UINT64 pos);
void SetRange(UInt64 range);
void SetPos(UInt64 pos);
virtual bool OnInit();
virtual void OnCancel();
NWindows::NSynchronization::CManualResetEvent _dialogCreatedEvent;
@@ -122,6 +147,8 @@ private:
void OnPauseButton();
void OnPriorityButton();
bool OnButtonClicked(int buttonID, HWND buttonHWND);
void SetTitleText();
public:
CProgressSynch ProgressSynch;
@@ -134,7 +161,7 @@ public:
CProgressDialog(): _timer(0)
#ifndef _SFX
,MainWindow(0)
,MainWindow(0)
#endif
{}
@@ -151,10 +178,7 @@ public:
virtual bool OnMessage(UINT message, WPARAM wParam, LPARAM lParam);
void MyClose()
{
PostMessage(kCloseMessage);
};
void MyClose() { PostMessage(kCloseMessage); };
};
#endif

View File

@@ -5,6 +5,10 @@
#define IDC_BUTTON_PAUSE 3
#define IDC_BUTTON_PROGRESS_PRIORITY 4
#define IDD_DIALOG_PROGRESS 500
#define IDS_PROGRESS_PAUSED 700
#define IDS_PROGRESS_FOREGROUND 701
#define IDS_PROGRESS_CONTINUE 702
#define IDS_PROGRESS_ASK_CANCEL 703
#define IDC_PROGRESS1 1000
#define IDC_PROGRESS_ELAPSED 1002
#define IDC_PROGRESS_ELAPSED_VALUE 1003
@@ -14,11 +18,7 @@
#define IDC_PROGRESS_SPEED_VALUE 1007
#define IDC_PROGRESS_TOTAL 1008
#define IDC_PROGRESS_SPEED_TOTAL_VALUE 1009
#define IDS_PROGRESS_PAUSED 700
#define IDS_PROGRESS_FOREGROUND 701
#define IDS_PROGRESS_CONTINUE 702
#define IDS_PROGRESS_ASK_CANCEL 703
#define IDC_PROGRESS_FILE_NAME 1010
// Next default values for new objects
//

View File

@@ -63,25 +63,26 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
// Dialog
//
IDD_DIALOG_PROGRESS DIALOG DISCARDABLE 0, 0, 246, 78
IDD_DIALOG_PROGRESS DIALOG DISCARDABLE 0, 0, 304, 90
STYLE DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP |
WS_CAPTION | WS_SYSMENU
CAPTION "Progress"
FONT 8, "MS Shell Dlg"
BEGIN
PUSHBUTTON "&Background",IDC_BUTTON_PROGRESS_PRIORITY,7,57,72,14
PUSHBUTTON "&Pause",IDC_BUTTON_PAUSE,92,57,72,14
PUSHBUTTON "Cancel",IDCANCEL,175,57,64,14
LTEXT "Elapsed time:",IDC_PROGRESS_ELAPSED,7,7,71,8
RTEXT "00:00:00",IDC_PROGRESS_ELAPSED_VALUE,78,7,42,8
LTEXT "Remaining time:",IDC_PROGRESS_REMAINING,7,18,71,8
RTEXT "",IDC_PROGRESS_REMAINING_VALUE,78,18,42,8
LTEXT "Size:",IDC_PROGRESS_TOTAL,149,7,48,8
RTEXT "",IDC_PROGRESS_SPEED_TOTAL_VALUE,197,7,42,8
LTEXT "Speed:",IDC_PROGRESS_SPEED,149,18,48,8
RTEXT "",IDC_PROGRESS_SPEED_VALUE,197,18,42,8
PUSHBUTTON "&Background",IDC_BUTTON_PROGRESS_PRIORITY,61,69,72,14
PUSHBUTTON "&Pause",IDC_BUTTON_PAUSE,143,69,72,14
PUSHBUTTON "Cancel",IDCANCEL,225,69,72,14
LTEXT "Elapsed time:",IDC_PROGRESS_ELAPSED,7,7,91,8
RTEXT "00:00:00",IDC_PROGRESS_ELAPSED_VALUE,98,7,42,8
LTEXT "Remaining time:",IDC_PROGRESS_REMAINING,7,18,91,8
RTEXT "",IDC_PROGRESS_REMAINING_VALUE,98,18,42,8
LTEXT "Size:",IDC_PROGRESS_TOTAL,178,7,77,8
RTEXT "",IDC_PROGRESS_SPEED_TOTAL_VALUE,255,7,42,8
LTEXT "Speed:",IDC_PROGRESS_SPEED,178,18,77,8
RTEXT "",IDC_PROGRESS_SPEED_VALUE,255,18,42,8
CONTROL "Progress1",IDC_PROGRESS1,"msctls_progress32",PBS_SMOOTH |
WS_BORDER,7,34,232,13
WS_BORDER,7,49,290,13
LTEXT "",IDC_PROGRESS_FILE_NAME,7,34,290,8
END
@@ -96,13 +97,13 @@ BEGIN
IDD_DIALOG_PROGRESS, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 239
VERTGUIDE, 78
VERTGUIDE, 120
VERTGUIDE, 149
VERTGUIDE, 197
RIGHTMARGIN, 297
VERTGUIDE, 98
VERTGUIDE, 140
VERTGUIDE, 178
VERTGUIDE, 255
TOPMARGIN, 7
BOTTOMMARGIN, 71
BOTTOMMARGIN, 83
END
END
#endif // APSTUDIO_INVOKED