--- Vago/trunk/Vago/packageWizard/packagepage2.cpp 2016/04/02 15:58:07 1039 +++ s10k/Vago/packageWizard/packagepage2.cpp 2017/12/30 13:57:32 1093 @@ -5,12 +5,12 @@ const QString PackagePage2::ZipCacheFile const QString PackagePage2::PackagesCacheUrl = "http://mods.oni2.net/jsoncache/"+ZipCacheFile; const QString PackagePage2::CacheFile = "nodes.json"; -PackagePage2::PackagePage2(Logger *myLogger, QWidget *parent) : +PackagePage2::PackagePage2(QWidget *parent) : QWizardPage(parent), ui(new Ui::PackagePage2) { ui->setupUi(this); - this->myLogger=myLogger; + this->setTitle("Mandatory Fields"); //Register fields to be accessible in another pages //Not using mandatory field, it would require empty verification too... @@ -37,21 +37,21 @@ bool PackagePage2::validatePage(){ QString description=ui->ptDescription->toPlainText(); QString number=ui->lePackageNumber->text(); - bool emptyContent=Util::checkEmptySpaces(QStringList()<lePackageNumber->text(); - if(Util::checkEmptySpaces(QStringList(number))){ - Util::showErrorPopUp("Number is empty. Please fill it first."); + if(Util::Validation::checkEmptySpaces(QStringList(number))){ + Util::Dialogs::showError("Number is empty. Please fill it first."); return; } if(number.size()!=5){ - Util::showErrorPopUp("Invalid number format. It should contain 5 numeric characters."); + Util::Dialogs::showError("Invalid number format. It should contain 5 numeric characters."); return; } - if(Util::isStringInteger(number)){ + if(Util::Validation::isStringInteger(number)){ 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 @@ -108,7 +107,7 @@ void PackagePage2::on_pbCheck_clicked() } } else{ - Util::showErrorPopUp("Number is not numeric."); + Util::Dialogs::showError("Number is not numeric."); } } @@ -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("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("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("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("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 @@ -192,26 +176,16 @@ void PackagePage2::checkForPackagesInCac } if(!existingModName.isEmpty()){ - Util::showRichErrorPopUp("Package "+packageNumber+" is already being used by the following mod:

"+ + Util::Dialogs::showRichError("Package "+packageNumber+" is already being used by the following mod:

"+ existingModName+"

"+ "More information here."); } else{ - Util::showPopUp("It seems that the package number " + packageNumber + " is not being used yet! :)"); + Util::Dialogs::showInfo("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)+"XXXX"); } - -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); - } -}