mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 17:41:12 +02:00
Removed all the temporaryDir junk
This commit is contained in:
parent
262c6d3206
commit
3be2319081
2 changed files with 14 additions and 65 deletions
|
@ -15,7 +15,6 @@
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QProgressBar>
|
#include <QProgressBar>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QTemporaryDir>
|
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
|
@ -35,16 +34,8 @@ static const int MAX_SIZE = 10 * 1024 * 1024; // 10 MB
|
||||||
static const int TIMEOUT = 1000;
|
static const int TIMEOUT = 1000;
|
||||||
static const int MAX_CHECK = 30;
|
static const int MAX_CHECK = 30;
|
||||||
|
|
||||||
// Class providing the QObject parent system to QTemporaryDir
|
|
||||||
class TemporaryDir : public QTemporaryDir, public QObject {
|
|
||||||
public:
|
|
||||||
virtual ~TemporaryDir() {
|
|
||||||
// ensuring the entire object gets deleted by the QObject parent.
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ModelUploader::ModelUploader(bool isHead) :
|
ModelUploader::ModelUploader(bool isHead) :
|
||||||
_zipDir(new TemporaryDir()),
|
|
||||||
_lodCount(-1),
|
_lodCount(-1),
|
||||||
_texturesCount(-1),
|
_texturesCount(-1),
|
||||||
_totalSize(0),
|
_totalSize(0),
|
||||||
|
@ -53,7 +44,6 @@ ModelUploader::ModelUploader(bool isHead) :
|
||||||
_dataMultiPart(new QHttpMultiPart(QHttpMultiPart::FormDataType)),
|
_dataMultiPart(new QHttpMultiPart(QHttpMultiPart::FormDataType)),
|
||||||
_numberOfChecks(MAX_CHECK)
|
_numberOfChecks(MAX_CHECK)
|
||||||
{
|
{
|
||||||
_zipDir->setParent(_dataMultiPart);
|
|
||||||
connect(&_timer, SIGNAL(timeout()), SLOT(checkS3()));
|
connect(&_timer, SIGNAL(timeout()), SLOT(checkS3()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,11 +76,7 @@ bool ModelUploader::zip() {
|
||||||
qDebug() << "Reading FST file : " << QFileInfo(fst).filePath();
|
qDebug() << "Reading FST file : " << QFileInfo(fst).filePath();
|
||||||
|
|
||||||
// Compress and copy the fst
|
// Compress and copy the fst
|
||||||
if (!compressFile(QFileInfo(fst).filePath(), _zipDir->path() + "/" + QFileInfo(fst).fileName())) {
|
if (!addPart(QFileInfo(fst).filePath(), QString("fst"))) {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!addPart(_zipDir->path() + "/" + QFileInfo(fst).fileName(),
|
|
||||||
QString("fst"))) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,10 +108,7 @@ bool ModelUploader::zip() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Compress and copy
|
// Compress and copy
|
||||||
if (!compressFile(fbx.filePath(), _zipDir->path() + "/" + line[1])) {
|
if (!addPart(fbx.filePath(), "fbx")) {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!addPart(_zipDir->path() + "/" + line[1], "fbx")) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (line[0] == TEXDIR_FIELD) { // Check existence
|
} else if (line[0] == TEXDIR_FIELD) { // Check existence
|
||||||
|
@ -152,10 +135,7 @@ bool ModelUploader::zip() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Compress and copy
|
// Compress and copy
|
||||||
if (!compressFile(lod.filePath(), _zipDir->path() + "/" + line[1])) {
|
if (!addPart(lod.filePath(), QString("lod%1").arg(++_lodCount))) {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!addPart(_zipDir->path() + "/" + line[1], QString("lod%1").arg(++_lodCount))) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -189,7 +169,6 @@ void ModelUploader::send() {
|
||||||
callbackParams.updateSlot = SLOT(uploadUpdate(qint64, qint64));
|
callbackParams.updateSlot = SLOT(uploadUpdate(qint64, qint64));
|
||||||
|
|
||||||
AccountManager::getInstance().authenticatedRequest(MODEL_URL, QNetworkAccessManager::PostOperation, callbackParams, QByteArray(), _dataMultiPart);
|
AccountManager::getInstance().authenticatedRequest(MODEL_URL, QNetworkAccessManager::PostOperation, callbackParams, QByteArray(), _dataMultiPart);
|
||||||
_zipDir = NULL;
|
|
||||||
_dataMultiPart = NULL;
|
_dataMultiPart = NULL;
|
||||||
qDebug() << "Sending model...";
|
qDebug() << "Sending model...";
|
||||||
_progressDialog = new QDialog();
|
_progressDialog = new QDialog();
|
||||||
|
@ -287,11 +266,7 @@ bool ModelUploader::addTextures(const QFileInfo& texdir) {
|
||||||
foreach (QFileInfo info, list) {
|
foreach (QFileInfo info, list) {
|
||||||
if (info.isFile()) {
|
if (info.isFile()) {
|
||||||
// Compress and copy
|
// Compress and copy
|
||||||
if (!compressFile(info.filePath(), _zipDir->path() + "/" + info.fileName())) {
|
if (!addPart(info.filePath(), QString("texture%1").arg(++_texturesCount))) {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!addPart(_zipDir->path() + "/" + info.fileName(),
|
|
||||||
QString("texture%1").arg(++_texturesCount))) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (info.isDir()) {
|
} else if (info.isDir()) {
|
||||||
|
@ -304,54 +279,30 @@ bool ModelUploader::addTextures(const QFileInfo& texdir) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ModelUploader::compressFile(const QString &inFileName, const QString &outFileName) {
|
|
||||||
QFile inFile(inFileName);
|
|
||||||
inFile.open(QIODevice::ReadOnly);
|
|
||||||
QByteArray buffer = inFile.readAll();
|
|
||||||
|
|
||||||
QFile outFile(outFileName);
|
|
||||||
if (!outFile.open(QIODevice::WriteOnly)) {
|
|
||||||
QDir(_zipDir->path()).mkpath(QFileInfo(outFileName).path());
|
|
||||||
if (!outFile.open(QIODevice::WriteOnly)) {
|
|
||||||
QMessageBox::warning(NULL,
|
|
||||||
QString("ModelUploader::compressFile()"),
|
|
||||||
QString("Could not compress %1").arg(inFileName),
|
|
||||||
QMessageBox::Ok);
|
|
||||||
qDebug() << "[Warning] " << QString("Could not compress %1").arg(inFileName);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
QDataStream out(&outFile);
|
|
||||||
out << qCompress(buffer);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool ModelUploader::addPart(const QString &path, const QString& name) {
|
bool ModelUploader::addPart(const QString &path, const QString& name) {
|
||||||
QFile* file = new QFile(path);
|
QFile file(path);
|
||||||
if (!file->open(QIODevice::ReadOnly)) {
|
if (!file.open(QIODevice::ReadOnly)) {
|
||||||
QMessageBox::warning(NULL,
|
QMessageBox::warning(NULL,
|
||||||
QString("ModelUploader::addPart()"),
|
QString("ModelUploader::addPart()"),
|
||||||
QString("Could not open %1").arg(path),
|
QString("Could not open %1").arg(path),
|
||||||
QMessageBox::Ok);
|
QMessageBox::Ok);
|
||||||
qDebug() << "[Warning] " << QString("Could not open %1").arg(path);
|
qDebug() << "[Warning] " << QString("Could not open %1").arg(path);
|
||||||
delete file;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
QByteArray buffer = qCompress(file.readAll());
|
||||||
|
buffer.remove(0, 4);
|
||||||
|
|
||||||
QHttpPart part;
|
QHttpPart part;
|
||||||
part.setHeader(QNetworkRequest::ContentDispositionHeader, "form-data;"
|
part.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data;"
|
||||||
" name=\"" + name.toUtf8() + "\";"
|
" name=\"" + name.toUtf8() + "\";"
|
||||||
" filename=\"" + QFileInfo(*file).fileName().toUtf8() + "\"");
|
" filename=\"" + QFileInfo(file).fileName().toUtf8() + "\""));
|
||||||
part.setHeader(QNetworkRequest::ContentTypeHeader, "application/octet-stream");
|
part.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/octet-stream"));
|
||||||
part.setBodyDevice(file);
|
part.setBody(buffer);
|
||||||
_dataMultiPart->append(part);
|
_dataMultiPart->append(part);
|
||||||
file->setParent(_dataMultiPart);
|
|
||||||
|
|
||||||
|
|
||||||
qDebug() << "File " << QFileInfo(*file).fileName() << " added to model.";
|
qDebug() << "File " << QFileInfo(file).fileName() << " added to model.";
|
||||||
_totalSize += file->size();
|
_totalSize += file.size();
|
||||||
if (_totalSize > MAX_SIZE) {
|
if (_totalSize > MAX_SIZE) {
|
||||||
QMessageBox::warning(NULL,
|
QMessageBox::warning(NULL,
|
||||||
QString("ModelUploader::zip()"),
|
QString("ModelUploader::zip()"),
|
||||||
|
|
|
@ -38,7 +38,6 @@ private slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString _url;
|
QString _url;
|
||||||
TemporaryDir* _zipDir;
|
|
||||||
int _lodCount;
|
int _lodCount;
|
||||||
int _texturesCount;
|
int _texturesCount;
|
||||||
int _totalSize;
|
int _totalSize;
|
||||||
|
@ -57,7 +56,6 @@ private:
|
||||||
|
|
||||||
bool zip();
|
bool zip();
|
||||||
bool addTextures(const QFileInfo& texdir);
|
bool addTextures(const QFileInfo& texdir);
|
||||||
bool compressFile(const QString& inFileName, const QString& outFileName);
|
|
||||||
bool addPart(const QString& path, const QString& name);
|
bool addPart(const QString& path, const QString& name);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue