| 81 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 82 |  | bool necessaryToRedownload=false; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 83 |  |  | 
 
 
 
 
 
 
 
 
 
 
 | 84 | < | QFile *file = new QFile(GlobalVars::VagoTemporaryDir+"/"+this->ZipCacheFile); | 
 
 
 
 
 
 
 
 
 | 84 | > | QFile file(GlobalVars::VagoTemporaryDir+"/"+this->ZipCacheFile); | 
 
 
 
 
 
 
 
 
 
 
 | 85 |  |  | 
 
 
 
 
 
 
 
 
 
 
 | 86 | < | if(!file->exists()){ | 
 
 
 
 
 
 
 
 
 | 86 | > | if(!file.exists()){ | 
 
 
 
 
 
 
 
 
 
 
 | 87 |  | necessaryToRedownload=true; //File doesn't exist yet, necessary to download | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 88 |  | } | 
 
 
 
 
 
 
 
 
 
 
 | 89 | < | else if (QDateTime::currentDateTime().toTime_t()-QFileInfo(*file).lastModified().toTime_t() > 150){ //checks between 2 minutes (give more 30 seconds due to zip extraction) | 
 
 
 
 
 
 
 
 
 | 89 | > | else if (QDateTime::currentDateTime().toTime_t()-QFileInfo(file).lastModified().toTime_t() > 150){ //checks between 2 minutes (give more 30 seconds due to zip extraction) | 
 
 
 
 
 
 
 
 
 
 
 | 90 |  | necessaryToRedownload=true; //File already exists but already expired (+2 mins without update) | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 91 |  | } | 
 
 
 
 
 
 
 
 
 | 92 | – | delete file; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 92 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 93 |  | if(necessaryToRedownload){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 94 |  | //let's start the search in the web, so we make sure it doesn't exists yet | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 115 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 116 |  | if(result->error()==QNetworkReply::NoError){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 117 |  |  | 
 
 
 
 
 
 
 
 
 
 
 | 118 | < | QFile *file = new QFile(GlobalVars::VagoTemporaryDir+"/"+this->ZipCacheFile); | 
 
 
 
 
 
 
 
 
 | 118 | > | QFile file(GlobalVars::VagoTemporaryDir+"/"+this->ZipCacheFile); | 
 
 
 
 
 
 
 
 
 
 
 | 119 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 120 |  | // Create temp folder if it doesn't exist | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 121 |  | if(!QDir(GlobalVars::VagoTemporaryDir).exists()){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 122 |  | QDir().mkdir(GlobalVars::VagoTemporaryDir); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 123 |  | } | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 124 |  |  | 
 
 
 
 
 
 
 
 
 
 
 | 125 | < | if(!file->open(QIODevice::WriteOnly)){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 126 | < | const QString error="Error fetching package data: creating cache file."; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 128 | < | this->myLogger->writeString(error); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 129 | < | Util::showErrorPopUp(error); | 
 
 
 
 
 
 
 
 
 | 125 | > | if(!file.open(QIODevice::WriteOnly)){ | 
 
 
 
 
 | 126 | > | UtilVago::showAndLogErrorPopUp(this->myLogger, "Error fetching package data: creating cache file."); | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 127 |  | return; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 128 |  | } | 
 
 
 
 
 
 
 
 
 
 
 | 129 | < | file->write(result->readAll()); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 130 | < | file->close(); | 
 
 
 
 
 
 
 
 
 | 129 | > | file.write(result->readAll()); | 
 
 
 
 
 | 130 | > | file.close(); | 
 
 
 
 
 
 
 
 
 
 
 | 131 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 132 |  | //Let's extract the cache data | 
 
 
 
 
 
 
 
 
 
 
 | 133 | < | UnZip uz; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 134 | < | UnZip::ErrorCode ec = uz.openArchive(GlobalVars::VagoTemporaryDir+"/"+this->ZipCacheFile); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 135 | < | checkForUnzipError(ec); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 139 | < |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 140 | < | //Extract the cache files | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 141 | < | ec = uz.extractAll(GlobalVars::VagoTemporaryDir); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 142 | < | checkForUnzipError(ec); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 143 | < |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 144 | < | //Close zip archive | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 145 | < | uz.closeArchive(); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 146 | < |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 147 | < | delete file; | 
 
 
 
 
 
 
 
 
 | 133 | > | if(JlCompress::extractFile(GlobalVars::VagoTemporaryDir+"/"+this->ZipCacheFile, "/"+this->CacheFile ,GlobalVars::VagoTemporaryDir+"/"+this->CacheFile).isEmpty()){ | 
 
 
 
 
 | 134 | > | UtilVago::showAndLogErrorPopUp(this->myLogger, "An error occurred while unzipping the package data."); | 
 
 
 
 
 | 135 | > | } | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 136 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 137 |  | checkForPackagesInCache(); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 138 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 139 |  | } | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 140 |  | else{ | 
 
 
 
 
 
 
 
 
 
 
 | 141 | < | const QString error="An error occurred checking number availability:\n\n"+result->errorString(); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 154 | < | this->myLogger->writeString(error); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 155 | < | Util::showErrorLogPopUp(error); | 
 
 
 
 
 
 
 
 
 | 141 | > | UtilVago::showAndLogErrorPopUpLogButton(this->myLogger, "An error occurred checking number availability:\n\n"+result->errorString()); | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 142 |  | } | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 143 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 144 |  | result->deleteLater(); | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 147 |  | void PackagePage2::checkForPackagesInCache(){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 148 |  | QString packageNumber=ui->lePackageNumber->text(); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 149 |  |  | 
 
 
 
 
 
 
 
 
 
 
 | 150 | < | QFile *file = new QFile(GlobalVars::VagoTemporaryDir+"/"+this->CacheFile); //let's read the chache unzipped | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 151 | < | if(!file->open(QIODevice::ReadOnly)){ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 152 | < | const QString error="Error reading downloaded package cache data."; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 167 | < | this->myLogger->writeString(error); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 168 | < | Util::showErrorPopUp(error); | 
 
 
 
 
 
 
 
 
 | 150 | > | QFile file(GlobalVars::VagoTemporaryDir+"/"+this->CacheFile); //let's read the chache unzipped | 
 
 
 
 
 | 151 | > | if(!file.open(QIODevice::ReadOnly)){ | 
 
 
 
 
 | 152 | > | UtilVago::showAndLogErrorPopUp(this->myLogger, "Error reading downloaded package cache data."); | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 153 |  | return; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 154 |  | } | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 155 |  | //Read file cache to ram | 
 
 
 
 
 
 
 
 
 
 
 | 156 | < | QString data=file->readAll(); | 
 
 
 
 
 
 
 
 
 | 156 | > | QString data=file.readAll(); | 
 
 
 
 
 
 
 
 
 
 
 | 157 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 158 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 159 |  | //Let's play with json engine | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 183 |  | else{ | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 184 |  | Util::showPopUp("It seems that the package number " + packageNumber + " is not being used yet! :)"); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 185 |  | } | 
 
 
 
 
 
 
 
 
 | 202 | – |  | 
 
 
 
 
 
 
 
 
 | 203 | – | delete file; | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 186 |  | } | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 187 |  |  | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 188 |  | void PackagePage2::on_cbType_currentIndexChanged(int index) | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 189 |  | { | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 190 |  | ui->lePackageNumber->setText(QString().setNum(index+1)+"XXXX"); | 
 
 
 
 
 
 
 
 
 
 
 
 
 | 191 |  | } | 
 
 
 
 
 
 
 
 
 | 210 | – |  | 
 
 
 
 
 
 
 
 
 | 211 | – | void PackagePage2::checkForUnzipError(UnZip::ErrorCode ec){ | 
 
 
 
 
 
 
 
 
 | 212 | – | if (ec != UnZip::Ok){ | 
 
 
 
 
 
 
 
 
 | 213 | – | const QString error="Error found while unzipping the package data. Error number = "+QString::number(ec); | 
 
 
 
 
 
 
 
 
 | 214 | – | Util::showErrorPopUp(error); | 
 
 
 
 
 
 
 
 
 | 215 | – | this->myLogger->writeString(error); | 
 
 
 
 
 
 
 
 
 | 216 | – | } | 
 
 
 
 
 
 
 
 
 | 217 | – | } |