--- Vago/trunk/Vago/packageWizard/packagepage2.cpp 2013/04/06 20:54:26 790 +++ s10k/Vago/packageWizard/packagepage2.cpp 2017/12/30 13:43:28 1092 @@ -73,7 +73,7 @@ void PackagePage2::on_pbCheck_clicked() } if(number.size()!=5){ - Util::showErrorPopUp("Invalid number format. It should contain 5 numbers."); + Util::showErrorPopUp("Invalid number format. It should contain 5 numeric characters."); return; } @@ -81,15 +81,14 @@ void PackagePage2::on_pbCheck_clicked() bool necessaryToRedownload=false; - QFile *file = new QFile(GlobalVars::VagoTemporaryDir+"/"+this->ZipCacheFile); + QFile file(GlobalVars::VagoTemporaryDir+"/"+this->ZipCacheFile); - if(!file->exists()){ + if(!file.exists()){ necessaryToRedownload=true; //File doesn't exist yet, necessary to download } - else if (QDateTime::currentDateTime().toTime_t()-QFileInfo(*file).lastModified().toTime_t() > 150){ //checks between 2 minutes (give more 30 seconds due to zip extraction) + else if (QDateTime::currentDateTime().toTime_t()-QFileInfo(file).lastModified().toTime_t() > 150){ //checks between 2 minutes (give more 30 seconds due to zip extraction) necessaryToRedownload=true; //File already exists but already expired (+2 mins without update) } - delete file; if(necessaryToRedownload){ //let's start the search in the web, so we make sure it doesn't exists yet @@ -116,43 +115,30 @@ void PackagePage2::downloadPackagesCache if(result->error()==QNetworkReply::NoError){ - QFile *file = new QFile(GlobalVars::VagoTemporaryDir+"/"+this->ZipCacheFile); + QFile file(GlobalVars::VagoTemporaryDir+"/"+this->ZipCacheFile); // Create temp folder if it doesn't exist if(!QDir(GlobalVars::VagoTemporaryDir).exists()){ QDir().mkdir(GlobalVars::VagoTemporaryDir); } - if(!file->open(QIODevice::WriteOnly)){ - const QString error="Error fetching package data: creating cache file."; - this->myLogger->writeString(error); - Util::showErrorPopUp(error); + if(!file.open(QIODevice::WriteOnly)){ + UtilVago::showAndLogErrorPopUp(this->myLogger, "Error fetching package data: creating cache file."); return; } - file->write(result->readAll()); - file->close(); + file.write(result->readAll()); + file.close(); //Let's extract the cache data - UnZip uz; - UnZip::ErrorCode ec = uz.openArchive(GlobalVars::VagoTemporaryDir+"/"+this->ZipCacheFile); - checkForUnzipError(ec); - - //Extract the cache files - ec = uz.extractAll(GlobalVars::VagoTemporaryDir); - checkForUnzipError(ec); - - //Close zip archive - uz.closeArchive(); - - delete file; + if(JlCompress::extractFile(GlobalVars::VagoTemporaryDir+"/"+this->ZipCacheFile, "/"+this->CacheFile ,GlobalVars::VagoTemporaryDir+"/"+this->CacheFile).isEmpty()){ + UtilVago::showAndLogErrorPopUp(this->myLogger, "An error occurred while unzipping the package data."); + } checkForPackagesInCache(); } else{ - const QString error="An error occurred checking number availability:\n\n"+result->errorString(); - this->myLogger->writeString(error); - Util::showErrorLogPopUp(error); + UtilVago::showAndLogErrorPopUpLogButton(this->myLogger, "An error occurred checking number availability:\n\n"+result->errorString()); } result->deleteLater(); @@ -161,15 +147,13 @@ void PackagePage2::downloadPackagesCache void PackagePage2::checkForPackagesInCache(){ QString packageNumber=ui->lePackageNumber->text(); - QFile *file = new QFile(GlobalVars::VagoTemporaryDir+"/"+this->CacheFile); //let's read the chache unzipped - if(!file->open(QIODevice::ReadOnly)){ - const QString error="Error reading downloaded package cache data."; - this->myLogger->writeString(error); - Util::showErrorPopUp(error); + QFile file(GlobalVars::VagoTemporaryDir+"/"+this->CacheFile); //let's read the chache unzipped + if(!file.open(QIODevice::ReadOnly)){ + UtilVago::showAndLogErrorPopUp(this->myLogger, "Error reading downloaded package cache data."); return; } //Read file cache to ram - QString data=file->readAll(); + QString data=file.readAll(); //Let's play with json engine @@ -197,21 +181,11 @@ void PackagePage2::checkForPackagesInCac "More information here."); } else{ - Util::showPopUp("Package "+packageNumber+" seems it's not being used yet! :)"); + Util::showPopUp("It seems that the package number " + packageNumber + " is not being used yet! :)"); } - - delete file; } void PackagePage2::on_cbType_currentIndexChanged(int index) { - ui->lePackageNumber->setText(QString().setNum(index+1)+"000X"); -} - -void PackagePage2::checkForUnzipError(UnZip::ErrorCode ec){ - if (ec != UnZip::Ok){ - const QString error="Error found while unzipping the package data. Error number = "+QString::number(ec); - Util::showErrorPopUp(error); - this->myLogger->writeString(error); - } + ui->lePackageNumber->setText(QString().setNum(index+1)+"XXXX"); }