Ignore:
Timestamp:
2001-06-13T11:02:50+12:00 (23 years ago)
Author:
cs025
Message:

Added better monitoring of installation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsinstaller/copyProgress.cpp

    r2073 r2534  
    2525    progressBar = (copyProgressBar *) GetWindowLong(window, GWL_USERDATA);
    2626    if (progressBar == NULL)
    27       { 
    28         MessageBox(0, "A", "A", MB_OK);
     27      {
     28        // TODO: error handling
    2929      }
    3030
     
    6363}
    6464
    65 copyProgressBar::copyProgressBar(unsigned long totalSize)
    66 {   this->total     = totalSize;
    67     this->copied    = 0;
     65copyProgressBar::copyProgressBar(unsigned long totalSize, unsigned long totalFiles)
     66{   this->total         = totalSize;
     67    this->totalFiles    = totalFiles;
     68    this->copied        = 0;
     69   this->copiedFiles = 0;
     70   this->showing        = false;
    6871}
    6972
    7073copyProgressBar::copyProgressBar()
    71 {   this->total     = 0;
    72     this->copied    = 0;
     74{   this->total         = 0;
     75    this->totalFiles  = 0;
     76    this->copied        = 0;
     77   this->copiedFiles    = 0;
     78   this->showing    = false;
    7379}
    7480
    75 void copyProgressBar::init(unsigned long totalSize)
    76 {   this->total     = totalSize;
    77     this->copied    = 0;
     81// just ensure everything is tidily terminated
     82copyProgressBar::~copyProgressBar()
     83{   this->close();
     84}
     85
     86void copyProgressBar::init(unsigned long totalSize, unsigned long totalFiles)
     87{   this->total         = totalSize;
     88    this->totalFiles    = totalFiles;
     89    this->copied        = 0;
     90   this->copiedFiles    = 0;
    7891}
    7992
    8093void copyProgressBar::done(unsigned long bytesDone)
    81 { unsigned int percent;
    82   this->copied += bytesDone;
     94{
     95    static char   progressText[100] = "Remaining: ";
     96   static int    progressTimePos  = strlen(progressText);
     97   double         seconds;
    8398
    84   percent =(this->copied  * 100 / this->total);
     99   // note the progress made by the extra bytes
     100    this->copied += bytesDone;
     101   this->copiedFiles += 1;
    85102
    86     SendMessage(this->progressBar, PBM_SETPOS, percent, 0L);
     103   // present the progress in the progress bar
     104    double percent = (double) this->copied / (double) this->total;
     105   percent = percent * 100;
     106    SendMessage(this->progressBar, PBM_SETPOS, (int) percent, 0L);
     107
     108   // present time remaining
     109   seconds = difftime(time(NULL), this->startTime);
     110   if (this->copied == 0)
     111   { return;
     112   }
     113   seconds = seconds * (double) (this->total - this->copied) / (double) this->copied;
     114
     115   sprintf(&progressText[progressTimePos], "%d:%02d %3.1fMb (%d files)", (int) (seconds / 60), ((int) seconds) % 60, double (this->total - this->copied) / (double) (1024 * 1024), this->totalFiles - this->copiedFiles);
     116   SetWindowText(this->progressTime, progressText);
     117}
     118
     119void copyProgressBar::done(unsigned long bytesDone, LPSTR message)
     120{
     121   this->done(bytesDone);
     122   this->message(message);
     123}
     124
     125void copyProgressBar::message(LPSTR message)
     126{   SetWindowText(this->progressText, message);
    87127}
    88128
     
    97137  gsInstall_getDesktopExt(&sx, &sy);
    98138
    99   dx = (sx - 200) >> 1;
    100   dy = (sy - 80) >> 1;
     139  dx = (sx - 400) >> 1;
     140  dy = (sy - 110) >> 1;
    101141
    102142
     143    // Create the parent to hold the progress elements
    103144    this->progressParent    = CreateWindowEx(   WS_EX_APPWINDOW, "CopyProgressBar",
    104145                                                                                "GreenStone Installer", WS_VISIBLE,
    105                                                                                     dx, dy, 200, 80,
     146                                                                                    dx, dy, 400, 110,
    106147                                          0, (HMENU) 0,
    107148                                                    app_instance, (void *) params);
     149    // Create the progress bar itself
    108150    this->progressBar   = CreateWindowEx(0, PROGRESS_CLASS, NULL, WS_CHILD | WS_VISIBLE,
    109                                                                          10, 30, 180, GetSystemMetrics(SM_CYVSCROLL),
     151                                                                         10, 60, 380, GetSystemMetrics(SM_CYVSCROLL),
    110152                                     this->progressParent, (HMENU) 0,
    111153                                         app_instance, NULL);
     154
     155    // Create the text reporter
     156   this->progressText = CreateWindowEx(0, "STATIC", "", WS_CHILD | SS_LEFT | WS_VISIBLE,
     157                                                10, 5, 380, 20,
     158                                       this->progressParent, (HMENU) 0,
     159                                       app_instance, NULL);
     160
     161   // Create the time reporter
     162   this->progressTime = CreateWindowEx(0, "STATIC", "", WS_CHILD | SS_LEFT | WS_VISIBLE,
     163                                                10, 30, 380, 20,
     164                                       this->progressParent, (HMENU) 0,
     165                                       app_instance, NULL);
     166
     167    // Note that we are now showing the progress bar
     168    this->showing = true;
    112169}
    113170
     171// ensure that if the windows are showing, they are closed before the object
     172// is destroyed
    114173void copyProgressBar::close()
    115 { // return;
    116     ShowWindow(this->progressBar, SW_HIDE);
    117     DestroyWindow(this->progressBar);
     174{   if (this->showing == true)
     175   {
     176        ShowWindow(this->progressBar, SW_HIDE);
     177        DestroyWindow(this->progressBar);
    118178
    119   ShowWindow(this->progressParent, SW_HIDE);
    120   DestroyWindow(this->progressParent);
     179    ShowWindow(this->progressParent, SW_HIDE);
     180        DestroyWindow(this->progressParent);
     181      this->showing = false;
     182   }
    121183}
    122184
Note: See TracChangeset for help on using the changeset viewer.