Merge pull request #2504 from Atlante45/upload_feedback

Display warning popup when something went wrong with the fst upload
This commit is contained in:
Brad Hefta-Gaub 2014-03-26 13:31:49 -07:00
commit d90ebfd29a

View file

@ -14,6 +14,7 @@
#include <QStandardPaths> #include <QStandardPaths>
#include <QHttpMultiPart> #include <QHttpMultiPart>
#include <QVariant> #include <QVariant>
#include <QMessageBox>
#include "AccountManager.h" #include "AccountManager.h"
@ -50,11 +51,18 @@ bool FstReader::zip() {
"Select your .fst file ...", "Select your .fst file ...",
QStandardPaths::writableLocation(QStandardPaths::DownloadLocation), QStandardPaths::writableLocation(QStandardPaths::DownloadLocation),
"*.fst"); "*.fst");
if (filename == "") {
// If the user canceled we return.
return false;
}
// First we check the FST file // First we check the FST file
QFile fst(filename); QFile fst(filename);
if (!fst.open(QFile::ReadOnly | QFile::Text)) { if (!fst.open(QFile::ReadOnly | QFile::Text)) {
qDebug() << "[ERROR] Could not open FST file : " << fst.fileName(); QMessageBox::warning(NULL,
QString("ModelUploader::zip()"),
QString("Could not open FST file."),
QMessageBox::Ok);
return false; return false;
} }
@ -79,7 +87,10 @@ bool FstReader::zip() {
} }
if (_totalSize > MAX_SIZE) { if (_totalSize > MAX_SIZE) {
qDebug() << "[ERROR] Model too big, over " << MAX_SIZE << " Bytes."; QMessageBox::warning(NULL,
QString("ModelUploader::zip()"),
QString("Model too big, over %1 Bytes.").arg(MAX_SIZE),
QMessageBox::Ok);
return false; return false;
} }
@ -95,7 +106,10 @@ bool FstReader::zip() {
} else if (line[1] == FILENAME_FIELD) { } else if (line[1] == FILENAME_FIELD) {
QFileInfo fbx(QFileInfo(fst).path() + "/" + line[1]); QFileInfo fbx(QFileInfo(fst).path() + "/" + line[1]);
if (!fbx.exists() || !fbx.isFile()) { // Check existence if (!fbx.exists() || !fbx.isFile()) { // Check existence
qDebug() << "[ERROR] FBX file " << fbx.absoluteFilePath() << " doesn't exist."; QMessageBox::warning(NULL,
QString("ModelUploader::zip()"),
QString("FBX file %1 could not be found.").arg(fbx.fileName()),
QMessageBox::Ok);
return false; return false;
} }
// Compress and copy // Compress and copy
@ -109,7 +123,10 @@ bool FstReader::zip() {
} else if (line[1] == TEXDIR_FIELD) { // Check existence } else if (line[1] == TEXDIR_FIELD) { // Check existence
QFileInfo texdir(QFileInfo(fst).path() + "/" + line[1]); QFileInfo texdir(QFileInfo(fst).path() + "/" + line[1]);
if (!texdir.exists() || !texdir.isDir()) { if (!texdir.exists() || !texdir.isDir()) {
qDebug() << "[ERROR] Texture directory " << texdir.absolutePath() << " doesn't exist."; QMessageBox::warning(NULL,
QString("ModelUploader::zip()"),
QString("Texture directory could not be found."),
QMessageBox::Ok);
return false; return false;
} }
if (!addTextures(texdir)) { // Recursive compress and copy if (!addTextures(texdir)) { // Recursive compress and copy
@ -118,7 +135,10 @@ bool FstReader::zip() {
} else if (line[1] == LOD_FIELD) { } else if (line[1] == LOD_FIELD) {
QFileInfo lod(QFileInfo(fst).path() + "/" + line[1]); QFileInfo lod(QFileInfo(fst).path() + "/" + line[1]);
if (!lod.exists() || !lod.isFile()) { // Check existence if (!lod.exists() || !lod.isFile()) { // Check existence
qDebug() << "[ERROR] FBX file " << lod.absoluteFilePath() << " doesn't exist."; QMessageBox::warning(NULL,
QString("ModelUploader::zip()"),
QString("FBX file %1 could not be found.").arg(lod.fileName()),
QMessageBox::Ok);
return false; return false;
} }
// Compress and copy // Compress and copy
@ -181,8 +201,6 @@ bool FstReader::addTextures(const QFileInfo& texdir) {
if (!addTextures(info)) { if (!addTextures(info)) {
return false; return false;
} }
} else {
qDebug() << "[DEBUG] Invalid file type : " << info.filePath();
} }
} }
@ -198,7 +216,10 @@ bool FstReader::compressFile(const QString &inFileName, const QString &outFileNa
if (!outFile.open(QIODevice::WriteOnly)) { if (!outFile.open(QIODevice::WriteOnly)) {
QDir(_zipDir.path()).mkpath(QFileInfo(outFileName).path()); QDir(_zipDir.path()).mkpath(QFileInfo(outFileName).path());
if (!outFile.open(QIODevice::WriteOnly)) { if (!outFile.open(QIODevice::WriteOnly)) {
qDebug() << "[ERROR] Could not compress " << inFileName << "."; QMessageBox::warning(NULL,
QString("ModelUploader::compressFile()"),
QString("Could not compress %1").arg(inFileName),
QMessageBox::Ok);
return false; return false;
} }
} }
@ -212,7 +233,10 @@ bool FstReader::compressFile(const QString &inFileName, const QString &outFileNa
bool FstReader::addPart(const QString &path, const QString& name) { bool FstReader::addPart(const QString &path, const QString& name) {
QFile* file = new QFile(path); QFile* file = new QFile(path);
if (!file->open(QIODevice::ReadOnly)) { if (!file->open(QIODevice::ReadOnly)) {
qDebug() << "[ERROR] Couldn't open " << file->fileName(); QMessageBox::warning(NULL,
QString("ModelUploader::addPart()"),
QString("Could not open %1").arg(path),
QMessageBox::Ok);
return false; return false;
} }