summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--indra/newview/llviewerassetupload.cpp351
-rw-r--r--indra/newview/llviewerassetupload.h142
-rwxr-xr-xindra/newview/llviewermenufile.cpp524
-rwxr-xr-xindra/newview/llviewermenufile.h146
4 files changed, 493 insertions, 670 deletions
diff --git a/indra/newview/llviewerassetupload.cpp b/indra/newview/llviewerassetupload.cpp
index 717b14bb72..1730523d8e 100644
--- a/indra/newview/llviewerassetupload.cpp
+++ b/indra/newview/llviewerassetupload.cpp
@@ -28,7 +28,6 @@
#include "llviewerprecompiledheaders.h"
#include "linden_common.h"
-#include "llviewerassetupload.h"
#include "llviewertexturelist.h"
#include "llimage.h"
#include "lltrans.h"
@@ -43,6 +42,356 @@
#include "llstatusbar.h"
#include "llinventorypanel.h"
#include "llsdutil.h"
+#include "llviewerassetupload.h"
+#include "llappviewer.h"
+#include "llviewerstats.h"
+#include "llvfile.h"
+
+LLSD NewResourceUploadInfo::prepareUpload()
+{
+ if (mAssetId.isNull())
+ generateNewAssetId();
+
+ incrementUploadStats();
+ assignDefaults();
+
+ return LLSD().with("success", LLSD::Boolean(true));
+}
+
+std::string NewResourceUploadInfo::getAssetTypeString() const
+{
+ return LLAssetType::lookup(mAssetType);
+}
+
+std::string NewResourceUploadInfo::getInventoryTypeString() const
+{
+ return LLInventoryType::lookup(mInventoryType);
+}
+
+LLSD NewResourceUploadInfo::generatePostBody()
+{
+ LLSD body;
+
+ body["folder_id"] = mFolderId;
+ body["asset_type"] = getAssetTypeString();
+ body["inventory_type"] = getInventoryTypeString();
+ body["name"] = mName;
+ body["description"] = mDescription;
+ body["next_owner_mask"] = LLSD::Integer(mNextOwnerPerms);
+ body["group_mask"] = LLSD::Integer(mGroupPerms);
+ body["everyone_mask"] = LLSD::Integer(mEveryonePerms);
+
+ return body;
+
+}
+
+void NewResourceUploadInfo::logPreparedUpload()
+{
+ LL_INFOS() << "*** Uploading: " << std::endl <<
+ "Type: " << LLAssetType::lookup(mAssetType) << std::endl <<
+ "UUID: " << mAssetId.asString() << std::endl <<
+ "Name: " << mName << std::endl <<
+ "Desc: " << mDescription << std::endl <<
+ "Expected Upload Cost: " << mExpectedUploadCost << std::endl <<
+ "Folder: " << mFolderId << std::endl <<
+ "Asset Type: " << LLAssetType::lookup(mAssetType) << LL_ENDL;
+}
+
+LLUUID NewResourceUploadInfo::finishUpload(LLSD &result)
+{
+ if (getFolderId().isNull())
+ {
+ return LLUUID::null;
+ }
+
+ U32 permsEveryone = PERM_NONE;
+ U32 permsGroup = PERM_NONE;
+ U32 permsNextOwner = PERM_ALL;
+
+ if (result.has("new_next_owner_mask"))
+ {
+ // The server provided creation perms so use them.
+ // Do not assume we got the perms we asked for in
+ // since the server may not have granted them all.
+ permsEveryone = result["new_everyone_mask"].asInteger();
+ permsGroup = result["new_group_mask"].asInteger();
+ permsNextOwner = result["new_next_owner_mask"].asInteger();
+ }
+ else
+ {
+ // The server doesn't provide creation perms
+ // so use old assumption-based perms.
+ if (getAssetTypeString() != "snapshot")
+ {
+ permsNextOwner = PERM_MOVE | PERM_TRANSFER;
+ }
+ }
+
+ LLPermissions new_perms;
+ new_perms.init(
+ gAgent.getID(),
+ gAgent.getID(),
+ LLUUID::null,
+ LLUUID::null);
+
+ new_perms.initMasks(
+ PERM_ALL,
+ PERM_ALL,
+ permsEveryone,
+ permsGroup,
+ permsNextOwner);
+
+ U32 flagsInventoryItem = 0;
+ if (result.has("inventory_flags"))
+ {
+ flagsInventoryItem = static_cast<U32>(result["inventory_flags"].asInteger());
+ if (flagsInventoryItem != 0)
+ {
+ LL_INFOS() << "inventory_item_flags " << flagsInventoryItem << LL_ENDL;
+ }
+ }
+ S32 creationDate = time_corrected();
+
+ LLUUID serverInventoryItem = result["new_inventory_item"].asUUID();
+ LLUUID serverAssetId = result["new_asset"].asUUID();
+
+ LLPointer<LLViewerInventoryItem> item = new LLViewerInventoryItem(
+ serverInventoryItem,
+ getFolderId(),
+ new_perms,
+ serverAssetId,
+ getAssetType(),
+ getInventoryType(),
+ getName(),
+ getDescription(),
+ LLSaleInfo::DEFAULT,
+ flagsInventoryItem,
+ creationDate);
+
+ gInventory.updateItem(item);
+ gInventory.notifyObservers();
+
+ return serverInventoryItem;
+}
+
+
+LLAssetID NewResourceUploadInfo::generateNewAssetId()
+{
+ if (gDisconnected)
+ {
+ LLAssetID rv;
+
+ rv.setNull();
+ return rv;
+ }
+ mAssetId = mTransactionId.makeAssetID(gAgent.getSecureSessionID());
+
+ return mAssetId;
+}
+
+void NewResourceUploadInfo::incrementUploadStats() const
+{
+ if (LLAssetType::AT_SOUND == mAssetType)
+ {
+ add(LLStatViewer::UPLOAD_SOUND, 1);
+ }
+ else if (LLAssetType::AT_TEXTURE == mAssetType)
+ {
+ add(LLStatViewer::UPLOAD_TEXTURE, 1);
+ }
+ else if (LLAssetType::AT_ANIMATION == mAssetType)
+ {
+ add(LLStatViewer::ANIMATION_UPLOADS, 1);
+ }
+}
+
+void NewResourceUploadInfo::assignDefaults()
+{
+ if (LLInventoryType::IT_NONE == mInventoryType)
+ {
+ mInventoryType = LLInventoryType::defaultForAssetType(mAssetType);
+ }
+ LLStringUtil::stripNonprintable(mName);
+ LLStringUtil::stripNonprintable(mDescription);
+
+ if (mName.empty())
+ {
+ mName = "(No Name)";
+ }
+ if (mDescription.empty())
+ {
+ mDescription = "(No Description)";
+ }
+
+ mFolderId = gInventory.findCategoryUUIDForType(
+ (mDestinationFolderType == LLFolderType::FT_NONE) ?
+ (LLFolderType::EType)mAssetType : mDestinationFolderType);
+
+}
+
+std::string NewResourceUploadInfo::getDisplayName() const
+{
+ return (mName.empty()) ? mAssetId.asString() : mName;
+};
+
+//=========================================================================
+NewFileResourceUploadInfo::NewFileResourceUploadInfo(
+ std::string fileName,
+ std::string name,
+ std::string description,
+ S32 compressionInfo,
+ LLFolderType::EType destinationType,
+ LLInventoryType::EType inventoryType,
+ U32 nextOWnerPerms,
+ U32 groupPerms,
+ U32 everyonePerms,
+ S32 expectedCost) :
+ NewResourceUploadInfo(name, description, compressionInfo,
+ destinationType, inventoryType,
+ nextOWnerPerms, groupPerms, everyonePerms, expectedCost),
+ mFileName(fileName)
+{
+ LLTransactionID tid;
+ tid.generate();
+ setTransactionId(tid);
+}
+
+
+
+LLSD NewFileResourceUploadInfo::prepareUpload()
+{
+ generateNewAssetId();
+
+ LLSD result = exportTempFile();
+ if (result.has("error"))
+ return result;
+
+ return NewResourceUploadInfo::prepareUpload();
+}
+
+LLSD NewFileResourceUploadInfo::exportTempFile()
+{
+ std::string filename = gDirUtilp->getTempFilename();
+
+ std::string exten = gDirUtilp->getExtension(getFileName());
+ U32 codec = LLImageBase::getCodecFromExtension(exten);
+
+ LLAssetType::EType assetType = LLAssetType::AT_NONE;
+ std::string errorMessage;
+ std::string errorLabel;
+
+ bool error = false;
+
+ if (exten.empty())
+ {
+ std::string shortName = gDirUtilp->getBaseFileName(filename);
+
+ // No extension
+ errorMessage = llformat(
+ "No file extension for the file: '%s'\nPlease make sure the file has a correct file extension",
+ shortName.c_str());
+ errorLabel = "NoFileExtension";
+ error = true;
+ }
+ else if (codec != IMG_CODEC_INVALID)
+ {
+ // It's an image file, the upload procedure is the same for all
+ assetType = LLAssetType::AT_TEXTURE;
+ if (!LLViewerTextureList::createUploadFile(getFileName(), filename, codec))
+ {
+ errorMessage = llformat("Problem with file %s:\n\n%s\n",
+ getFileName().c_str(), LLImage::getLastError().c_str());
+ errorLabel = "ProblemWithFile";
+ error = true;
+ }
+ }
+ else if (exten == "wav")
+ {
+ assetType = LLAssetType::AT_SOUND; // tag it as audio
+ S32 encodeResult = 0;
+
+ LL_INFOS() << "Attempting to encode wav as an ogg file" << LL_ENDL;
+
+ encodeResult = encode_vorbis_file(getFileName(), filename);
+
+ if (LLVORBISENC_NOERR != encodeResult)
+ {
+ switch (encodeResult)
+ {
+ case LLVORBISENC_DEST_OPEN_ERR:
+ errorMessage = llformat("Couldn't open temporary compressed sound file for writing: %s\n", filename.c_str());
+ errorLabel = "CannotOpenTemporarySoundFile";
+ break;
+
+ default:
+ errorMessage = llformat("Unknown vorbis encode failure on: %s\n", getFileName().c_str());
+ errorLabel = "UnknownVorbisEncodeFailure";
+ break;
+ }
+ error = true;
+ }
+ }
+ else if (exten == "bvh")
+ {
+ errorMessage = llformat("We do not currently support bulk upload of animation files\n");
+ errorLabel = "DoNotSupportBulkAnimationUpload";
+ error = true;
+ }
+ else if (exten == "anim")
+ {
+ assetType = LLAssetType::AT_ANIMATION;
+ filename = getFileName();
+ }
+ else
+ {
+ // Unknown extension
+ errorMessage = llformat(LLTrans::getString("UnknownFileExtension").c_str(), exten.c_str());
+ errorLabel = "ErrorMessage";
+ error = TRUE;;
+ }
+
+ if (error)
+ {
+ LLSD errorResult(LLSD::emptyMap());
+
+ errorResult["error"] = LLSD::Binary(true);
+ errorResult["message"] = errorMessage;
+ errorResult["label"] = errorLabel;
+ return errorResult;
+ }
+
+ setAssetType(assetType);
+
+ // copy this file into the vfs for upload
+ S32 file_size;
+ LLAPRFile infile;
+ infile.open(filename, LL_APR_RB, NULL, &file_size);
+ if (infile.getFileHandle())
+ {
+ LLVFile file(gVFS, getAssetId(), assetType, LLVFile::WRITE);
+
+ file.setMaxSize(file_size);
+
+ const S32 buf_size = 65536;
+ U8 copy_buf[buf_size];
+ while ((file_size = infile.read(copy_buf, buf_size)))
+ {
+ file.write(copy_buf, file_size);
+ }
+ }
+ else
+ {
+ errorMessage = llformat("Unable to access output file: %s", filename.c_str());
+ LLSD errorResult(LLSD::emptyMap());
+
+ errorResult["error"] = LLSD::Binary(true);
+ errorResult["message"] = errorMessage;
+ return errorResult;
+ }
+
+ return LLSD();
+
+}
//=========================================================================
/*static*/
diff --git a/indra/newview/llviewerassetupload.h b/indra/newview/llviewerassetupload.h
index 38167fc0c7..82cb8d1b85 100644
--- a/indra/newview/llviewerassetupload.h
+++ b/indra/newview/llviewerassetupload.h
@@ -35,7 +35,147 @@
#include "llcoros.h"
#include "llcorehttputil.h"
-#include "llviewermenufile.h"
+class NewResourceUploadInfo
+{
+public:
+ typedef boost::shared_ptr<NewResourceUploadInfo> ptr_t;
+
+ NewResourceUploadInfo(
+ LLTransactionID transactId,
+ LLAssetType::EType assetType,
+ std::string name,
+ std::string description,
+ S32 compressionInfo,
+ LLFolderType::EType destinationType,
+ LLInventoryType::EType inventoryType,
+ U32 nextOWnerPerms,
+ U32 groupPerms,
+ U32 everyonePerms,
+ S32 expectedCost) :
+ mTransactionId(transactId),
+ mAssetType(assetType),
+ mName(name),
+ mDescription(description),
+ mCompressionInfo(compressionInfo),
+ mDestinationFolderType(destinationType),
+ mInventoryType(inventoryType),
+ mNextOwnerPerms(nextOWnerPerms),
+ mGroupPerms(groupPerms),
+ mEveryonePerms(everyonePerms),
+ mExpectedUploadCost(expectedCost),
+ mFolderId(LLUUID::null),
+ mItemId(LLUUID::null),
+ mAssetId(LLAssetID::null)
+ { }
+
+ virtual ~NewResourceUploadInfo()
+ { }
+
+ virtual LLSD prepareUpload();
+ virtual LLSD generatePostBody();
+ virtual void logPreparedUpload();
+ virtual LLUUID finishUpload(LLSD &result);
+
+ LLTransactionID getTransactionId() const { return mTransactionId; }
+ LLAssetType::EType getAssetType() const { return mAssetType; }
+ std::string getAssetTypeString() const;
+ std::string getName() const { return mName; };
+ std::string getDescription() const { return mDescription; };
+ S32 getCompressionInfo() const { return mCompressionInfo; };
+ LLFolderType::EType getDestinationFolderType() const { return mDestinationFolderType; };
+ LLInventoryType::EType getInventoryType() const { return mInventoryType; };
+ std::string getInventoryTypeString() const;
+ U32 getNextOwnerPerms() const { return mNextOwnerPerms; };
+ U32 getGroupPerms() const { return mGroupPerms; };
+ U32 getEveryonePerms() const { return mEveryonePerms; };
+ S32 getExpectedUploadCost() const { return mExpectedUploadCost; };
+
+ virtual std::string getDisplayName() const;
+
+ LLUUID getFolderId() const { return mFolderId; }
+ LLUUID getItemId() const { return mItemId; }
+ LLAssetID getAssetId() const { return mAssetId; }
+
+protected:
+ NewResourceUploadInfo(
+ std::string name,
+ std::string description,
+ S32 compressionInfo,
+ LLFolderType::EType destinationType,
+ LLInventoryType::EType inventoryType,
+ U32 nextOWnerPerms,
+ U32 groupPerms,
+ U32 everyonePerms,
+ S32 expectedCost) :
+ mName(name),
+ mDescription(description),
+ mCompressionInfo(compressionInfo),
+ mDestinationFolderType(destinationType),
+ mInventoryType(inventoryType),
+ mNextOwnerPerms(nextOWnerPerms),
+ mGroupPerms(groupPerms),
+ mEveryonePerms(everyonePerms),
+ mExpectedUploadCost(expectedCost),
+ mTransactionId(),
+ mAssetType(LLAssetType::AT_NONE),
+ mFolderId(LLUUID::null),
+ mItemId(LLUUID::null),
+ mAssetId(LLAssetID::null)
+ { }
+
+ void setTransactionId(LLTransactionID tid) { mTransactionId = tid; }
+ void setAssetType(LLAssetType::EType assetType) { mAssetType = assetType; }
+
+ LLAssetID generateNewAssetId();
+ void incrementUploadStats() const;
+ virtual void assignDefaults();
+
+private:
+ LLTransactionID mTransactionId;
+ LLAssetType::EType mAssetType;
+ std::string mName;
+ std::string mDescription;
+ S32 mCompressionInfo;
+ LLFolderType::EType mDestinationFolderType;
+ LLInventoryType::EType mInventoryType;
+ U32 mNextOwnerPerms;
+ U32 mGroupPerms;
+ U32 mEveryonePerms;
+ S32 mExpectedUploadCost;
+
+ LLUUID mFolderId;
+ LLUUID mItemId;
+ LLAssetID mAssetId;
+};
+
+class NewFileResourceUploadInfo : public NewResourceUploadInfo
+{
+public:
+ NewFileResourceUploadInfo(
+ std::string fileName,
+ std::string name,
+ std::string description,
+ S32 compressionInfo,
+ LLFolderType::EType destinationType,
+ LLInventoryType::EType inventoryType,
+ U32 nextOWnerPerms,
+ U32 groupPerms,
+ U32 everyonePerms,
+ S32 expectedCost);
+
+ virtual LLSD prepareUpload();
+
+ std::string getFileName() const { return mFileName; };
+
+protected:
+
+ virtual LLSD exportTempFile();
+
+private:
+ std::string mFileName;
+
+};
+
class LLViewerAssetUpload
{
diff --git a/indra/newview/llviewermenufile.cpp b/indra/newview/llviewermenufile.cpp
index 20fbfaf71a..9c4045fa1e 100755
--- a/indra/newview/llviewermenufile.cpp
+++ b/indra/newview/llviewermenufile.cpp
@@ -451,39 +451,6 @@ class LLFileUploadBulk : public view_listener_t
filename = picker.getNextFile();
}
-#if 0
- const std::string& filename = picker.getFirstFile();
- std::string name = gDirUtilp->getBaseFileName(filename, true);
-
- std::string asset_name = name;
- LLStringUtil::replaceNonstandardASCII( asset_name, '?' );
- LLStringUtil::replaceChar(asset_name, '|', '?');
- LLStringUtil::stripNonprintable(asset_name);
- LLStringUtil::trim(asset_name);
-
- std::string display_name = LLStringUtil::null;
- LLAssetStorage::LLStoreAssetCallback callback = NULL;
- S32 expected_upload_cost = LLGlobalEconomy::Singleton::getInstance()->getPriceUpload();
- void *userdata = NULL;
-
- upload_new_resource(
- filename,
- asset_name,
- asset_name,
- 0,
- LLFolderType::FT_NONE,
- LLInventoryType::IT_NONE,
- LLFloaterPerms::getNextOwnerPerms("Uploads"),
- LLFloaterPerms::getGroupPerms("Uploads"),
- LLFloaterPerms::getEveryonePerms("Uploads"),
- display_name,
- callback,
- expected_upload_cost,
- userdata);
-
- // *NOTE: Ew, we don't iterate over the file list here,
- // we handle the next files in upload_done_callback()
-#endif
}
else
{
@@ -678,151 +645,6 @@ LLUUID upload_new_resource(
upload_new_resource(uploadInfo, callback, userdata);
return LLUUID::null;
-
-#if 0
- // Generate the temporary UUID.
- std::string filename = gDirUtilp->getTempFilename();
- LLTransactionID tid;
- LLAssetID uuid;
-
- LLSD args;
-
- std::string exten = gDirUtilp->getExtension(src_filename);
- U32 codec = LLImageBase::getCodecFromExtension(exten);
- LLAssetType::EType asset_type = LLAssetType::AT_NONE;
- std::string error_message;
-
- BOOL error = FALSE;
-
- if (exten.empty())
- {
- std::string short_name = gDirUtilp->getBaseFileName(filename);
-
- // No extension
- error_message = llformat(
- "No file extension for the file: '%s'\nPlease make sure the file has a correct file extension",
- short_name.c_str());
- args["FILE"] = short_name;
- upload_error(error_message, "NoFileExtension", filename, args);
- return LLUUID();
- }
- else if (codec != IMG_CODEC_INVALID)
- {
- // It's an image file, the upload procedure is the same for all
- asset_type = LLAssetType::AT_TEXTURE;
- if (!LLViewerTextureList::createUploadFile(src_filename, filename, codec ))
- {
- error_message = llformat( "Problem with file %s:\n\n%s\n",
- src_filename.c_str(), LLImage::getLastError().c_str());
- args["FILE"] = src_filename;
- args["ERROR"] = LLImage::getLastError();
- upload_error(error_message, "ProblemWithFile", filename, args);
- return LLUUID();
- }
- }
- else if(exten == "wav")
- {
- asset_type = LLAssetType::AT_SOUND; // tag it as audio
- S32 encode_result = 0;
-
- LL_INFOS() << "Attempting to encode wav as an ogg file" << LL_ENDL;
-
- encode_result = encode_vorbis_file(src_filename, filename);
-
- if (LLVORBISENC_NOERR != encode_result)
- {
- switch(encode_result)
- {
- case LLVORBISENC_DEST_OPEN_ERR:
- error_message = llformat( "Couldn't open temporary compressed sound file for writing: %s\n", filename.c_str());
- args["FILE"] = filename;
- upload_error(error_message, "CannotOpenTemporarySoundFile", filename, args);
- break;
-
- default:
- error_message = llformat("Unknown vorbis encode failure on: %s\n", src_filename.c_str());
- args["FILE"] = src_filename;
- upload_error(error_message, "UnknownVorbisEncodeFailure", filename, args);
- break;
- }
- return LLUUID();
- }
- }
- else if (exten == "bvh")
- {
- error_message = llformat("We do not currently support bulk upload of animation files\n");
- upload_error(error_message, "DoNotSupportBulkAnimationUpload", filename, args);
- return LLUUID();
- }
- else if (exten == "anim")
- {
- asset_type = LLAssetType::AT_ANIMATION;
- filename = src_filename;
- }
- else
- {
- // Unknown extension
- error_message = llformat(LLTrans::getString("UnknownFileExtension").c_str(), exten.c_str());
- error = TRUE;;
- }
-
- // gen a new transaction ID for this asset
- tid.generate();
-
- if (!error)
- {
- uuid = tid.makeAssetID(gAgent.getSecureSessionID());
- // copy this file into the vfs for upload
- S32 file_size;
- LLAPRFile infile ;
- infile.open(filename, LL_APR_RB, NULL, &file_size);
- if (infile.getFileHandle())
- {
- LLVFile file(gVFS, uuid, asset_type, LLVFile::WRITE);
-
- file.setMaxSize(file_size);
-
- const S32 buf_size = 65536;
- U8 copy_buf[buf_size];
- while ((file_size = infile.read(copy_buf, buf_size)))
- {
- file.write(copy_buf, file_size);
- }
- }
- else
- {
- error_message = llformat( "Unable to access output file: %s", filename.c_str());
- error = TRUE;
- }
- }
-
- if (!error)
- {
- NewResourceUploadInfo::ptr_t uploadInfo(new NewResourceUploadInfo(
- tid, asset_type,
- name, desc, compression_info,
- destination_folder_type, inv_type,
- next_owner_perms, group_perms, everyone_perms,
- expected_upload_cost));
-
- upload_new_resource(uploadInfo,
- callback, userdata);
- }
- else
- {
- LL_WARNS() << error_message << LL_ENDL;
- LLSD args;
- args["ERROR_MESSAGE"] = error_message;
- LLNotificationsUtil::add("ErrorMessage", args);
- if(LLFile::remove(filename) == -1)
- {
- LL_DEBUGS() << "unable to remove temp file" << LL_ENDL;
- }
- LLFilePicker::instance().reset();
- }
-
- return uuid;
-#endif
}
void upload_done_callback(
@@ -1047,349 +869,3 @@ void init_menu_file()
// "File.SaveTexture" moved to llpanelmaininventory so that it can be properly handled.
}
-
-LLSD NewResourceUploadInfo::prepareUpload()
-{
- if (mAssetId.isNull())
- generateNewAssetId();
-
- incrementUploadStats();
- assignDefaults();
-
- return LLSD().with("success", LLSD::Boolean(true));
-}
-
-std::string NewResourceUploadInfo::getAssetTypeString() const
-{
- return LLAssetType::lookup(mAssetType);
-}
-
-std::string NewResourceUploadInfo::getInventoryTypeString() const
-{
- return LLInventoryType::lookup(mInventoryType);
-}
-
-LLSD NewResourceUploadInfo::generatePostBody()
-{
- LLSD body;
-
- body["folder_id"] = mFolderId;
- body["asset_type"] = getAssetTypeString();
- body["inventory_type"] = getInventoryTypeString();
- body["name"] = mName;
- body["description"] = mDescription;
- body["next_owner_mask"] = LLSD::Integer(mNextOwnerPerms);
- body["group_mask"] = LLSD::Integer(mGroupPerms);
- body["everyone_mask"] = LLSD::Integer(mEveryonePerms);
-
- return body;
-
-}
-
-void NewResourceUploadInfo::logPreparedUpload()
-{
- LL_INFOS() << "*** Uploading: " << std::endl <<
- "Type: " << LLAssetType::lookup(mAssetType) << std::endl <<
- "UUID: " << mAssetId.asString() << std::endl <<
- "Name: " << mName << std::endl <<
- "Desc: " << mDescription << std::endl <<
- "Expected Upload Cost: " << mExpectedUploadCost << std::endl <<
- "Folder: " << mFolderId << std::endl <<
- "Asset Type: " << LLAssetType::lookup(mAssetType) << LL_ENDL;
-}
-
-LLUUID NewResourceUploadInfo::finishUpload(LLSD &result)
-{
- if (getFolderId().isNull())
- {
- return LLUUID::null;
- }
-
- U32 permsEveryone = PERM_NONE;
- U32 permsGroup = PERM_NONE;
- U32 permsNextOwner = PERM_ALL;
-
- if (result.has("new_next_owner_mask"))
- {
- // The server provided creation perms so use them.
- // Do not assume we got the perms we asked for in
- // since the server may not have granted them all.
- permsEveryone = result["new_everyone_mask"].asInteger();
- permsGroup = result["new_group_mask"].asInteger();
- permsNextOwner = result["new_next_owner_mask"].asInteger();
- }
- else
- {
- // The server doesn't provide creation perms
- // so use old assumption-based perms.
- if (getAssetTypeString() != "snapshot")
- {
- permsNextOwner = PERM_MOVE | PERM_TRANSFER;
- }
- }
-
- LLPermissions new_perms;
- new_perms.init(
- gAgent.getID(),
- gAgent.getID(),
- LLUUID::null,
- LLUUID::null);
-
- new_perms.initMasks(
- PERM_ALL,
- PERM_ALL,
- permsEveryone,
- permsGroup,
- permsNextOwner);
-
- U32 flagsInventoryItem = 0;
- if (result.has("inventory_flags"))
- {
- flagsInventoryItem = static_cast<U32>(result["inventory_flags"].asInteger());
- if (flagsInventoryItem != 0)
- {
- LL_INFOS() << "inventory_item_flags " << flagsInventoryItem << LL_ENDL;
- }
- }
- S32 creationDate = time_corrected();
-
- LLUUID serverInventoryItem = result["new_inventory_item"].asUUID();
- LLUUID serverAssetId = result["new_asset"].asUUID();
-
- LLPointer<LLViewerInventoryItem> item = new LLViewerInventoryItem(
- serverInventoryItem,
- getFolderId(),
- new_perms,
- serverAssetId,
- getAssetType(),
- getInventoryType(),
- getName(),
- getDescription(),
- LLSaleInfo::DEFAULT,
- flagsInventoryItem,
- creationDate);
-
- gInventory.updateItem(item);
- gInventory.notifyObservers();
-
- return serverInventoryItem;
-}
-
-
-LLAssetID NewResourceUploadInfo::generateNewAssetId()
-{
- if (gDisconnected)
- {
- LLAssetID rv;
-
- rv.setNull();
- return rv;
- }
- mAssetId = mTransactionId.makeAssetID(gAgent.getSecureSessionID());
-
- return mAssetId;
-}
-
-void NewResourceUploadInfo::incrementUploadStats() const
-{
- if (LLAssetType::AT_SOUND == mAssetType)
- {
- add(LLStatViewer::UPLOAD_SOUND, 1);
- }
- else if (LLAssetType::AT_TEXTURE == mAssetType)
- {
- add(LLStatViewer::UPLOAD_TEXTURE, 1);
- }
- else if (LLAssetType::AT_ANIMATION == mAssetType)
- {
- add(LLStatViewer::ANIMATION_UPLOADS, 1);
- }
-}
-
-void NewResourceUploadInfo::assignDefaults()
-{
- if (LLInventoryType::IT_NONE == mInventoryType)
- {
- mInventoryType = LLInventoryType::defaultForAssetType(mAssetType);
- }
- LLStringUtil::stripNonprintable(mName);
- LLStringUtil::stripNonprintable(mDescription);
-
- if (mName.empty())
- {
- mName = "(No Name)";
- }
- if (mDescription.empty())
- {
- mDescription = "(No Description)";
- }
-
- mFolderId = gInventory.findCategoryUUIDForType(
- (mDestinationFolderType == LLFolderType::FT_NONE) ?
- (LLFolderType::EType)mAssetType : mDestinationFolderType);
-
-}
-
-std::string NewResourceUploadInfo::getDisplayName() const
-{
- return (mName.empty()) ? mAssetId.asString() : mName;
-};
-
-
-NewFileResourceUploadInfo::NewFileResourceUploadInfo(
- std::string fileName,
- std::string name,
- std::string description,
- S32 compressionInfo,
- LLFolderType::EType destinationType,
- LLInventoryType::EType inventoryType,
- U32 nextOWnerPerms,
- U32 groupPerms,
- U32 everyonePerms,
- S32 expectedCost):
- NewResourceUploadInfo(name, description, compressionInfo,
- destinationType, inventoryType,
- nextOWnerPerms, groupPerms, everyonePerms, expectedCost),
- mFileName(fileName)
-{
- LLTransactionID tid;
- tid.generate();
- setTransactionId(tid);
-}
-
-
-
-LLSD NewFileResourceUploadInfo::prepareUpload()
-{
- generateNewAssetId();
-
- LLSD result = exportTempFile();
- if (result.has("error"))
- return result;
-
- return NewResourceUploadInfo::prepareUpload();
-}
-
-LLSD NewFileResourceUploadInfo::exportTempFile()
-{
- std::string filename = gDirUtilp->getTempFilename();
-
- std::string exten = gDirUtilp->getExtension(getFileName());
- U32 codec = LLImageBase::getCodecFromExtension(exten);
-
- LLAssetType::EType assetType = LLAssetType::AT_NONE;
- std::string errorMessage;
- std::string errorLabel;
-
- bool error = false;
-
- if (exten.empty())
- {
- std::string shortName = gDirUtilp->getBaseFileName(filename);
-
- // No extension
- errorMessage = llformat(
- "No file extension for the file: '%s'\nPlease make sure the file has a correct file extension",
- shortName.c_str());
- errorLabel = "NoFileExtension";
- error = true;
- }
- else if (codec != IMG_CODEC_INVALID)
- {
- // It's an image file, the upload procedure is the same for all
- assetType = LLAssetType::AT_TEXTURE;
- if (!LLViewerTextureList::createUploadFile(getFileName(), filename, codec))
- {
- errorMessage = llformat("Problem with file %s:\n\n%s\n",
- getFileName().c_str(), LLImage::getLastError().c_str());
- errorLabel = "ProblemWithFile";
- error = true;
- }
- }
- else if (exten == "wav")
- {
- assetType = LLAssetType::AT_SOUND; // tag it as audio
- S32 encodeResult = 0;
-
- LL_INFOS() << "Attempting to encode wav as an ogg file" << LL_ENDL;
-
- encodeResult = encode_vorbis_file(getFileName(), filename);
-
- if (LLVORBISENC_NOERR != encodeResult)
- {
- switch (encodeResult)
- {
- case LLVORBISENC_DEST_OPEN_ERR:
- errorMessage = llformat("Couldn't open temporary compressed sound file for writing: %s\n", filename.c_str());
- errorLabel = "CannotOpenTemporarySoundFile";
- break;
-
- default:
- errorMessage = llformat("Unknown vorbis encode failure on: %s\n", getFileName().c_str());
- errorLabel = "UnknownVorbisEncodeFailure";
- break;
- }
- error = true;
- }
- }
- else if (exten == "bvh")
- {
- errorMessage = llformat("We do not currently support bulk upload of animation files\n");
- errorLabel = "DoNotSupportBulkAnimationUpload";
- error = true;
- }
- else if (exten == "anim")
- {
- assetType = LLAssetType::AT_ANIMATION;
- filename = getFileName();
- }
- else
- {
- // Unknown extension
- errorMessage = llformat(LLTrans::getString("UnknownFileExtension").c_str(), exten.c_str());
- errorLabel = "ErrorMessage";
- error = TRUE;;
- }
-
- if (error)
- {
- LLSD errorResult(LLSD::emptyMap());
-
- errorResult["error"] = LLSD::Binary(true);
- errorResult["message"] = errorMessage;
- errorResult["label"] = errorLabel;
- return errorResult;
- }
-
- setAssetType(assetType);
-
- // copy this file into the vfs for upload
- S32 file_size;
- LLAPRFile infile;
- infile.open(filename, LL_APR_RB, NULL, &file_size);
- if (infile.getFileHandle())
- {
- LLVFile file(gVFS, getAssetId(), assetType, LLVFile::WRITE);
-
- file.setMaxSize(file_size);
-
- const S32 buf_size = 65536;
- U8 copy_buf[buf_size];
- while ((file_size = infile.read(copy_buf, buf_size)))
- {
- file.write(copy_buf, file_size);
- }
- }
- else
- {
- errorMessage = llformat("Unable to access output file: %s", filename.c_str());
- LLSD errorResult(LLSD::emptyMap());
-
- errorResult["error"] = LLSD::Binary(true);
- errorResult["message"] = errorMessage;
- return errorResult;
- }
-
- return LLSD();
-
-}
diff --git a/indra/newview/llviewermenufile.h b/indra/newview/llviewermenufile.h
index 7ee5043777..616eaed373 100755
--- a/indra/newview/llviewermenufile.h
+++ b/indra/newview/llviewermenufile.h
@@ -34,155 +34,13 @@
#include "llthread.h"
#include <queue>
+#include "llviewerassetupload.h"
+
class LLTransactionID;
void init_menu_file();
-class NewResourceUploadInfo
-{
-public:
- typedef boost::shared_ptr<NewResourceUploadInfo> ptr_t;
-
- NewResourceUploadInfo(
- LLTransactionID transactId,
- LLAssetType::EType assetType,
- std::string name,
- std::string description,
- S32 compressionInfo,
- LLFolderType::EType destinationType,
- LLInventoryType::EType inventoryType,
- U32 nextOWnerPerms,
- U32 groupPerms,
- U32 everyonePerms,
- S32 expectedCost) :
- mTransactionId(transactId),
- mAssetType(assetType),
- mName(name),
- mDescription(description),
- mCompressionInfo(compressionInfo),
- mDestinationFolderType(destinationType),
- mInventoryType(inventoryType),
- mNextOwnerPerms(nextOWnerPerms),
- mGroupPerms(groupPerms),
- mEveryonePerms(everyonePerms),
- mExpectedUploadCost(expectedCost),
- mFolderId(LLUUID::null),
- mItemId(LLUUID::null),
- mAssetId(LLAssetID::null)
- { }
-
- virtual ~NewResourceUploadInfo()
- { }
-
- virtual LLSD prepareUpload();
- virtual LLSD generatePostBody();
- virtual void logPreparedUpload();
- virtual LLUUID finishUpload(LLSD &result);
-
- //void setAssetType(LLAssetType::EType assetType) { mAssetType = assetType; }
- //void setTransactionId(LLTransactionID transactionId) { mTransactionId = transactionId; }
-
- LLTransactionID getTransactionId() const { return mTransactionId; }
- LLAssetType::EType getAssetType() const { return mAssetType; }
- std::string getAssetTypeString() const;
- std::string getName() const { return mName; };
- std::string getDescription() const { return mDescription; };
- S32 getCompressionInfo() const { return mCompressionInfo; };
- LLFolderType::EType getDestinationFolderType() const { return mDestinationFolderType; };
- LLInventoryType::EType getInventoryType() const { return mInventoryType; };
- std::string getInventoryTypeString() const;
- U32 getNextOwnerPerms() const { return mNextOwnerPerms; };
- U32 getGroupPerms() const { return mGroupPerms; };
- U32 getEveryonePerms() const { return mEveryonePerms; };
- S32 getExpectedUploadCost() const { return mExpectedUploadCost; };
-
- virtual std::string getDisplayName() const;
-
- LLUUID getFolderId() const { return mFolderId; }
- LLUUID getItemId() const { return mItemId; }
- LLAssetID getAssetId() const { return mAssetId; }
-
-protected:
- NewResourceUploadInfo(
- std::string name,
- std::string description,
- S32 compressionInfo,
- LLFolderType::EType destinationType,
- LLInventoryType::EType inventoryType,
- U32 nextOWnerPerms,
- U32 groupPerms,
- U32 everyonePerms,
- S32 expectedCost) :
- mName(name),
- mDescription(description),
- mCompressionInfo(compressionInfo),
- mDestinationFolderType(destinationType),
- mInventoryType(inventoryType),
- mNextOwnerPerms(nextOWnerPerms),
- mGroupPerms(groupPerms),
- mEveryonePerms(everyonePerms),
- mExpectedUploadCost(expectedCost),
- mTransactionId(),
- mAssetType(LLAssetType::AT_NONE),
- mFolderId(LLUUID::null),
- mItemId(LLUUID::null),
- mAssetId(LLAssetID::null)
- { }
-
- void setTransactionId(LLTransactionID tid) { mTransactionId = tid; }
- void setAssetType(LLAssetType::EType assetType) { mAssetType = assetType; }
-
- LLAssetID generateNewAssetId();
- void incrementUploadStats() const;
- virtual void assignDefaults();
-
-private:
- LLTransactionID mTransactionId;
- LLAssetType::EType mAssetType;
- std::string mName;
- std::string mDescription;
- S32 mCompressionInfo;
- LLFolderType::EType mDestinationFolderType;
- LLInventoryType::EType mInventoryType;
- U32 mNextOwnerPerms;
- U32 mGroupPerms;
- U32 mEveryonePerms;
- S32 mExpectedUploadCost;
-
- LLUUID mFolderId;
- LLUUID mItemId;
- LLAssetID mAssetId;
-};
-
-class NewFileResourceUploadInfo : public NewResourceUploadInfo
-{
-public:
- NewFileResourceUploadInfo(
- std::string fileName,
- std::string name,
- std::string description,
- S32 compressionInfo,
- LLFolderType::EType destinationType,
- LLInventoryType::EType inventoryType,
- U32 nextOWnerPerms,
- U32 groupPerms,
- U32 everyonePerms,
- S32 expectedCost);
-
- virtual LLSD prepareUpload();
-
- std::string getFileName() const { return mFileName; };
-
-protected:
-
- virtual LLSD exportTempFile();
-
-private:
- std::string mFileName;
-
-};
-
LLUUID upload_new_resource(
const std::string& src_filename,