Merge pull request #100 from birarda/atp-mappings

add to world on upload, trim for paths
This commit is contained in:
Clément Brisset 2016-03-10 17:00:35 -08:00
commit 49ce6a87fe
5 changed files with 51 additions and 30 deletions

View file

@ -509,7 +509,8 @@ bool AssetServer::writeMappingsToFile() {
return false; return false;
} }
bool AssetServer::setMapping(const AssetPath& path, const AssetHash& hash) { bool AssetServer::setMapping(AssetPath path, AssetHash hash) {
path = path.trimmed();
if (!isValidPath(path)) { if (!isValidPath(path)) {
qWarning() << "Cannot set a mapping for invalid path:" << path << "=>" << hash; qWarning() << "Cannot set a mapping for invalid path:" << path << "=>" << hash;
@ -550,13 +551,15 @@ bool pathIsFolder(const AssetPath& path) {
return path.endsWith('/'); return path.endsWith('/');
} }
bool AssetServer::deleteMappings(const AssetPathList& paths) { bool AssetServer::deleteMappings(AssetPathList& paths) {
// take a copy of the current mappings in case persistence of these deletes fails // take a copy of the current mappings in case persistence of these deletes fails
auto oldMappings = _fileMappings; auto oldMappings = _fileMappings;
// enumerate the paths to delete and remove them all // enumerate the paths to delete and remove them all
for (auto& path : paths) { for (auto& path : paths) {
path = path.trimmed();
// figure out if this path will delete a file or folder // figure out if this path will delete a file or folder
if (pathIsFolder(path)) { if (pathIsFolder(path)) {
// enumerate the in memory file mappings and remove anything that matches // enumerate the in memory file mappings and remove anything that matches
@ -602,7 +605,10 @@ bool AssetServer::deleteMappings(const AssetPathList& paths) {
} }
} }
bool AssetServer::renameMapping(const AssetPath& oldPath, const AssetPath& newPath) { bool AssetServer::renameMapping(AssetPath oldPath, AssetPath newPath) {
oldPath = oldPath.trimmed();
newPath = newPath.trimmed();
if (!isValidPath(oldPath) || !isValidPath(newPath)) { if (!isValidPath(oldPath) || !isValidPath(newPath)) {
qWarning() << "Cannot perform rename with invalid paths - both should have leading forward slashes:" qWarning() << "Cannot perform rename with invalid paths - both should have leading forward slashes:"
<< oldPath << "=>" << newPath; << oldPath << "=>" << newPath;

View file

@ -52,13 +52,13 @@ private:
bool writeMappingsToFile(); bool writeMappingsToFile();
/// Set the mapping for path to hash /// Set the mapping for path to hash
bool setMapping(const AssetPath& path, const AssetHash& hash); bool setMapping(AssetPath path, AssetHash hash);
/// Delete mapping `path`. Returns `true` if deletion of mappings succeeds, else `false`. /// Delete mapping `path`. Returns `true` if deletion of mappings succeeds, else `false`.
bool deleteMappings(const AssetPathList& paths); bool deleteMappings(AssetPathList& paths);
/// Rename mapping from `oldPath` to `newPath`. Returns true if successful /// Rename mapping from `oldPath` to `newPath`. Returns true if successful
bool renameMapping(const AssetPath& oldPath, const AssetPath& newPath); bool renameMapping(AssetPath oldPath, AssetPath newPath);
void performMappingMigration(); void performMappingMigration();

View file

@ -55,23 +55,20 @@ Window {
Assets.deleteMappings(path, function(err) { Assets.deleteMappings(path, function(err) {
if (err) { if (err) {
console.log("Error deleting path: ", path, err); console.log("Asset browser - error deleting path: ", path, err);
box = errorMessageBox("There was an error deleting:\n" + path + "\n" + Assets.getErrorString(err)); box = errorMessageBox("There was an error deleting:\n" + path + "\n" + Assets.getErrorString(err));
box.selected.connect(reload); box.selected.connect(reload);
} else { } else {
console.log("Finished deleting path: ", path); console.log("Asset browser - finished deleting path: ", path);
reload(); reload();
} }
}); });
} }
function doUploadFile(path, mapping, addToWorld) {
console.log("Uploading " + path + " to " + mapping + " (addToWorld: " + addToWorld + ")");
}
function doRenameFile(oldPath, newPath) { function doRenameFile(oldPath, newPath) {
if (newPath[0] != "/") { if (newPath[0] != "/") {
newPath = "/" + newPath; newPath = "/" + newPath;
} }
@ -81,14 +78,15 @@ Window {
box.selected.connect(reload); box.selected.connect(reload);
} }
console.log("Renaming " + oldPath + " to " + newPath); console.log("Asset browser - renaming " + oldPath + " to " + newPath);
Assets.renameMapping(oldPath, newPath, function(err) { Assets.renameMapping(oldPath, newPath, function(err) {
if (err) { if (err) {
console.log("Error renaming: ", oldPath, "=>", newPath, " - error ", err); console.log("Asset browser - error renaming: ", oldPath, "=>", newPath, " - error ", err);
box = errorMessageBox("There was an error renaming:\n" + oldPath + " to " + newPath + "\n" + Assets.getErrorString(err)); box = errorMessageBox("There was an error renaming:\n" + oldPath + " to " + newPath + "\n" + Assets.getErrorString(err));
box.selected.connect(reload); box.selected.connect(reload);
} else { } else {
console.log("Finished rename: ", oldPath, "=>", newPath); console.log("Asset browser - finished rename: ", oldPath, "=>", newPath);
} }
reload(); reload();
@ -123,7 +121,6 @@ Window {
} }
function reload() { function reload() {
print("reload");
Assets.mappingModel.refresh(); Assets.mappingModel.refresh();
} }
@ -134,16 +131,22 @@ Window {
); );
} }
function addToWorld() { function addToWorld(url) {
var url = assetProxyModel.data(treeView.currentIndex, 0x103); if (!url) {
url = assetProxyModel.data(treeView.currentIndex, 0x103);
}
if (!url || !canAddToWorld(url)) { if (!url || !canAddToWorld(url)) {
return; return;
} }
console.log("Asset browser - adding asset " + url + " to world.");
var addPosition = Vec3.sum(MyAvatar.position, Vec3.multiply(2, Quat.getFront(MyAvatar.orientation))); var addPosition = Vec3.sum(MyAvatar.position, Vec3.multiply(2, Quat.getFront(MyAvatar.orientation)));
Entities.addModelEntity(url, addPosition); Entities.addModelEntity(url, addPosition);
} }
function copyURLToClipboard() { function copyURLToClipboard(index) {
if (!index) { if (!index) {
index = treeView.currentIndex; index = treeView.currentIndex;
} }
@ -170,6 +173,8 @@ Window {
placeholderText: "Enter path here" placeholderText: "Enter path here"
}); });
object.selected.connect(function(destinationPath) { object.selected.connect(function(destinationPath) {
destinationPath = destinationPath.trim();
if (path == destinationPath) { if (path == destinationPath) {
return; return;
} }
@ -227,7 +232,7 @@ Window {
uploadOpen = true; uploadOpen = true;
var fileUrl = fileUrlTextField.text var fileUrl = fileUrlTextField.text
var addToWorld = addToWorldCheckBox.checked var shouldAddToWorld = addToWorldCheckBox.checked
var path = assetProxyModel.data(treeView.currentIndex, 0x100); var path = assetProxyModel.data(treeView.currentIndex, 0x100);
var directory = path ? path.slice(0, path.lastIndexOf('/') + 1) : "/"; var directory = path ? path.slice(0, path.lastIndexOf('/') + 1) : "/";
@ -235,13 +240,18 @@ Window {
Assets.uploadFile(fileUrl, directory + filename, function(err) { Assets.uploadFile(fileUrl, directory + filename, function(err) {
if (err) { if (err) {
console.log("Error uploading: ", fileUrl, " - error ", err); console.log("Asset Browser - error uploading: ", fileUrl, " - error ", err);
errorMessage("There was an error uploading:\n" + fileUrl + "\n" + Assets.getErrorString(err)); var box = errorMessage("There was an error uploading:\n" + fileUrl + "\n" + Assets.getErrorString(err));
box.selected.connect(reload);
} else { } else {
console.log("Finished uploading: ", fileUrl); console.log("Asset Browser - finished uploading: ", fileUrl);
}
reload(); if (shouldAddToWorld) {
addToWorld("atp:" + directory + filename);
}
reload();
}
}); });
uploadOpen = false; uploadOpen = false;
} }

View file

@ -88,13 +88,15 @@ void AssetMappingsScriptingInterface::uploadFile(QString path, QString mapping,
return; return;
} }
mapping = result.toString(); mapping = result.toString();
mapping = mapping.trimmed();
if (mapping[0] != '/') { if (mapping[0] != '/') {
mapping = "/" + mapping; mapping = "/" + mapping;
} }
// Check for override // Check for override
if (isKnownMapping(mapping)) { if (isKnownMapping(mapping)) {
auto message = path + "\n" + "This file already exists. Do you want to overwrite it?"; auto message = mapping + "\n" + "This file already exists. Do you want to overwrite it?";
auto button = offscreenUi->messageBox(OffscreenUi::ICON_QUESTION, "Overwrite File", message, auto button = offscreenUi->messageBox(OffscreenUi::ICON_QUESTION, "Overwrite File", message,
QMessageBox::Yes | QMessageBox::No, QMessageBox::No); QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
if (button == QMessageBox::No) { if (button == QMessageBox::No) {

View file

@ -25,7 +25,7 @@ void MappingRequest::start() {
doStart(); doStart();
}; };
GetMappingRequest::GetMappingRequest(const AssetPath& path) : _path(path) { GetMappingRequest::GetMappingRequest(const AssetPath& path) : _path(path.trimmed()) {
}; };
void GetMappingRequest::doStart() { void GetMappingRequest::doStart() {
@ -97,7 +97,7 @@ void GetAllMappingsRequest::doStart() {
}; };
SetMappingRequest::SetMappingRequest(const AssetPath& path, const AssetHash& hash) : SetMappingRequest::SetMappingRequest(const AssetPath& path, const AssetHash& hash) :
_path(path), _path(path.trimmed()),
_hash(hash) _hash(hash)
{ {
@ -138,6 +138,9 @@ void SetMappingRequest::doStart() {
}; };
DeleteMappingsRequest::DeleteMappingsRequest(const AssetPathList& paths) : _paths(paths) { DeleteMappingsRequest::DeleteMappingsRequest(const AssetPathList& paths) : _paths(paths) {
for (auto& path : _paths) {
path = path.trimmed();
}
}; };
void DeleteMappingsRequest::doStart() { void DeleteMappingsRequest::doStart() {
@ -175,8 +178,8 @@ void DeleteMappingsRequest::doStart() {
}; };
RenameMappingRequest::RenameMappingRequest(const AssetPath& oldPath, const AssetPath& newPath) : RenameMappingRequest::RenameMappingRequest(const AssetPath& oldPath, const AssetPath& newPath) :
_oldPath(oldPath), _oldPath(oldPath.trimmed()),
_newPath(newPath) _newPath(newPath.trimmed())
{ {
} }