Annotation of truecrypt/common/progress.c, revision 1.1.1.9

1.1.1.6   root        1: /* Legal Notice: The source code contained in this file has been derived from
                      2:    the source code of Encryption for the Masses 2.02a, which is Copyright (c)
                      3:    1998-99 Paul Le Roux and which is covered by the 'License Agreement for
                      4:    Encryption for the Masses'. Modifications and additions to that source code
1.1.1.8   root        5:    contained in this file are Copyright (c) 2004-2006 TrueCrypt Foundation and
1.1.1.9 ! root        6:    Copyright (c) 2004 TrueCrypt Team, and are covered by TrueCrypt License 2.1
1.1.1.6   root        7:    the full text of which is contained in the file License.txt included in
                      8:    TrueCrypt binary and source code distribution archives.  */
                      9: 
                     10: #include "Tcdefs.h"
                     11: #include "Language.h"
                     12: #include "Dlgcode.h"
                     13: #include "Progress.h"
1.1       root       14: #include "../format/resource.h"
                     15: 
                     16: extern HWND hCurPage;
                     17: extern HWND hProgressBar;
                     18: extern BOOL bThreadCancel;
                     19: extern int nPbar;
                     20: 
1.1.1.3   root       21: ULONG prevTime, startTime;
                     22: __int64 totalSectors;
1.1       root       23: 
1.1.1.7   root       24: static wchar_t *seconds, *minutes, *hours, *days;
1.1.1.6   root       25: 
1.1       root       26: void
1.1.1.3   root       27: InitProgressBar (__int64 totalSecs)
1.1       root       28: {
                     29:        HWND hProgressBar = GetDlgItem (hCurPage, nPbar);
                     30:        SendMessage (hProgressBar, PBM_SETRANGE32, 0, 10000);
                     31:        SendMessage (hProgressBar, PBM_SETSTEP, 1, 0);
                     32: 
1.1.1.7   root       33:        seconds = GetString ("SECONDS");
1.1.1.6   root       34:        minutes = GetString ("MINUTES");
                     35:        hours = GetString ("HOURS");
                     36:        days = GetString ("DAYS");
                     37: 
1.1       root       38:        prevTime = startTime = GetTickCount ();
                     39:        totalSectors = totalSecs;
                     40: }
                     41: 
                     42: BOOL
1.1.1.3   root       43: UpdateProgressBar (__int64 nSecNo)
1.1       root       44: {
1.1.1.6   root       45:        wchar_t text[100];
                     46:        wchar_t speed[100];
1.1       root       47:        HWND hProgressBar = GetDlgItem (hCurPage, nPbar);
                     48:        int time = GetTickCount ();
                     49:        int elapsed = (time - startTime) / 1000;
1.1.1.6   root       50:        unsigned __int64 bytesDone = (nSecNo + 1) * SECTOR_SIZE;
                     51:        unsigned __int64 bytesPerSec = bytesDone / (1 + elapsed);
1.1       root       52: 
1.1.1.6   root       53:        GetSizeString (bytesDone, text);
1.1.1.7   root       54:        if (bytesDone < (unsigned __int64) BYTES_PER_MB * 1000000)
                     55:                swprintf(text, L"%I64d %s ", bytesDone / BYTES_PER_MB, GetString ("MB"));
                     56:        else if (bytesDone < (unsigned __int64) BYTES_PER_GB * 1000000)
                     57:                swprintf(text, L"%I64d %s ", bytesDone / BYTES_PER_GB, GetString ("GB"));
                     58:        else if (bytesDone < (unsigned __int64) BYTES_PER_TB * 1000000)
                     59:                swprintf(text, L"%I64d %s ", bytesDone / BYTES_PER_TB, GetString ("TB"));
                     60:        else
                     61:                swprintf(text, L"%I64d %s ", bytesDone / BYTES_PER_PB, GetString ("PB"));
                     62: 
1.1.1.6   root       63:        SetWindowTextW (GetDlgItem (hCurPage, IDC_BYTESWRITTEN), text);
                     64: 
                     65:        GetSpeedString (bytesPerSec, speed);
                     66:        wcscat (speed, L" ");
                     67:        SetWindowTextW (GetDlgItem (hCurPage, IDC_WRITESPEED), speed);
1.1       root       68: 
                     69:        if (nSecNo < totalSectors)
                     70:        {
1.1.1.6   root       71:                int sec = (int)((totalSectors  - nSecNo) / ((nSecNo + 1)/(elapsed + 1) + 1));
1.1.1.3   root       72: 
1.1.1.6   root       73:                if (sec >= 60 * 60 * 24 * 2)
                     74:                        swprintf (text, L"%d %s ", sec / (60 * 24 * 60), days);
1.1.1.4   root       75:                else if (sec >= 120 * 60)
1.1.1.6   root       76:                        swprintf (text, L"%d %s ", sec / (60 * 60), hours);
1.1.1.4   root       77:                else if (sec >= 120)
1.1.1.6   root       78:                        swprintf (text, L"%d %s ", sec / 60, minutes);
1.1.1.3   root       79:                else
1.1.1.7   root       80:                        swprintf (text, L"%d %s ", sec, seconds);
1.1.1.3   root       81: 
1.1.1.6   root       82:                SetWindowTextW (GetDlgItem (hCurPage, IDC_TIMEREMAIN), text);
1.1       root       83:        }
                     84: 
                     85:        prevTime = time;
                     86: 
                     87:        SendMessage (hProgressBar, PBM_SETPOS, (int) (10000.0 * nSecNo / totalSectors), 0);
                     88: 
                     89:        return bThreadCancel;
                     90: }
1.1.1.7   root       91: 
                     92: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.