| 5 |
|
const QString PackagePage2::PackagesCacheUrl = "http://mods.oni2.net/jsoncache/"+ZipCacheFile; |
| 6 |
|
const QString PackagePage2::CacheFile = "nodes.json"; |
| 7 |
|
|
| 8 |
< |
PackagePage2::PackagePage2(Logger *myLogger, QWidget *parent) : |
| 8 |
> |
PackagePage2::PackagePage2(QWidget *parent) : |
| 9 |
|
QWizardPage(parent), |
| 10 |
|
ui(new Ui::PackagePage2) |
| 11 |
|
{ |
| 12 |
|
ui->setupUi(this); |
| 13 |
< |
this->myLogger=myLogger; |
| 13 |
> |
|
| 14 |
|
this->setTitle("Mandatory Fields"); |
| 15 |
|
|
| 16 |
|
//Register fields to be accessible in another pages //Not using mandatory field, it would require empty verification too... |
| 37 |
|
QString description=ui->ptDescription->toPlainText(); |
| 38 |
|
QString number=ui->lePackageNumber->text(); |
| 39 |
|
|
| 40 |
< |
bool emptyContent=Util::checkEmptySpaces(QStringList()<<modName<<authors<<version<<description<<number); |
| 40 |
> |
bool emptyContent=Util::Validation::checkEmptySpaces(QStringList()<<modName<<authors<<version<<description<<number); |
| 41 |
|
|
| 42 |
|
|
| 43 |
|
if(emptyContent){ |
| 44 |
< |
Util::showErrorPopUp("You need to fill all fields first!"); |
| 44 |
> |
Util::Dialogs::showError("You need to fill all fields first!"); |
| 45 |
|
return false; |
| 46 |
|
} |
| 47 |
|
|
| 48 |
|
if(number.size()!=5){ |
| 49 |
< |
Util::showErrorPopUp("Invalid number format. It should contain 5 numbers."); |
| 49 |
> |
Util::Dialogs::showError("Invalid number format. It should contain 5 numbers."); |
| 50 |
|
return false; |
| 51 |
|
} |
| 52 |
|
|
| 53 |
< |
if(!Util::isStringInteger(number)){ |
| 54 |
< |
Util::showErrorPopUp("Number is not numeric."); |
| 53 |
> |
if(!Util::Validation::isStringInteger(number)){ |
| 54 |
> |
Util::Dialogs::showError("Number is not numeric."); |
| 55 |
|
return false; |
| 56 |
|
} |
| 57 |
|
|
| 67 |
|
{ |
| 68 |
|
QString number = ui->lePackageNumber->text(); |
| 69 |
|
|
| 70 |
< |
if(Util::checkEmptySpaces(QStringList(number))){ |
| 71 |
< |
Util::showErrorPopUp("Number is empty. Please fill it first."); |
| 70 |
> |
if(Util::Validation::checkEmptySpaces(QStringList(number))){ |
| 71 |
> |
Util::Dialogs::showError("Number is empty. Please fill it first."); |
| 72 |
|
return; |
| 73 |
|
} |
| 74 |
|
|
| 75 |
|
if(number.size()!=5){ |
| 76 |
< |
Util::showErrorPopUp("Invalid number format. It should contain 5 numeric characters."); |
| 76 |
> |
Util::Dialogs::showError("Invalid number format. It should contain 5 numeric characters."); |
| 77 |
|
return; |
| 78 |
|
} |
| 79 |
|
|
| 80 |
< |
if(Util::isStringInteger(number)){ |
| 80 |
> |
if(Util::Validation::isStringInteger(number)){ |
| 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 |
| 107 |
|
} |
| 108 |
|
} |
| 109 |
|
else{ |
| 110 |
< |
Util::showErrorPopUp("Number is not numeric."); |
| 110 |
> |
Util::Dialogs::showError("Number is not numeric."); |
| 111 |
|
} |
| 112 |
|
} |
| 113 |
|
|
| 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("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("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("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("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 |
| 176 |
|
} |
| 177 |
|
|
| 178 |
|
if(!existingModName.isEmpty()){ |
| 179 |
< |
Util::showRichErrorPopUp("Package "+packageNumber+" is already being used by the following mod:<br/><br/>"+ |
| 179 |
> |
Util::Dialogs::showRichError("Package "+packageNumber+" is already being used by the following mod:<br/><br/>"+ |
| 180 |
|
existingModName+"<br/><br/>"+ |
| 181 |
|
"More information <a href='"+existingModUrl+"'>here</a>."); |
| 182 |
|
} |
| 183 |
|
else{ |
| 184 |
< |
Util::showPopUp("It seems that the package number " + packageNumber + " is not being used yet! :)"); |
| 184 |
> |
Util::Dialogs::showInfo("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 |
– |
} |