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

1.1.1.10  root        1: /*
1.1.1.12  root        2:  Legal Notice: Some portions of the source code contained in this file were
                      3:  derived from the source code of Encryption for the Masses 2.02a, which is
                      4:  Copyright (c) 1998-2000 Paul Le Roux and which is governed by the 'License
                      5:  Agreement for Encryption for the Masses'. Modifications and additions to
                      6:  the original source code (contained in this file) and all other portions of
                      7:  this file are Copyright (c) 2003-2008 TrueCrypt Foundation and are governed
1.1.1.14! root        8:  by the TrueCrypt License 2.6 the full text of which is contained in the
1.1.1.12  root        9:  file License.txt included in TrueCrypt binary and source code distribution
1.1.1.10  root       10:  packages. */
1.1.1.6   root       11: 
                     12: #include "Tcdefs.h"
                     13: #include "Language.h"
                     14: #include "Dlgcode.h"
                     15: #include "Progress.h"
1.1.1.12  root       16: #include "../Format/Tcformat.h"
1.1.1.10  root       17: #include "../Format/FormatCom.h"
                     18: #include "../Format/resource.h"
1.1       root       19: 
1.1.1.3   root       20: ULONG prevTime, startTime;
                     21: __int64 totalSectors;
1.1.1.12  root       22: __int64 resumedPointBytesDone;
                     23: BOOL bProgressBarReverse = FALSE;
                     24: BOOL bRWThroughput = FALSE;
                     25: BOOL bShowStatus = FALSE;
                     26: BOOL bPercentMode = FALSE;
1.1       root       27: 
1.1.1.7   root       28: static wchar_t *seconds, *minutes, *hours, *days;
1.1.1.6   root       29: 
1.1.1.12  root       30: 
                     31: // If bIOThroughput is TRUE, the speed reflects the amount of data read AND written per second (rather than
                     32: // the speed of the "transform cursor").
                     33: void InitProgressBar (__int64 totalSecs, __int64 bytesDone, BOOL bReverse, BOOL bIOThroughput, BOOL bDisplayStatus, BOOL bShowPercent)
1.1       root       34: {
                     35:        HWND hProgressBar = GetDlgItem (hCurPage, nPbar);
                     36:        SendMessage (hProgressBar, PBM_SETRANGE32, 0, 10000);
                     37:        SendMessage (hProgressBar, PBM_SETSTEP, 1, 0);
                     38: 
1.1.1.12  root       39:        bProgressBarReverse = bReverse;
                     40:        bRWThroughput = bIOThroughput;
                     41:        bShowStatus = bDisplayStatus;
                     42:        bPercentMode = bShowPercent;
                     43: 
1.1.1.7   root       44:        seconds = GetString ("SECONDS");
1.1.1.6   root       45:        minutes = GetString ("MINUTES");
                     46:        hours = GetString ("HOURS");
                     47:        days = GetString ("DAYS");
                     48: 
1.1       root       49:        prevTime = startTime = GetTickCount ();
                     50:        totalSectors = totalSecs;
1.1.1.12  root       51:        resumedPointBytesDone = bytesDone;
1.1       root       52: }
                     53: 
1.1.1.10  root       54: 
1.1.1.12  root       55: BOOL UpdateProgressBar (__int64 nSecNo)
1.1       root       56: {
1.1.1.10  root       57:        return UpdateProgressBarProc (nSecNo);
                     58: }
                     59: 
                     60: 
1.1.1.12  root       61: BOOL UpdateProgressBarProc (__int64 nSecNo)
1.1.1.10  root       62: {
1.1.1.6   root       63:        wchar_t text[100];
                     64:        wchar_t speed[100];
1.1       root       65:        HWND hProgressBar = GetDlgItem (hCurPage, nPbar);
                     66:        int time = GetTickCount ();
                     67:        int elapsed = (time - startTime) / 1000;
                     68: 
1.1.1.12  root       69:        unsigned __int64 bytesDone = (bProgressBarReverse ? ((totalSectors - nSecNo + 1) * SECTOR_SIZE) : ((nSecNo + 1) * SECTOR_SIZE));
                     70:        unsigned __int64 bytesPerSec = (bProgressBarReverse ? (resumedPointBytesDone - nSecNo * SECTOR_SIZE + 1) : (bytesDone - resumedPointBytesDone + 1)) / (elapsed + 1);
                     71: 
                     72:        if (bPercentMode)
                     73:        {
                     74:                double perc = (double) (100.0 * (bProgressBarReverse ? ((double) (totalSectors - nSecNo)) : ((double) nSecNo)) / (totalSectors == 0 ? 0.0001 : ((double) totalSectors)));
                     75: 
                     76:                if (perc > 99.999999999)
                     77:                        wcscpy (text, GetString ("PROCESSED_PORTION_100_PERCENT"));
                     78:                else
                     79:                        _snwprintf (text, sizeof text/2, GetString ("PROCESSED_PORTION_X_PERCENT"), perc);
                     80: 
                     81:                wcscat (speed, L" ");
                     82:        }
1.1.1.7   root       83:        else
1.1.1.12  root       84:        {
                     85:                GetSizeString (bytesDone, text);
                     86:                if (bytesDone < (unsigned __int64) BYTES_PER_MB * 1000000)
                     87:                        swprintf(text, L"%I64d %s ", bytesDone / BYTES_PER_MB, GetString ("MB"));
                     88:                else if (bytesDone < (unsigned __int64) BYTES_PER_GB * 1000000)
                     89:                        swprintf(text, L"%I64d %s ", bytesDone / BYTES_PER_GB, GetString ("GB"));
                     90:                else if (bytesDone < (unsigned __int64) BYTES_PER_TB * 1000000)
                     91:                        swprintf(text, L"%I64d %s ", bytesDone / BYTES_PER_TB, GetString ("TB"));
                     92:                else
                     93:                        swprintf(text, L"%I64d %s ", bytesDone / BYTES_PER_PB, GetString ("PB"));
                     94:        }
1.1.1.7   root       95: 
1.1.1.6   root       96:        SetWindowTextW (GetDlgItem (hCurPage, IDC_BYTESWRITTEN), text);
                     97: 
1.1.1.12  root       98:        if (!bShowStatus)
                     99:        {
                    100:                GetSpeedString (bRWThroughput ? bytesPerSec*2 : bytesPerSec, speed);
                    101:                wcscat (speed, L" ");
                    102:                SetWindowTextW (GetDlgItem (hCurPage, IDC_WRITESPEED), speed);
                    103:        }
1.1       root      104: 
                    105:        if (nSecNo < totalSectors)
                    106:        {
1.1.1.12  root      107:                __int32 sec = (__int32)((bProgressBarReverse ? nSecNo : (totalSectors - nSecNo)) / ((bytesPerSec == 0 ? 0.00001 : bytesPerSec) / SECTOR_SIZE));
1.1.1.3   root      108: 
1.1.1.6   root      109:                if (sec >= 60 * 60 * 24 * 2)
                    110:                        swprintf (text, L"%d %s ", sec / (60 * 24 * 60), days);
1.1.1.4   root      111:                else if (sec >= 120 * 60)
1.1.1.6   root      112:                        swprintf (text, L"%d %s ", sec / (60 * 60), hours);
1.1.1.4   root      113:                else if (sec >= 120)
1.1.1.6   root      114:                        swprintf (text, L"%d %s ", sec / 60, minutes);
1.1.1.3   root      115:                else
1.1.1.7   root      116:                        swprintf (text, L"%d %s ", sec, seconds);
1.1.1.3   root      117: 
1.1.1.6   root      118:                SetWindowTextW (GetDlgItem (hCurPage, IDC_TIMEREMAIN), text);
1.1       root      119:        }
                    120: 
                    121:        prevTime = time;
                    122: 
1.1.1.12  root      123:        SendMessage (hProgressBar, PBM_SETPOS, 
                    124:                (int) (10000.0 * (bProgressBarReverse ? (totalSectors - nSecNo) : nSecNo) / (totalSectors == 0 ? 1 : totalSectors)),
                    125:                0);
1.1       root      126: 
1.1.1.14! root      127:        return bVolTransformThreadCancel;
1.1       root      128: }

unix.superglobalmegacorp.com

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