"Fossies" - the Fresh Open Source Software Archive

Member "src/Common/Progress.c" (10 Oct 2018, 5043 Bytes) of package /windows/misc/VeraCrypt_1.23-Hotfix-2_Source.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "Progress.c" see the Fossies "Dox" file reference documentation.

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