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

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
        !             5:    contained in this file are Copyright (c) 2004-2005 TrueCrypt Foundation and
        !             6:    Copyright (c) 2004 TrueCrypt Team, and are covered by TrueCrypt License 2.0
        !             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.6 ! root       24: static wchar_t *minute, *minutes, *hours, *days;
        !            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.6 ! root       33:        minutes = GetString ("MINUTES");
        !            34:        hours = GetString ("HOURS");
        !            35:        days = GetString ("DAYS");
        !            36: 
1.1       root       37:        prevTime = startTime = GetTickCount ();
                     38:        totalSectors = totalSecs;
                     39: }
                     40: 
                     41: BOOL
1.1.1.3   root       42: UpdateProgressBar (__int64 nSecNo)
1.1       root       43: {
1.1.1.6 ! root       44:        wchar_t text[100];
        !            45:        wchar_t speed[100];
1.1       root       46:        HWND hProgressBar = GetDlgItem (hCurPage, nPbar);
                     47:        int time = GetTickCount ();
                     48:        int elapsed = (time - startTime) / 1000;
1.1.1.6 ! root       49:        unsigned __int64 bytesDone = (nSecNo + 1) * SECTOR_SIZE;
        !            50:        unsigned __int64 bytesPerSec = bytesDone / (1 + elapsed);
1.1       root       51: 
1.1.1.6 ! root       52:        GetSizeString (bytesDone, text);
        !            53:        wcscat (text, L" ");
        !            54:        SetWindowTextW (GetDlgItem (hCurPage, IDC_BYTESWRITTEN), text);
        !            55: 
        !            56:        GetSpeedString (bytesPerSec, speed);
        !            57:        wcscat (speed, L" ");
        !            58:        SetWindowTextW (GetDlgItem (hCurPage, IDC_WRITESPEED), speed);
1.1       root       59: 
                     60:        if (nSecNo < totalSectors)
                     61:        {
1.1.1.6 ! root       62:                int sec = (int)((totalSectors  - nSecNo) / ((nSecNo + 1)/(elapsed + 1) + 1));
1.1.1.3   root       63: 
1.1.1.6 ! root       64:                if (sec >= 60 * 60 * 24 * 2)
        !            65:                        swprintf (text, L"%d %s ", sec / (60 * 24 * 60), days);
1.1.1.4   root       66:                else if (sec >= 120 * 60)
1.1.1.6 ! root       67:                        swprintf (text, L"%d %s ", sec / (60 * 60), hours);
1.1.1.4   root       68:                else if (sec >= 120)
1.1.1.6 ! root       69:                        swprintf (text, L"%d %s ", sec / 60, minutes);
1.1.1.3   root       70:                else
1.1.1.6 ! root       71:                        swprintf (text, L"%d s ", sec);
1.1.1.3   root       72: 
1.1.1.6 ! root       73:                SetWindowTextW (GetDlgItem (hCurPage, IDC_TIMEREMAIN), text);
1.1       root       74:        }
                     75: 
                     76:        prevTime = time;
                     77: 
                     78:        SendMessage (hProgressBar, PBM_SETPOS, (int) (10000.0 * nSecNo / totalSectors), 0);
                     79: 
                     80:        return bThreadCancel;
                     81: }

unix.superglobalmegacorp.com

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