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;
}
bool AssetServer::setMapping(const AssetPath& path, const AssetHash& hash) {
bool AssetServer::setMapping(AssetPath path, AssetHash hash) {
path = path.trimmed();
if (!isValidPath(path)) {
qWarning() << "Cannot set a mapping for invalid path:" << path << "=>" << hash;
@ -550,13 +551,15 @@ bool pathIsFolder(const AssetPath& path) {
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
auto oldMappings = _fileMappings;
// enumerate the paths to delete and remove them all
for (auto& path : paths) {
path = path.trimmed();
// figure out if this path will delete a file or folder
if (pathIsFolder(path)) {
// 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)) {
qWarning() << "Cannot perform rename with invalid paths - both should have leading forward slashes:"
<< oldPath << "=>" << newPath;

View file

@ -52,13 +52,13 @@ private:
bool writeMappingsToFile();
/// 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`.
bool deleteMappings(const AssetPathList& paths);
bool deleteMappings(AssetPathList& paths);
/// 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();

View file

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

View file

@ -88,13 +88,15 @@ void AssetMappingsScriptingInterface::uploadFile(QString path, QString mapping,
return;
}
mapping = result.toString();
mapping = mapping.trimmed();
if (mapping[0] != '/') {
mapping = "/" + mapping;
}
// Check for override
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,
QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
if (button == QMessageBox::No) {

View file

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