mirror of
https://github.com/Armored-Dragon/overte.git
synced 2025-03-11 16:13:16 +01:00
Add uploadFile method that prompts the user
This commit is contained in:
parent
dc79d3262a
commit
7d7a683b18
6 changed files with 74 additions and 36 deletions
|
@ -159,7 +159,7 @@ Window {
|
|||
|
||||
var object = desktop.inputDialog({
|
||||
label: "Enter new path:",
|
||||
prefilledText: path,
|
||||
current: path,
|
||||
placeholderText: "Enter path here"
|
||||
});
|
||||
object.selected.connect(function(destinationPath) {
|
||||
|
@ -220,18 +220,12 @@ Window {
|
|||
var directory = path ? path.slice(0, path.lastIndexOf('/') + 1) : "";
|
||||
var filename = fileUrl.slice(fileUrl.lastIndexOf('/') + 1);
|
||||
|
||||
var object = desktop.inputDialog({
|
||||
label: "Enter asset path:",
|
||||
prefilledText: directory + filename,
|
||||
placeholderText: "Enter path here"
|
||||
});
|
||||
object.selected.connect(function(destinationPath) {
|
||||
if (fileExists(destinationPath)) {
|
||||
askForOverride(fileUrl, function() {
|
||||
doUploadFile(fileUrl, destinationPath, addToWorld);
|
||||
});
|
||||
Assets.uploadFile(fileUrl, directory + filename, function(err) {
|
||||
if (err) {
|
||||
console.log("Error uploading: ", fileUrl, " - error ", err);
|
||||
errorMessage("There was an error uploading:\n" + fileUrl + "\n\nPlease try again.");
|
||||
} else {
|
||||
doUploadFile(fileUrl, destinationPath, addToWorld);
|
||||
console.log("Finished uploading: ", fileUrl);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -34,12 +34,10 @@ ModalWindow {
|
|||
property var items;
|
||||
property string label
|
||||
property var result;
|
||||
// FIXME not current honored
|
||||
property var current;
|
||||
property alias current: textResult.text
|
||||
|
||||
// For text boxes
|
||||
property alias placeholderText: textResult.placeholderText
|
||||
property alias prefilledText: textResult.text
|
||||
|
||||
// For combo boxes
|
||||
property bool editable: true;
|
||||
|
|
|
@ -66,7 +66,6 @@
|
|||
#include <BuildInfo.h>
|
||||
#include <AssetClient.h>
|
||||
#include <AssetUpload.h>
|
||||
#include <AssetMappingsScriptingInterface.h>
|
||||
#include <AutoUpdater.h>
|
||||
#include <AudioInjectorManager.h>
|
||||
#include <CursorManager.h>
|
||||
|
@ -142,6 +141,7 @@
|
|||
#include "ModelPackager.h"
|
||||
#include "PluginContainerProxy.h"
|
||||
#include "scripting/AccountScriptingInterface.h"
|
||||
#include "scripting/AssetMappingsScriptingInterface.h"
|
||||
#include "scripting/AudioDeviceScriptingInterface.h"
|
||||
#include "scripting/ClipboardScriptingInterface.h"
|
||||
#include "scripting/DesktopScriptingInterface.h"
|
||||
|
|
|
@ -12,11 +12,13 @@
|
|||
#include "AssetMappingsScriptingInterface.h"
|
||||
|
||||
#include <QtScript/QScriptEngine>
|
||||
#include <QtCore/QFile>
|
||||
|
||||
#include <AssetRequest.h>
|
||||
#include <AssetUpload.h>
|
||||
#include <MappingRequest.h>
|
||||
#include <NetworkLogging.h>
|
||||
#include <OffscreenUi.h>
|
||||
|
||||
AssetMappingsScriptingInterface::AssetMappingsScriptingInterface() {
|
||||
_proxyModel.setSourceModel(&_assetMappingModel);
|
||||
|
@ -51,12 +53,12 @@ void AssetMappingsScriptingInterface::setMapping(QString path, QString hash, QJS
|
|||
auto request = assetClient->createSetMappingRequest(path, hash);
|
||||
|
||||
connect(request, &SetMappingRequest::finished, this, [this, callback](SetMappingRequest* request) mutable {
|
||||
QJSValueList args { uint8_t(request->getError()) };
|
||||
|
||||
callback.call(args);
|
||||
if (callback.isCallable()) {
|
||||
QJSValueList args { uint8_t(request->getError()) };
|
||||
callback.call(args);
|
||||
}
|
||||
|
||||
request->deleteLater();
|
||||
|
||||
});
|
||||
|
||||
request->start();
|
||||
|
@ -67,28 +69,70 @@ void AssetMappingsScriptingInterface::getMapping(QString path, QJSValue callback
|
|||
auto request = assetClient->createGetMappingRequest(path);
|
||||
|
||||
connect(request, &GetMappingRequest::finished, this, [this, callback](GetMappingRequest* request) mutable {
|
||||
QJSValueList args { uint8_t(request->getError()), request->getHash() };
|
||||
|
||||
callback.call(args);
|
||||
if (callback.isCallable()) {
|
||||
QJSValueList args { uint8_t(request->getError()) };
|
||||
callback.call(args);
|
||||
}
|
||||
|
||||
request->deleteLater();
|
||||
|
||||
});
|
||||
|
||||
request->start();
|
||||
}
|
||||
|
||||
void AssetMappingsScriptingInterface::uploadFile(QString path, QString mapping, QJSValue callback) {
|
||||
QFile file(path);
|
||||
if (!file.open(QFile::ReadOnly)) {
|
||||
qCWarning(asset_client) << "Error uploading file to asset server:\n"
|
||||
<< "Could not open" << qPrintable(path);
|
||||
OffscreenUi::warning("File Error", "Could not open file: " + path, QMessageBox::Ok);
|
||||
return;
|
||||
}
|
||||
|
||||
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
||||
auto result = offscreenUi->inputDialog(OffscreenUi::ICON_NONE, "Enter asset path:", "", mapping);
|
||||
if (!result.isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check for override
|
||||
if (isKnownMapping(result.toString())) {
|
||||
auto message = "The following file already exists:\n" + path + "\nDo you want to override it?";
|
||||
auto button = offscreenUi->messageBox(OffscreenUi::ICON_QUESTION, "", message,
|
||||
QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
|
||||
if (button == QMessageBox::No) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
auto upload = DependencyManager::get<AssetClient>()->createUpload(file.readAll());
|
||||
QObject::connect(upload, &AssetUpload::finished, this, [=](AssetUpload* upload, const QString& hash) mutable {
|
||||
if (upload->getError() != AssetUpload::NoError) {
|
||||
if (callback.isCallable()) {
|
||||
QJSValueList args { uint8_t(upload->getError()) };
|
||||
callback.call(args);
|
||||
}
|
||||
} else {
|
||||
setMapping(mapping, hash, callback);
|
||||
}
|
||||
|
||||
upload->deleteLater();
|
||||
});
|
||||
|
||||
upload->start();
|
||||
}
|
||||
|
||||
void AssetMappingsScriptingInterface::deleteMappings(QStringList paths, QJSValue callback) {
|
||||
auto assetClient = DependencyManager::get<AssetClient>();
|
||||
auto request = assetClient->createDeleteMappingsRequest(paths);
|
||||
|
||||
connect(request, &DeleteMappingsRequest::finished, this, [this, callback](DeleteMappingsRequest* request) mutable {
|
||||
QJSValueList args { uint8_t(request->getError()) };
|
||||
|
||||
callback.call(args);
|
||||
if (callback.isCallable()) {
|
||||
QJSValueList args { uint8_t(request->getError()) };
|
||||
callback.call(args);
|
||||
}
|
||||
|
||||
request->deleteLater();
|
||||
|
||||
});
|
||||
|
||||
request->start();
|
||||
|
@ -106,12 +150,12 @@ void AssetMappingsScriptingInterface::getAllMappings(QJSValue callback) {
|
|||
map.setProperty(kv.first, kv.second);
|
||||
}
|
||||
|
||||
QJSValueList args { uint8_t(request->getError()), map };
|
||||
|
||||
callback.call(args);
|
||||
if (callback.isCallable()) {
|
||||
QJSValueList args { uint8_t(request->getError()) };
|
||||
callback.call(args);
|
||||
}
|
||||
|
||||
request->deleteLater();
|
||||
|
||||
});
|
||||
|
||||
request->start();
|
||||
|
@ -122,12 +166,12 @@ void AssetMappingsScriptingInterface::renameMapping(QString oldPath, QString new
|
|||
auto request = assetClient->createRenameMappingRequest(oldPath, newPath);
|
||||
|
||||
connect(request, &RenameMappingRequest::finished, this, [this, callback](RenameMappingRequest* request) mutable {
|
||||
QJSValueList args { uint8_t(request->getError()) };
|
||||
|
||||
callback.call(args);
|
||||
if (callback.isCallable()) {
|
||||
QJSValueList args { uint8_t(request->getError()) };
|
||||
callback.call(args);
|
||||
}
|
||||
|
||||
request->deleteLater();
|
||||
|
||||
});
|
||||
|
||||
request->start();
|
|
@ -61,6 +61,7 @@ public:
|
|||
|
||||
Q_INVOKABLE void setMapping(QString path, QString hash, QJSValue callback);
|
||||
Q_INVOKABLE void getMapping(QString path, QJSValue callback);
|
||||
Q_INVOKABLE void uploadFile(QString path, QString mapping, QJSValue callback = QJSValue());
|
||||
Q_INVOKABLE void deleteMappings(QStringList paths, QJSValue callback);
|
||||
Q_INVOKABLE void deleteMapping(QString path, QJSValue callback) { deleteMappings(QStringList(path), callback); }
|
||||
Q_INVOKABLE void getAllMappings(QJSValue callback);
|
|
@ -64,6 +64,7 @@ class SetMappingRequest : public MappingRequest {
|
|||
public:
|
||||
SetMappingRequest(const AssetPath& path, const AssetHash& hash);
|
||||
|
||||
AssetPath getPath() const { return _path; }
|
||||
AssetHash getHash() const { return _hash; }
|
||||
|
||||
signals:
|
||||
|
|
Loading…
Reference in a new issue