mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 19:10:49 +02:00
Merge pull request #2581 from Atlante45/more_upload_fixes
More upload fixes
This commit is contained in:
commit
f12da05722
7 changed files with 82 additions and 50 deletions
|
@ -3613,13 +3613,21 @@ void Application::reloadAllScripts() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::uploadFST() {
|
void Application::uploadFST(bool isHead) {
|
||||||
FstReader reader;
|
FstReader reader(isHead);
|
||||||
if (reader.zip()) {
|
if (reader.zip()) {
|
||||||
reader.send();
|
reader.send();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Application::uploadHead() {
|
||||||
|
uploadFST(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::uploadSkeleton() {
|
||||||
|
uploadFST(false);
|
||||||
|
}
|
||||||
|
|
||||||
void Application::removeScriptName(const QString& fileNameString) {
|
void Application::removeScriptName(const QString& fileNameString) {
|
||||||
_activeScripts.removeOne(fileNameString);
|
_activeScripts.removeOne(fileNameString);
|
||||||
}
|
}
|
||||||
|
|
|
@ -261,7 +261,9 @@ public slots:
|
||||||
void stopAllScripts();
|
void stopAllScripts();
|
||||||
void reloadAllScripts();
|
void reloadAllScripts();
|
||||||
|
|
||||||
void uploadFST();
|
void uploadFST(bool isHead);
|
||||||
|
void uploadHead();
|
||||||
|
void uploadSkeleton();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void timer();
|
void timer();
|
||||||
|
|
|
@ -146,7 +146,8 @@ Menu::Menu() :
|
||||||
SLOT(goTo()));
|
SLOT(goTo()));
|
||||||
|
|
||||||
addDisabledActionAndSeparator(fileMenu, "Upload Avatar Model");
|
addDisabledActionAndSeparator(fileMenu, "Upload Avatar Model");
|
||||||
addActionToQMenuAndActionHash(fileMenu, MenuOption::UploadFST, 0, Application::getInstance(), SLOT(uploadFST()));
|
addActionToQMenuAndActionHash(fileMenu, MenuOption::UploadHead, 0, Application::getInstance(), SLOT(uploadHead()));
|
||||||
|
addActionToQMenuAndActionHash(fileMenu, MenuOption::UploadSkeleton, 0, Application::getInstance(), SLOT(uploadSkeleton()));
|
||||||
|
|
||||||
addDisabledActionAndSeparator(fileMenu, "Settings");
|
addDisabledActionAndSeparator(fileMenu, "Settings");
|
||||||
addActionToQMenuAndActionHash(fileMenu, MenuOption::SettingsImport, 0, this, SLOT(importSettings()));
|
addActionToQMenuAndActionHash(fileMenu, MenuOption::SettingsImport, 0, this, SLOT(importSettings()));
|
||||||
|
|
|
@ -302,7 +302,8 @@ namespace MenuOption {
|
||||||
const QString StopAllScripts = "Stop All Scripts";
|
const QString StopAllScripts = "Stop All Scripts";
|
||||||
const QString TestPing = "Test Ping";
|
const QString TestPing = "Test Ping";
|
||||||
const QString TransmitterDrive = "Transmitter Drive";
|
const QString TransmitterDrive = "Transmitter Drive";
|
||||||
const QString UploadFST = "Upload FST file";
|
const QString UploadHead = "Upload Head Model";
|
||||||
|
const QString UploadSkeleton = "Upload Skeleton Model";
|
||||||
const QString Visage = "Visage";
|
const QString Visage = "Visage";
|
||||||
const QString Quit = "Quit";
|
const QString Quit = "Quit";
|
||||||
const QString Voxels = "Voxels";
|
const QString Voxels = "Voxels";
|
||||||
|
|
|
@ -144,14 +144,15 @@ void AccountManager::invokedRequest(const QString& path, QNetworkAccessManager::
|
||||||
break;
|
break;
|
||||||
case QNetworkAccessManager::PostOperation:
|
case QNetworkAccessManager::PostOperation:
|
||||||
case QNetworkAccessManager::PutOperation:
|
case QNetworkAccessManager::PutOperation:
|
||||||
authenticatedRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
|
||||||
if (dataMultiPart) {
|
if (dataMultiPart) {
|
||||||
if (operation == QNetworkAccessManager::PostOperation) {
|
if (operation == QNetworkAccessManager::PostOperation) {
|
||||||
networkReply = _networkAccessManager->post(authenticatedRequest, dataMultiPart);
|
networkReply = _networkAccessManager->post(authenticatedRequest, dataMultiPart);
|
||||||
} else {
|
} else {
|
||||||
networkReply = _networkAccessManager->put(authenticatedRequest, dataMultiPart);
|
networkReply = _networkAccessManager->put(authenticatedRequest, dataMultiPart);
|
||||||
}
|
}
|
||||||
|
dataMultiPart->setParent(networkReply);
|
||||||
} else {
|
} else {
|
||||||
|
authenticatedRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||||
if (operation == QNetworkAccessManager::PostOperation) {
|
if (operation == QNetworkAccessManager::PostOperation) {
|
||||||
networkReply = _networkAccessManager->post(authenticatedRequest, dataByteArray);
|
networkReply = _networkAccessManager->post(authenticatedRequest, dataByteArray);
|
||||||
} else {
|
} else {
|
||||||
|
@ -199,6 +200,7 @@ void AccountManager::passSuccessToCallback() {
|
||||||
qDebug() << jsonResponse;
|
qDebug() << jsonResponse;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
delete requestReply;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AccountManager::passErrorToCallback(QNetworkReply::NetworkError errorCode) {
|
void AccountManager::passErrorToCallback(QNetworkReply::NetworkError errorCode) {
|
||||||
|
@ -219,6 +221,7 @@ void AccountManager::passErrorToCallback(QNetworkReply::NetworkError errorCode)
|
||||||
qDebug() << "Error" << errorCode << "-" << requestReply->errorString();
|
qDebug() << "Error" << errorCode << "-" << requestReply->errorString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
delete requestReply;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AccountManager::hasValidAccessToken() {
|
bool AccountManager::hasValidAccessToken() {
|
||||||
|
|
|
@ -13,11 +13,11 @@
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QHttpMultiPart>
|
#include <QHttpMultiPart>
|
||||||
|
#include <QTemporaryDir>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
||||||
#include "AccountManager.h"
|
#include "AccountManager.h"
|
||||||
|
|
||||||
#include "FstReader.h"
|
#include "FstReader.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,20 +25,30 @@ static const QString NAME_FIELD = "name";
|
||||||
static const QString FILENAME_FIELD = "filename";
|
static const QString FILENAME_FIELD = "filename";
|
||||||
static const QString TEXDIR_FIELD = "texdir";
|
static const QString TEXDIR_FIELD = "texdir";
|
||||||
static const QString LOD_FIELD = "lod";
|
static const QString LOD_FIELD = "lod";
|
||||||
static const QString HEAD_SPECIFIC_FIELD = "bs";
|
|
||||||
|
|
||||||
static const QString MODEL_URL = "/api/v1/models";
|
static const QString MODEL_URL = "/api/v1/models";
|
||||||
|
|
||||||
static const int MAX_SIZE = 10 * 1024 * 1024; // 10 MB
|
static const int MAX_SIZE = 10 * 1024 * 1024; // 10 MB
|
||||||
|
|
||||||
FstReader::FstReader() :
|
// 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.
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
FstReader::FstReader(bool isHead) :
|
||||||
|
_zipDir(new TemporaryDir()),
|
||||||
_lodCount(-1),
|
_lodCount(-1),
|
||||||
_texturesCount(-1),
|
_texturesCount(-1),
|
||||||
_totalSize(0),
|
_totalSize(0),
|
||||||
_isHead(false),
|
_isHead(isHead),
|
||||||
_readyToSend(false),
|
_readyToSend(false),
|
||||||
_dataMultiPart(new QHttpMultiPart(QHttpMultiPart::FormDataType))
|
_dataMultiPart(new QHttpMultiPart(QHttpMultiPart::FormDataType))
|
||||||
{
|
{
|
||||||
|
_zipDir->setParent(_dataMultiPart);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FstReader::~FstReader() {
|
FstReader::~FstReader() {
|
||||||
|
@ -63,20 +73,20 @@ bool FstReader::zip() {
|
||||||
QString("ModelUploader::zip()"),
|
QString("ModelUploader::zip()"),
|
||||||
QString("Could not open FST file."),
|
QString("Could not open FST file."),
|
||||||
QMessageBox::Ok);
|
QMessageBox::Ok);
|
||||||
return false;
|
qDebug() << "[Warning] " << QString("Could not open FST file.");
|
||||||
}
|
|
||||||
|
|
||||||
// Compress and copy the fst
|
|
||||||
if (!compressFile(QFileInfo(fst).filePath(), _zipDir.path() + "/" + QFileInfo(fst).fileName())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
_totalSize += QFileInfo(fst).size();
|
|
||||||
if (!addPart(_zipDir.path() + "/" + QFileInfo(fst).fileName(),
|
|
||||||
QString("fst"))) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
qDebug() << "Reading FST file : " << QFileInfo(fst).filePath();
|
qDebug() << "Reading FST file : " << QFileInfo(fst).filePath();
|
||||||
|
|
||||||
|
// Compress and copy the fst
|
||||||
|
if (!compressFile(QFileInfo(fst).filePath(), _zipDir->path() + "/" + QFileInfo(fst).fileName())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!addPart(_zipDir->path() + "/" + QFileInfo(fst).fileName(),
|
||||||
|
QString("fst"))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Let's read through the FST file
|
// Let's read through the FST file
|
||||||
QTextStream stream(&fst);
|
QTextStream stream(&fst);
|
||||||
QList<QString> line;
|
QList<QString> line;
|
||||||
|
@ -86,73 +96,63 @@ bool FstReader::zip() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_totalSize > MAX_SIZE) {
|
|
||||||
QMessageBox::warning(NULL,
|
|
||||||
QString("ModelUploader::zip()"),
|
|
||||||
QString("Model too big, over %1 Bytes.").arg(MAX_SIZE),
|
|
||||||
QMessageBox::Ok);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// according to what is read, we modify the command
|
// according to what is read, we modify the command
|
||||||
if (line[1] == HEAD_SPECIFIC_FIELD) {
|
if (line[0] == NAME_FIELD) {
|
||||||
_isHead = true;
|
|
||||||
} else if (line[1] == NAME_FIELD) {
|
|
||||||
QHttpPart textPart;
|
QHttpPart textPart;
|
||||||
textPart.setHeader(QNetworkRequest::ContentDispositionHeader, "form-data;"
|
textPart.setHeader(QNetworkRequest::ContentDispositionHeader, "form-data;"
|
||||||
" name=\"model_name\"");
|
" name=\"model_name\"");
|
||||||
textPart.setBody(line[1].toUtf8());
|
textPart.setBody(line[1].toUtf8());
|
||||||
_dataMultiPart->append(textPart);
|
_dataMultiPart->append(textPart);
|
||||||
} else if (line[1] == FILENAME_FIELD) {
|
} else if (line[0] == 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
|
||||||
QMessageBox::warning(NULL,
|
QMessageBox::warning(NULL,
|
||||||
QString("ModelUploader::zip()"),
|
QString("ModelUploader::zip()"),
|
||||||
QString("FBX file %1 could not be found.").arg(fbx.fileName()),
|
QString("FBX file %1 could not be found.").arg(fbx.fileName()),
|
||||||
QMessageBox::Ok);
|
QMessageBox::Ok);
|
||||||
|
qDebug() << "[Warning] " << QString("FBX file %1 could not be found.").arg(fbx.fileName());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Compress and copy
|
// Compress and copy
|
||||||
if (!compressFile(fbx.filePath(), _zipDir.path() + "/" + line[1])) {
|
if (!compressFile(fbx.filePath(), _zipDir->path() + "/" + line[1])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
_totalSize += fbx.size();
|
if (!addPart(_zipDir->path() + "/" + line[1], "fbx")) {
|
||||||
if (!addPart(_zipDir.path() + "/" + line[1], "fbx")) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (line[1] == TEXDIR_FIELD) { // Check existence
|
} else if (line[0] == 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()) {
|
||||||
QMessageBox::warning(NULL,
|
QMessageBox::warning(NULL,
|
||||||
QString("ModelUploader::zip()"),
|
QString("ModelUploader::zip()"),
|
||||||
QString("Texture directory could not be found."),
|
QString("Texture directory could not be found."),
|
||||||
QMessageBox::Ok);
|
QMessageBox::Ok);
|
||||||
|
qDebug() << "[Warning] " << QString("Texture directory could not be found.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!addTextures(texdir)) { // Recursive compress and copy
|
if (!addTextures(texdir)) { // Recursive compress and copy
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (line[1] == LOD_FIELD) {
|
} else if (line[0] == 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
|
||||||
QMessageBox::warning(NULL,
|
QMessageBox::warning(NULL,
|
||||||
QString("ModelUploader::zip()"),
|
QString("ModelUploader::zip()"),
|
||||||
QString("FBX file %1 could not be found.").arg(lod.fileName()),
|
QString("FBX file %1 could not be found.").arg(lod.fileName()),
|
||||||
QMessageBox::Ok);
|
QMessageBox::Ok);
|
||||||
|
qDebug() << "[Warning] " << QString("FBX file %1 could not be found.").arg(lod.fileName());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Compress and copy
|
// Compress and copy
|
||||||
if (!compressFile(lod.filePath(), _zipDir.path() + "/" + line[1])) {
|
if (!compressFile(lod.filePath(), _zipDir->path() + "/" + line[1])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
_totalSize += lod.size();
|
if (!addPart(_zipDir->path() + "/" + line[1], QString("lod%1").arg(++_lodCount))) {
|
||||||
if (!addPart(_zipDir.path() + "/" + line[1], QString("lod%1").arg(++_lodCount))) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QHttpPart textPart;
|
QHttpPart textPart;
|
||||||
textPart.setHeader(QNetworkRequest::ContentDispositionHeader, "form-data;"
|
textPart.setHeader(QNetworkRequest::ContentDispositionHeader, "form-data;"
|
||||||
" name=\"model_category\"");
|
" name=\"model_category\"");
|
||||||
|
@ -173,6 +173,9 @@ bool FstReader::send() {
|
||||||
}
|
}
|
||||||
|
|
||||||
AccountManager::getInstance().authenticatedRequest(MODEL_URL, QNetworkAccessManager::PostOperation, JSONCallbackParameters(), QByteArray(), _dataMultiPart);
|
AccountManager::getInstance().authenticatedRequest(MODEL_URL, QNetworkAccessManager::PostOperation, JSONCallbackParameters(), QByteArray(), _dataMultiPart);
|
||||||
|
_zipDir = NULL;
|
||||||
|
_dataMultiPart = NULL;
|
||||||
|
qDebug() << "Model sent.";
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -189,11 +192,10 @@ bool FstReader::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 (!compressFile(info.filePath(), _zipDir->path() + "/" + info.fileName())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
_totalSize += info.size();
|
if (!addPart(_zipDir->path() + "/" + info.fileName(),
|
||||||
if (!addPart(_zipDir.path() + "/" + info.fileName(),
|
|
||||||
QString("texture%1").arg(++_texturesCount))) {
|
QString("texture%1").arg(++_texturesCount))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -214,12 +216,13 @@ bool FstReader::compressFile(const QString &inFileName, const QString &outFileNa
|
||||||
|
|
||||||
QFile outFile(outFileName);
|
QFile outFile(outFileName);
|
||||||
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)) {
|
||||||
QMessageBox::warning(NULL,
|
QMessageBox::warning(NULL,
|
||||||
QString("ModelUploader::compressFile()"),
|
QString("ModelUploader::compressFile()"),
|
||||||
QString("Could not compress %1").arg(inFileName),
|
QString("Could not compress %1").arg(inFileName),
|
||||||
QMessageBox::Ok);
|
QMessageBox::Ok);
|
||||||
|
qDebug() << "[Warning] " << QString("Could not compress %1").arg(inFileName);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -237,6 +240,8 @@ bool FstReader::addPart(const QString &path, const QString& name) {
|
||||||
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);
|
||||||
|
delete file;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,6 +254,19 @@ bool FstReader::addPart(const QString &path, const QString& name) {
|
||||||
_dataMultiPart->append(part);
|
_dataMultiPart->append(part);
|
||||||
file->setParent(_dataMultiPart);
|
file->setParent(_dataMultiPart);
|
||||||
|
|
||||||
|
|
||||||
|
qDebug() << "File " << QFileInfo(*file).fileName() << " added to model.";
|
||||||
|
_totalSize += file->size();
|
||||||
|
if (_totalSize > MAX_SIZE) {
|
||||||
|
QMessageBox::warning(NULL,
|
||||||
|
QString("ModelUploader::zip()"),
|
||||||
|
QString("Model too big, over %1 Bytes.").arg(MAX_SIZE),
|
||||||
|
QMessageBox::Ok);
|
||||||
|
qDebug() << "[Warning] " << QString("Model too big, over %1 Bytes.").arg(MAX_SIZE);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
qDebug() << "Current model size: " << _totalSize;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,20 +10,19 @@
|
||||||
#ifndef __hifi__FstReader__
|
#ifndef __hifi__FstReader__
|
||||||
#define __hifi__FstReader__
|
#define __hifi__FstReader__
|
||||||
|
|
||||||
#include <QTemporaryDir>
|
class TemporaryDir;
|
||||||
|
|
||||||
class QHttpMultiPart;
|
class QHttpMultiPart;
|
||||||
|
|
||||||
class FstReader {
|
class FstReader : public QObject {
|
||||||
public:
|
public:
|
||||||
FstReader();
|
FstReader(bool isHead);
|
||||||
~FstReader();
|
~FstReader();
|
||||||
|
|
||||||
bool zip();
|
bool zip();
|
||||||
bool send();
|
bool send();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QTemporaryDir _zipDir;
|
TemporaryDir* _zipDir;
|
||||||
int _lodCount;
|
int _lodCount;
|
||||||
int _texturesCount;
|
int _texturesCount;
|
||||||
int _totalSize;
|
int _totalSize;
|
||||||
|
|
Loading…
Reference in a new issue