Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

dlgMultiCheck.cpp

Go to the documentation of this file.
00001 /* 00002 * wxChecksums 00003 * Copyright (C) 2003-2004 Julien Couot 00004 * 00005 * This program is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU General Public License 00007 * as published by the Free Software Foundation; either version 2 00008 * of the License, or (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 */ 00019 00020 /** 00021 * \file dlgMultiCheck.cpp 00022 * Dialog for checking multiple checksums' files. 00023 */ 00024 00025 00026 //--------------------------------------------------------------------------- 00027 // For compilers that support precompilation, includes "wx.h". 00028 #include <wx/wxprec.h> 00029 00030 #ifdef __BORLANDC__ 00031 #pragma hdrstop 00032 #endif 00033 00034 #ifndef WX_PRECOMP 00035 // Include your minimal set of headers here, or wx.h 00036 #include <wx/wx.h> 00037 #endif 00038 00039 #include <wx/config.h> 00040 #include <wx/datetime.h> 00041 #include <wx/file.h> 00042 #include <wx/filename.h> 00043 00044 #include <climits> 00045 00046 #include "dlgMultiCheck.hpp" 00047 #include "appprefs.hpp" 00048 #include "bytedisp.hpp" 00049 #include "checksum.hpp" 00050 #include "checksumutil.hpp" 00051 #include "comdefs.hpp" 00052 #include "fileutil.hpp" 00053 #include "osdep.hpp" 00054 #include "sumfile.hpp" 00055 #include "utils.hpp" 00056 00057 #include "compat.hpp" 00058 //--------------------------------------------------------------------------- 00059 00060 00061 /// The C++ standard namespace. 00062 using namespace std; 00063 00064 00065 IMPLEMENT_DYNAMIC_CLASS(dlgMultiCheck, dlgResultsProgress) 00066 00067 00068 //########################################################################### 00069 // dlgMultiCheck::FilesStatistics methods 00070 //########################################################################### 00071 00072 /** 00073 * Statistics on the files. 00074 */ 00075 class dlgMultiCheck::FilesStatistics 00076 { 00077 public: 00078 int CKTotallyCorrect; ///< Checksums' files totally corrects. 00079 int CKPartiallyCorrect; ///< Checksums' files partially corrects. 00080 int CKFullyIncorrect; ///< Checksums' files fully incorrects. 00081 int CKInvalid; ///< Invalids Checksums' files. 00082 int CKNotOpened; ///< Checksums' files not opened. 00083 00084 int FCorrect; ///< Correct checked files. 00085 int FIncorrect; ///< Incorrect checked files. 00086 int FNotFound; ///< Files not found. 00087 int FNotOpened; ///< Files not opened. 00088 00089 /// Constructor. 00090 FilesStatistics() 00091 { 00092 CKTotallyCorrect = 0; 00093 CKPartiallyCorrect = 0; 00094 CKFullyIncorrect = 0; 00095 CKInvalid = 0; 00096 CKNotOpened = 0; 00097 00098 resetCkFiles(); 00099 } 00100 00101 /// Reset checksums' file statics. 00102 void resetCkFiles() 00103 { 00104 FCorrect = 0; 00105 FIncorrect = 0; 00106 FNotFound = 0; 00107 FNotOpened = 0; 00108 } 00109 00110 /// Gets the total of checked files. 00111 int getCheckedFilesCount() const 00112 { 00113 return FCorrect + FIncorrect + FNotFound + FNotOpened; 00114 } 00115 00116 /// Gets the total of checksum's files checked. 00117 int getChecksumsFilesChecked() const 00118 { 00119 return CKTotallyCorrect + CKPartiallyCorrect + CKFullyIncorrect + CKInvalid + CKNotOpened; 00120 } 00121 00122 /// Says if all the files in the checksums' file are corrects. 00123 bool allAreCorrects() const 00124 { 00125 return FIncorrect == 0 && FNotFound == 0 && FNotOpened == 0; 00126 } 00127 00128 /// Says if all the checksums' files are corrects. 00129 bool allChecksumsFilesAreCorrects() const 00130 { 00131 return CKPartiallyCorrect == 0 && CKFullyIncorrect == 0 && CKInvalid == 0 && CKNotOpened == 0; 00132 } 00133 }; 00134 //--------------------------------------------------------------------------- 00135 00136 00137 00138 //########################################################################### 00139 // A progression updater for the ChecksumFileCalculator class 00140 //########################################################################### 00141 00142 /** 00143 * Displays the progression of the process of computing of a checksum. 00144 */ 00145 class dlgMultiCheck::ChecksumProgress : public ::ChecksumProgress 00146 { 00147 protected: 00148 BytesDisplayer current; ///< numbers of preceeded bytes. 00149 wxTimeSpan timeSpan; ///< Time between to updates of the progress dialog. 00150 wxDateTime lt; ///< Last saved time. 00151 wxDateTime ct; ///< Current time. 00152 dlgMultiCheck* progress; ///< Progress dialog (don't delete it!). 00153 00154 /// Default constructor. Don't call it. 00155 ChecksumProgress() { init(); }; 00156 00157 // Initializes the instance. 00158 void init(); 00159 00160 public: 00161 // Constructor. 00162 ChecksumProgress(dlgMultiCheck* progressDlg, const BytesDisplayer& total); 00163 00164 // Updates the progression of the computing of a checksum. 00165 virtual void update(size_t read, bool& canceled); 00166 00167 // Indicates that the process is finished (hides the progress dialog). 00168 void finished(); 00169 }; 00170 //--------------------------------------------------------------------------- 00171 00172 00173 /** 00174 * Initializes the instance. 00175 */ 00176 void dlgMultiCheck::ChecksumProgress::init() 00177 { 00178 progress = NULL; 00179 } 00180 //--------------------------------------------------------------------------- 00181 00182 00183 /** 00184 * Constructor. 00185 * 00186 * @param progressDlg Progress dialog to update. 00187 * @param total Total of bytes to process. 00188 */ 00189 dlgMultiCheck::ChecksumProgress::ChecksumProgress(dlgMultiCheck* progressDlg, const BytesDisplayer& total) 00190 { 00191 init(); 00192 00193 timeSpan = wxTimeSpan(0, 0, 0, UPDATE_PROGRESS_DLG); 00194 lt = wxDateTime::UNow() - timeSpan; 00195 progress = progressDlg; 00196 00197 // Display information 00198 progress->setReadBytes(current); 00199 progress->setTotalBytes(total); 00200 } 00201 //--------------------------------------------------------------------------- 00202 00203 00204 /** 00205 * Updates the progression of the computing of a checksum. 00206 * 00207 * @param read Number of bytes read. 00208 * @param canceled Set it to <CODE>true</CODE> if the user want to cancel 00209 * the calculation. The caller should call it with its value 00210 * set to <CODE>false</CODE>. 00211 */ 00212 void dlgMultiCheck::ChecksumProgress::update(size_t read, bool& canceled) 00213 { 00214 current += static_cast<unsigned long>(read); 00215 ct = wxDateTime::UNow(); 00216 if (ct.IsLaterThan(lt)) 00217 { 00218 progress->setReadBytes(current); 00219 ::wxYield(); 00220 lt = ct + timeSpan; 00221 } 00222 00223 // Pause ? 00224 while (progress->getState() == dlgMultiCheck::paused) 00225 ::wxYield(); 00226 00227 // Canceled ? 00228 if (progress->getState() == dlgMultiCheck::canceled) 00229 canceled = true; 00230 } 00231 //--------------------------------------------------------------------------- 00232 00233 00234 /** 00235 * Indicates that the process is finished (hides the progress dialog). 00236 */ 00237 void dlgMultiCheck::ChecksumProgress::finished() 00238 { 00239 progress->setReadBytes(current); 00240 ::wxYield(); 00241 } 00242 //--------------------------------------------------------------------------- 00243 00244 00245 00246 //########################################################################### 00247 // dlgMultiCheck methods 00248 //########################################################################### 00249 00250 00251 /// Gauges limits 00252 #define GAUGE_MAX SHRT_MAX 00253 00254 /// Gauges limits (double value) 00255 #define DGAUGE_MAX static_cast<double>(GAUGE_MAX) 00256 //--------------------------------------------------------------------------- 00257 00258 00259 /** 00260 * Creates a new dialog. 00261 */ 00262 dlgMultiCheck::dlgMultiCheck() : dlgResultsProgress() 00263 { 00264 winDisabler = NULL; 00265 createControls(); 00266 } 00267 //--------------------------------------------------------------------------- 00268 00269 00270 /** 00271 * Creates a new dialog. 00272 * 00273 * @param parent Parent of the dialog. 00274 */ 00275 dlgMultiCheck::dlgMultiCheck(wxWindow* parent) : 00276 dlgResultsProgress(parent, -1, _("Check multiple checksums' files"), 00277 wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) 00278 { 00279 createControls(); 00280 Fit(); 00281 00282 // Change the size of the dialog. 00283 wxSize s = AppPrefs::get()->readSize(prMC_WINDOW_SIZE); 00284 if (s.GetWidth() == -1 || s.GetHeight() == -1) 00285 { 00286 if (GetParent() != NULL) 00287 SetSize(GetParent()->GetSize()); 00288 } 00289 else 00290 SetSize(s); 00291 Centre(); 00292 00293 Show(true); 00294 Enable(true); 00295 ::wxYield(); 00296 #ifdef __WXMAC__ 00297 MacUpdateImmediately(); 00298 #endif 00299 } 00300 //--------------------------------------------------------------------------- 00301 00302 00303 /** 00304 * Creates and initializes the controls of the dialog. 00305 */ 00306 void dlgMultiCheck::createControls() 00307 { 00308 // Creates the controls 00309 wxClientDC dc(txtResults); 00310 wxSize labelSize(dc.GetCharWidth() * 20, -1); 00311 00312 wxStaticText* lblCurTotal = new wxStaticText(this, -1, _("Checking:")); 00313 lblTotal = new wxStaticText(this, -1, wxEmptyString, wxDefaultPosition, 00314 labelSize, wxALIGN_RIGHT | wxST_NO_AUTORESIZE); 00315 gauTotal = new wxGauge(this, -1, 0, wxDefaultPosition, wxSize(-1, lblTotal->GetSize().GetHeight()), 00316 wxGA_HORIZONTAL | wxGA_SMOOTH); 00317 gauTotal->SetRange(GAUGE_MAX); 00318 wxStaticText* lblCurChecksumFile = new wxStaticText(this, -1, _("In checksums' file:")); 00319 lblChecksumFile = new wxStaticText(this, -1, wxEmptyString, wxDefaultPosition, 00320 labelSize, wxALIGN_RIGHT | wxST_NO_AUTORESIZE); 00321 gauChecksumFile = new wxGauge(this, -1, 0, wxDefaultPosition, wxSize(-1, lblChecksumFile->GetSize().GetHeight()), 00322 wxGA_HORIZONTAL | wxGA_SMOOTH); 00323 gauChecksumFile->SetRange(GAUGE_MAX); 00324 wxStaticText* lblCurFile = new wxStaticText(this, -1, _("Current file:")); 00325 lblFile = new wxStaticText(this, -1, wxEmptyString, wxDefaultPosition, 00326 labelSize, wxALIGN_RIGHT | wxST_NO_AUTORESIZE); 00327 gauFile = new wxGauge(this, -1, 0, wxDefaultPosition, wxSize(-1, lblFile->GetSize().GetHeight()), 00328 wxGA_HORIZONTAL | wxGA_SMOOTH); 00329 gauFile->SetRange(GAUGE_MAX); 00330 00331 //------------------------------------------------------------------------- 00332 // Creates the dialog sizers 00333 00334 // Progress section 00335 wxFlexGridSizer* progressSizer = new wxFlexGridSizer(3, CONTROL_SPACE / 2, CONTROL_SPACE); 00336 infoSizer->Add(progressSizer, 0, wxTOP | wxGROW, 3 * CONTROL_SPACE / 2); 00337 progressSizer->AddGrowableCol(2); 00338 progressSizer->Add(lblCurTotal, 0, wxALIGN_CENTER_VERTICAL); 00339 progressSizer->Add(lblTotal, 0, wxALIGN_CENTER_VERTICAL); 00340 progressSizer->Add(gauTotal, 1, wxALIGN_CENTER_VERTICAL | wxGROW); 00341 progressSizer->Add(lblCurChecksumFile, 0, wxALIGN_CENTER_VERTICAL); 00342 progressSizer->Add(lblChecksumFile, 0, wxALIGN_CENTER_VERTICAL); 00343 progressSizer->Add(gauChecksumFile, 1, wxALIGN_CENTER_VERTICAL | wxGROW); 00344 progressSizer->Add(lblCurFile, 0, wxALIGN_CENTER_VERTICAL); 00345 progressSizer->Add(lblFile, 0, wxALIGN_CENTER_VERTICAL); 00346 progressSizer->Add(gauFile, 1, wxALIGN_CENTER_VERTICAL | wxGROW); 00347 00348 // Set on the auto-layout feature 00349 this->SetAutoLayout(true); 00350 this->Layout(); 00351 00352 00353 //------------------------------------------------------------------------- 00354 // Initializes the controls 00355 setFilesToCheck(0); 00356 setFilesInChecksumsFile(0); 00357 setTotalBytes(BytesDisplayer(0UL)); 00358 } 00359 //--------------------------------------------------------------------------- 00360 00361 00362 /** 00363 * Processes button Cancel. 00364 * 00365 * @param event The event's parameters 00366 */ 00367 void dlgMultiCheck::btnCancelClick(wxCommandEvent& event) 00368 { 00369 if (getState() == finished) 00370 { 00371 // Save the dialog size. 00372 AppPrefs::get()->write(prMC_WINDOW_SIZE, GetSize()); 00373 } 00374 00375 // Let the default handler do the job. 00376 event.Skip(); 00377 } 00378 //--------------------------------------------------------------------------- 00379 00380 00381 /** 00382 * Gets the number of files to check. 00383 * 00384 * @return The number of files to check. 00385 */ 00386 unsigned long dlgMultiCheck::getFilesToCheck() const 00387 { 00388 return filesToCheck; 00389 } 00390 //--------------------------------------------------------------------------- 00391 00392 00393 /** 00394 * Sets the number of checksums' files to check. 00395 * 00396 * @param nbTotalChecksumsFiles Number of checksums' files to check. 00397 */ 00398 void dlgMultiCheck::setFilesToCheck(unsigned long nbTotalChecksumsFiles) 00399 { 00400 filesToCheck = nbTotalChecksumsFiles; 00401 if (getFileToBeChecked() > getFilesToCheck()) 00402 setFileToBeChecked(getFilesToCheck()); 00403 00404 updateTotalChecksumsFiles(); 00405 } 00406 //--------------------------------------------------------------------------- 00407 00408 00409 /** 00410 * Gets the number of the current checksum's file to be check. 00411 * 00412 * @return The number of the current checksum's file to be check. 00413 */ 00414 unsigned long dlgMultiCheck::getFileToBeChecked() const 00415 { 00416 return fileChecked; 00417 } 00418 //--------------------------------------------------------------------------- 00419 00420 00421 /** 00422 * Sets the number of the current checksum's files to check. 00423 * 00424 * @param nbChecksumsFiles The number of the current checksum's files to check. 00425 */ 00426 void dlgMultiCheck::setFileToBeChecked(unsigned long nbChecksumsFiles) 00427 { 00428 fileChecked = (getFilesToCheck() >= nbChecksumsFiles) ? nbChecksumsFiles : getFilesToCheck(); 00429 updateTotalChecksumsFiles(); 00430 } 00431 //--------------------------------------------------------------------------- 00432 00433 00434 /** 00435 * Gets the number of files in the current checksums' file. 00436 * 00437 * @return The number of files in the current checksums' file. 00438 */ 00439 unsigned long dlgMultiCheck::getFilesInChecksumsFile() const 00440 { 00441 return filesInChecksumsFile; 00442 } 00443 //--------------------------------------------------------------------------- 00444 00445 00446 /** 00447 * Sets the number of files in the current checksums' file. 00448 * 00449 * @param nbTotalInChecksumsFiles The number of files in the current checksums' file. 00450 */ 00451 void dlgMultiCheck::setFilesInChecksumsFile(unsigned long nbTotalInChecksumsFiles) 00452 { 00453 filesInChecksumsFile = nbTotalInChecksumsFiles; 00454 if (getFileInChecksumsFile() > getFilesInChecksumsFile()) 00455 setFileInChecksumsFile(getFilesInChecksumsFile()); 00456 00457 updateFilesInChecksumsFiles(); 00458 } 00459 //--------------------------------------------------------------------------- 00460 00461 00462 /** 00463 * Gets the number of the current file in the current checksums' file. 00464 * 00465 * @return The number of the current file in the current checksums' file. 00466 */ 00467 unsigned long dlgMultiCheck::getFileInChecksumsFile() const 00468 { 00469 return fileInChecksumsFile; 00470 } 00471 //--------------------------------------------------------------------------- 00472 00473 00474 /** 00475 * Sets the number of the current file in the current checksums' file. 00476 * 00477 * @param nbInChecksumsFiles The number of the current file in the current checksums' file. 00478 */ 00479 void dlgMultiCheck::setFileInChecksumsFile(unsigned long nbInChecksumsFiles) 00480 { 00481 fileInChecksumsFile = (getFilesInChecksumsFile() >= nbInChecksumsFiles) ? nbInChecksumsFiles : getFilesInChecksumsFile(); 00482 updateFilesInChecksumsFiles(); 00483 } 00484 //--------------------------------------------------------------------------- 00485 00486 00487 /** 00488 * Gets the number of bytes of the current checked file in the current checked checksums' file. 00489 * 00490 * @return The number of bytes of the current checked file in the current checked checksums' file. 00491 */ 00492 BytesDisplayer dlgMultiCheck::getTotalBytes() const 00493 { 00494 return totalBytes; 00495 } 00496 //--------------------------------------------------------------------------- 00497 00498 00499 /** 00500 * Sets the number of bytes of the current checked file in the current checked checksums' file. 00501 * 00502 * @param bytes The number of bytes of the current checked file in the current checked checksums' file. 00503 */ 00504 void dlgMultiCheck::setTotalBytes(const BytesDisplayer& bytes) 00505 { 00506 totalBytes = bytes; 00507 if (getReadBytes().toDouble() > getTotalBytes().toDouble()) 00508 setReadBytes(getTotalBytes()); 00509 00510 updateCurrentCheckedFile(); 00511 } 00512 //--------------------------------------------------------------------------- 00513 00514 00515 /** 00516 * Gets the number of bytes read of the current checked file in the current checked checksums' file. 00517 * 00518 * @return The number of bytes read of the current checked file in the current checked checksums' file. 00519 */ 00520 BytesDisplayer dlgMultiCheck::getReadBytes() const 00521 { 00522 return bytesRead; 00523 } 00524 //--------------------------------------------------------------------------- 00525 00526 00527 /** 00528 * Sets the number of bytes read of the current checked file in the current checked checksums' file. 00529 * 00530 * @param bytes The number of bytes read of the current checked file in the current checked checksums' file. 00531 */ 00532 void dlgMultiCheck::setReadBytes(const BytesDisplayer& bytes) 00533 { 00534 bytesRead = (getTotalBytes().toDouble() >= bytes.toDouble()) ? bytes : getTotalBytes(); 00535 updateCurrentCheckedFile(); 00536 } 00537 //--------------------------------------------------------------------------- 00538 00539 00540 /** 00541 * Update the information of the total of the checksums' files to be checked. 00542 */ 00543 void dlgMultiCheck::updateTotalChecksumsFiles() 00544 { 00545 lblTotal->SetLabel(wxString::Format(_("%d/%d"), getFileToBeChecked(), getFilesToCheck())); 00546 double gauTotalValue = (getFileToBeChecked() > 0) ? static_cast<double>(getFileToBeChecked() - 1) : 0.0; 00547 00548 if (getFilesToCheck() > 0) 00549 gauTotal->SetValue(static_cast<int>(gauTotalValue * DGAUGE_MAX / static_cast<double>(getFilesToCheck()))); 00550 else 00551 gauTotal->SetValue(0); 00552 00553 // Refresh the dialog 00554 refreshDialog(); 00555 } 00556 //--------------------------------------------------------------------------- 00557 00558 00559 /** 00560 * Update the information of the files in the checksums' files to be checked. 00561 */ 00562 void dlgMultiCheck::updateFilesInChecksumsFiles() 00563 { 00564 lblChecksumFile->SetLabel(wxString::Format(_("%d/%d"), getFileInChecksumsFile(), getFilesInChecksumsFile())); 00565 double gauChecksumFileValue = (getFileInChecksumsFile() > 0) ? static_cast<double>(getFileInChecksumsFile() - 1) : 0.0; 00566 00567 if (getFilesInChecksumsFile() > 0) 00568 gauChecksumFile->SetValue(static_cast<int>(gauChecksumFileValue * DGAUGE_MAX / static_cast<double>(getFilesInChecksumsFile()))); 00569 else 00570 gauChecksumFile->SetValue(0); 00571 00572 // Refresh the dialog 00573 refreshDialog(); 00574 00575 } 00576 //--------------------------------------------------------------------------- 00577 00578 00579 /** 00580 * Update the information of the current checked file. 00581 */ 00582 void dlgMultiCheck::updateCurrentCheckedFile() 00583 { 00584 // Updating current file label 00585 lblFile->SetLabel(wxString::Format(_("%s/%s"), getReadBytes().toString().c_str(), getTotalBytes().toString().c_str())); 00586 00587 // Computing gauges initial values (in interval [0.0...1.0]) 00588 double gauFileValue = (getTotalBytes().toDouble() > 0.0) ? getReadBytes().toDouble() / getTotalBytes().toDouble() : 0.0; 00589 00590 double gauChecksumFileValue = (getFileInChecksumsFile() > 0) ? static_cast<double>(getFileInChecksumsFile() - 1) : 0.0; 00591 gauChecksumFileValue += gauFileValue; 00592 gauChecksumFileValue = (getFilesInChecksumsFile() > 0) ? gauChecksumFileValue / static_cast<double>(getFilesInChecksumsFile()) : 0.0; 00593 00594 double gauTotalValue = (getFileToBeChecked() > 0) ? static_cast<double>(getFileToBeChecked() - 1) : 0.0; 00595 gauTotalValue += gauChecksumFileValue; 00596 gauTotalValue = (getFilesToCheck() > 0) ? gauTotalValue / static_cast<double>(getFilesToCheck()) : 0.0; 00597 00598 // Changing gauges values 00599 int intFileValue = static_cast<int>(gauFileValue * DGAUGE_MAX); 00600 int intChecksumFile = static_cast<int>(gauChecksumFileValue * DGAUGE_MAX); 00601 int intTotal = static_cast<int>(gauTotalValue * DGAUGE_MAX); 00602 00603 if (gauFile->GetValue() != intFileValue) 00604 gauFile->SetValue(intFileValue); 00605 if (gauChecksumFile->GetValue() != intChecksumFile) 00606 gauChecksumFile->SetValue(intChecksumFile); 00607 if (gauTotal->GetValue() != intTotal) 00608 gauTotal->SetValue(intTotal); 00609 00610 // Refresh the dialog 00611 refreshDialog(); 00612 } 00613 //--------------------------------------------------------------------------- 00614 00615 00616 /** 00617 * Checks a file. 00618 * 00619 * @param fileName Name of the file to check. 00620 * @param cc Checksum calculator. 00621 * @param checksum Checksum of the file stored in the checksums' file. 00622 * @param dlgPrg Progress dialog to update. 00623 * @param stats Statistics on the files. 00624 */ 00625 void dlgMultiCheck::checkFile(const wxFileName& fileName, Checksum* cc, const wxString& checksum, dlgMultiCheck& dlgPrg, FilesStatistics& stats) 00626 { 00627 wxCOff_t fs; // rest of the file size to read. 00628 BytesDisplayer total; // total of bytes to process. 00629 ChecksumFileCalculator::State retState; // state returned by the checksum' calculator. 00630 00631 fs = wxCGetFileLength(fileName.GetFullPath()); // get the length of the file to read 00632 total = (fs == static_cast<wxCOff_t>(wxInvalidOffset)) ? 0.0 : static_cast<double>(fs); 00633 00634 ChecksumProgress progressUpdater(&dlgPrg, total); 00635 ChecksumFileCalculator cfc(cc, &progressUpdater); 00636 00637 // Check the file. 00638 retState = cfc.check(fileName.GetFullPath(), checksum); 00639 00640 // Update the progress dialog 00641 progressUpdater.finished(); 00642 00643 switch (retState) 00644 { 00645 case ChecksumFileCalculator::Ok : // Checksum has been calculated (and corresponds for the check method). 00646 stats.FCorrect++; 00647 if (AppPrefs::get()->readBool(prMC_FILE_STATE)) 00648 if (AppPrefs::get()->readBool(prMC_NO_CORRECT_FILE_STATE)) 00649 dlgPrg.removeLastResultLine(); 00650 else 00651 dlgPrg.replaceLastResultLine(wxString::Format(_("'%s': OK\n"), fileName.GetFullPath().c_str()), 1U, getColour(prMC_SUCCESS_COLOUR)); 00652 break; 00653 00654 case ChecksumFileCalculator::Invalid : // Checksum has been verified and not corresponds. 00655 stats.FIncorrect++; 00656 if (AppPrefs::get()->readBool(prMC_FILE_STATE)) 00657 dlgPrg.replaceLastResultLine(wxString::Format(_("'%s': Checksums differ\n"), fileName.GetFullPath().c_str()), 1U, getColour(prMC_ERROR_COLOUR)); 00658 break; 00659 00660 case ChecksumFileCalculator::ReadError : // Error while reading the stream. 00661 stats.FNotFound++; 00662 if (AppPrefs::get()->readBool(prMC_FILE_STATE)) 00663 dlgPrg.replaceLastResultLine(wxString::Format(_("Error while reading '%s'.\n"), fileName.GetFullPath().c_str()), 1U, getColour(prMC_ERROR_COLOUR)); 00664 break; 00665 00666 case ChecksumFileCalculator::FileNotFound : // The file has been not found. 00667 stats.FNotFound++; 00668 if (AppPrefs::get()->readBool(prMC_FILE_STATE)) 00669 dlgPrg.replaceLastResultLine(wxString::Format(_("'%s': File not found\n"), fileName.GetFullPath().c_str()), 1U, getColour(prMC_ERROR_COLOUR)); 00670 break; 00671 00672 case ChecksumFileCalculator::CantOpenFile : // Can't open the stream. 00673 stats.FNotOpened++; 00674 if (AppPrefs::get()->readBool(prMC_FILE_STATE)) 00675 dlgPrg.replaceLastResultLine(wxString::Format(_("'%s': File cannot be opened\n"), fileName.GetFullPath().c_str()), 1U, getColour(prMC_ERROR_COLOUR)); 00676 break; 00677 00678 // case ChecksumFileCalculator::CanceledByUser : // User has canceled the calculation. 00679 } 00680 } 00681 //--------------------------------------------------------------------------- 00682 00683 00684 /** 00685 * Checks multiple checksums' files. 00686 * 00687 * @param files List of the checksums' files to check. 00688 * @param parent Parent of the dialog that will be created. 00689 */ 00690 void dlgMultiCheck::checkChecksumsFiles(const wxArrayString& files, wxWindow* parent) 00691 { 00692 FilesStatistics fstats; 00693 dlgMultiCheck dlgPrg(parent); 00694 SumFile* sumFile; 00695 wxFile file; 00696 size_t i, j; 00697 wxString msg; 00698 00699 // Some compilers don't like the ? : structure in function call, so using 00700 // this variable to store the result of ? : before the call. 00701 // Note : some versions of Borland C++ don't like nested ? : so using if else. 00702 wxColour colour; 00703 00704 // No log 00705 wxLogNull logNo; 00706 00707 dlgPrg.setFilesToCheck(files.GetCount()); 00708 i = 0; 00709 while (i < files.GetCount() && dlgPrg.canContinue()) 00710 { 00711 // Display information 00712 dlgPrg.addResultLine(wxString::Format(_("Checking '%s'.\n"), files[i].c_str()), 0U, getColour(prMC_NORMAL_COLOUR)); 00713 dlgPrg.setFileToBeChecked(i + 1); 00714 00715 // Try to open the file 00716 if (file.Open(files[i], wxFile::read)) 00717 { 00718 file.Close(); 00719 sumFile = ::openChecksumFile(files[i]); 00720 if (sumFile != NULL) 00721 { 00722 // Gets the name of the checksums' file. 00723 wxFileName sumFileName(sumFile->getFileName()); 00724 00725 // Set the number of files in this checksums' file. 00726 dlgPrg.setFilesInChecksumsFile(sumFile->getChecksumDataCount()); 00727 00728 // Gets a checksum calculator for this checksums' file. 00729 Checksum* cc = sumFile->getChecksumCalculator(); 00730 00731 // Checking each file. 00732 fstats.resetCkFiles(); 00733 j = 1; 00734 MChecksumData::const_iterator it = sumFile->getChecksumDataBegin(); 00735 while (it != sumFile->getChecksumDataEnd() && dlgPrg.canContinue()) 00736 { 00737 // Get the absolute name of the file to check. 00738 wxFileName fn(it->second.getFileName()); 00739 fn.MakeAbsolute(sumFileName.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR)); 00740 00741 // Update the dialog 00742 dlgPrg.setFileInChecksumsFile(j); 00743 msg.Printf(_("Checking '%s'...\n"), fn.GetFullPath().c_str()); 00744 if (it == sumFile->getChecksumDataBegin() || AppPrefs::get()->readBool(prMC_FILE_STATE)) 00745 dlgPrg.addResultLine(msg, 1U, getColour(prMC_NORMAL_COLOUR)); 00746 else 00747 dlgPrg.replaceLastResultLine(msg, 1U, getColour(prMC_NORMAL_COLOUR)); 00748 00749 // Check the file. 00750 checkFile(fn, cc, it->second.getChecksum(), dlgPrg, fstats); 00751 00752 it++; 00753 j++; 00754 } 00755 00756 // Display the summary of the checksums' file. 00757 if (dlgPrg.canContinue()) 00758 { 00759 if (sumFile->getChecksumDataCount() > 0) 00760 { 00761 // Remove the last line if the status of each file is NOT displayed 00762 if (!AppPrefs::get()->readBool(prMC_FILE_STATE)) 00763 dlgPrg.removeLastResultLine(); 00764 00765 if (AppPrefs::get()->readBool(prMC_CHECKSUMS_FILE_SUMMARY)) 00766 { 00767 if (AppPrefs::get()->readBool(prMC_FILE_STATE)) 00768 dlgPrg.addResultLine(wxT("\n")); 00769 dlgPrg.addResultLine(wxString::Format(_("Total checked: %d\n"), fstats.getCheckedFilesCount()), 0U, getColour(prMC_NORMAL_COLOUR)); 00770 if (fstats.allAreCorrects()) colour = getColour(prMC_SUCCESS_COLOUR); else if (fstats.FCorrect > 0) colour = getColour(prMC_WARNING_COLOUR); else colour = getColour(prMC_ERROR_COLOUR); 00771 dlgPrg.addResultLine(wxString::Format(_("Correct(s): %d\n"), fstats.FCorrect), 1U, colour); 00772 colour = (fstats.FIncorrect == 0) ? getColour(prMC_SUCCESS_COLOUR) : getColour(prMC_ERROR_COLOUR); 00773 dlgPrg.addResultLine(wxString::Format(_("Incorrect(s): %d\n"), fstats.FIncorrect), 1U, colour); 00774 colour = (fstats.FNotFound == 0) ? getColour(prMC_SUCCESS_COLOUR) : getColour(prMC_ERROR_COLOUR); 00775 dlgPrg.addResultLine(wxString::Format(_("Not found: %d\n"), fstats.FNotFound), 1U, colour); 00776 colour = (fstats.FNotOpened == 0) ? getColour(prMC_SUCCESS_COLOUR) : getColour(prMC_ERROR_COLOUR); 00777 dlgPrg.addResultLine(wxString::Format(_("Not opened: %d\n"), fstats.FNotOpened), 1U, colour); 00778 00779 if (AppPrefs::get()->readBool(prMC_FILE_STATE)) 00780 dlgPrg.addResultLine(wxT("\n")); 00781 } 00782 else 00783 { 00784 if (fstats.allAreCorrects()) 00785 dlgPrg.addResultLine(_("All checksums are corrects.\n"), 0U, getColour(prMC_SUCCESS_COLOUR)); 00786 else 00787 dlgPrg.addResultLine(_("Some checksums are incorrects.\n"), 0U, getColour(prMC_ERROR_COLOUR)); 00788 } 00789 } 00790 else 00791 dlgPrg.addResultLine(wxString::Format(_("'%s' is empty.\n"), files[i].c_str()), 0U, getColour(prMC_WARNING_COLOUR)); 00792 } 00793 00794 delete cc; 00795 delete sumFile; 00796 00797 // Updates statistics of checksums' files. 00798 if (fstats.allAreCorrects()) 00799 fstats.CKTotallyCorrect++; 00800 else 00801 if (fstats.FCorrect == 0) 00802 fstats.CKFullyIncorrect++; 00803 else 00804 fstats.CKPartiallyCorrect++; 00805 } 00806 else // the file can't be open 00807 { 00808 dlgPrg.addResultLine(wxString::Format(_("'%s' is not a valid checksums' file.\n"), files[i].c_str()), 0U, getColour(prMC_ERROR_COLOUR)); 00809 fstats.CKInvalid++; 00810 } 00811 } 00812 else 00813 { 00814 dlgPrg.addResultLine(wxString::Format(_("'%s' cannot be opened.\n"), files[i].c_str()), 0U, getColour(prMC_ERROR_COLOUR)); 00815 fstats.CKNotOpened++; 00816 } 00817 00818 dlgPrg.addResultLine(wxT("\n")); 00819 00820 i++; 00821 } 00822 00823 if (dlgPrg.getState() != canceled) 00824 { 00825 // Display the global summary. 00826 if (AppPrefs::get()->readBool(prMC_GLOBAL_SUMMARY)) 00827 { 00828 dlgPrg.addResultLine(wxString::Format(_("Total checksums' files checked: %d\n"), fstats.getChecksumsFilesChecked()), 0U, getColour(prMC_NORMAL_COLOUR)); 00829 if (fstats.allChecksumsFilesAreCorrects()) colour = getColour(prMC_SUCCESS_COLOUR); else if (fstats.CKTotallyCorrect > 0) colour = getColour(prMC_WARNING_COLOUR); else colour = getColour(prMC_ERROR_COLOUR); 00830 dlgPrg.addResultLine(wxString::Format(_("Correct(s): %d\n"), fstats.CKTotallyCorrect), 1U, colour); 00831 colour = (fstats.CKPartiallyCorrect == 0) ? getColour(prMC_SUCCESS_COLOUR) : getColour(prMC_ERROR_COLOUR); 00832 dlgPrg.addResultLine(wxString::Format(_("Partially correct(s): %d\n"), fstats.CKPartiallyCorrect), 1U, colour); 00833 colour = (fstats.CKFullyIncorrect == 0) ? getColour(prMC_SUCCESS_COLOUR) : getColour(prMC_ERROR_COLOUR); 00834 dlgPrg.addResultLine(wxString::Format(_("Fully incorrect(s): %d\n"), fstats.CKFullyIncorrect), 1U, colour); 00835 colour = (fstats.CKInvalid == 0) ? getColour(prMC_SUCCESS_COLOUR) : getColour(prMC_ERROR_COLOUR); 00836 dlgPrg.addResultLine(wxString::Format(_("Invalid(s): %d\n"), fstats.CKInvalid), 1U, colour); 00837 colour = (fstats.CKNotOpened == 0) ? getColour(prMC_SUCCESS_COLOUR) : getColour(prMC_ERROR_COLOUR); 00838 dlgPrg.addResultLine(wxString::Format(_("Not opened: %d\n"), fstats.CKNotOpened), 1U, colour); 00839 } 00840 else 00841 { 00842 if (fstats.allChecksumsFilesAreCorrects()) 00843 dlgPrg.addResultLine(_("All checksums' files are corrects.\n"), 0U, getColour(prMC_SUCCESS_COLOUR)); 00844 else 00845 dlgPrg.addResultLine(_("Some checksums' files are incorrects.\n"), 0U, getColour(prMC_ERROR_COLOUR)); 00846 } 00847 00848 dlgPrg.Finished(); 00849 } 00850 } 00851 //--------------------------------------------------------------------------- 00852 00853 00854 BEGIN_EVENT_TABLE(dlgMultiCheck, dlgResultsProgress) 00855 EVT_BUTTON(wxID_CANCEL, dlgMultiCheck::btnCancelClick) 00856 END_EVENT_TABLE() 00857 //---------------------------------------------------------------------------

Generated on Sun May 30 13:37:44 2004 for wxChecksums by doxygen 1.3.7