void LLInventoryPanel::createNewItem(const std::string& name, const LLUUID& parent_id, LLAssetType::EType asset_type, LLInventoryType::EType inv_type, U32 next_owner_perm) { std::string desc; LLViewerAssetType::generateDescriptionFor(asset_type, desc); next_owner_perm = (next_owner_perm) ? next_owner_perm : PERM_MOVE | PERM_TRANSFER; if (inv_type == LLInventoryType::IT_GESTURE) { LLPointer<LLInventoryCallback> cb = new LLBoostFuncInventoryCallback(create_gesture_cb); create_inventory_item(gAgent.getID(), gAgent.getSessionID(), parent_id, LLTransactionID::tnull, name, desc, asset_type, inv_type, NOT_WEARABLE, next_owner_perm, cb); } else { LLPointer<LLInventoryCallback> cb = NULL; create_inventory_item(gAgent.getID(), gAgent.getSessionID(), parent_id, LLTransactionID::tnull, name, desc, asset_type, inv_type, NOT_WEARABLE, next_owner_perm, cb); } }
void LLInventoryPanel::createNewItem(const std::string& name, const LLUUID& parent_id, LLAssetType::EType asset_type, LLInventoryType::EType inv_type, U32 next_owner_perm) { std::string desc; LLAssetType::generateDescriptionFor(asset_type, desc); next_owner_perm = (next_owner_perm) ? next_owner_perm : PERM_MOVE | PERM_TRANSFER; LLPointer<LLInventoryCallback> cb = NULL; if (inv_type == LLInventoryType::IT_GESTURE) { cb = new CreateGestureCallback(); // This better not screw up LLPointer -- MC } create_inventory_item(gAgent.getID(), gAgent.getSessionID(), parent_id, LLTransactionID::tnull, name, desc, asset_type, inv_type, NOT_WEARABLE, next_owner_perm, cb); /*else { create_inventory_item(gAgent.getID(), gAgent.getSessionID(), parent_id, LLTransactionID::tnull, name, desc, asset_type, inv_type, NOT_WEARABLE, next_owner_perm, cb); }*/ }
// static void LLFloaterLandmark::onBtnNew(void* userdata) { LLViewerRegion* agent_region = gAgent.getRegion(); if(!agent_region) { llwarns << "No agent region" << llendl; return; } LLParcel* agent_parcel = LLViewerParcelMgr::getInstance()->getAgentParcel(); if (!agent_parcel) { llwarns << "No agent parcel" << llendl; return; } if (!agent_parcel->getAllowLandmark() && !LLViewerParcelMgr::isParcelOwnedByAgent(agent_parcel, GP_LAND_ALLOW_LANDMARK)) { LLNotificationsUtil::add("CannotCreateLandmarkNotOwner"); return; } std::string landmark_name, landmark_desc; LLAgentUI::buildLocationString(landmark_name, LLAgentUI::LOCATION_FORMAT_LANDMARK); LLAgentUI::buildLocationString(landmark_desc, LLAgentUI::LOCATION_FORMAT_FULL); const LLUUID folder_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_LANDMARK); create_inventory_item(gAgent.getID(), gAgent.getSessionID(), folder_id, LLTransactionID::tnull, landmark_name, landmark_desc, // name, desc LLAssetType::AT_LANDMARK, LLInventoryType::IT_LANDMARK, NOT_WEARABLE, PERM_ALL, NULL); }
void LLFloaterGesture::onClickNew() { LLPointer<LLInventoryCallback> cb = new LLBoostFuncInventoryCallback(gesture_show_cb); create_inventory_item(gAgent.getID(), gAgent.getSessionID(), LLUUID::null, LLTransactionID::tnull, "New Gesture", "", LLAssetType::AT_GESTURE, LLInventoryType::IT_GESTURE, NOT_WEARABLE, PERM_MOVE | PERM_TRANSFER, cb); }
void LLLandmarkActions::createLandmarkHere( const std::string& name, const std::string& desc, const LLUUID& folder_id) { if(!gAgent.getRegion()) { llwarns << "No agent region" << llendl; return; } LLParcel* agent_parcel = LLViewerParcelMgr::getInstance()->getAgentParcel(); if (!agent_parcel) { llwarns << "No agent parcel" << llendl; return; } if (!canCreateLandmarkHere()) { LLNotificationsUtil::add("CannotCreateLandmarkNotOwner"); return; } create_inventory_item(gAgent.getID(), gAgent.getSessionID(), folder_id, LLTransactionID::tnull, name, desc, LLAssetType::AT_LANDMARK, LLInventoryType::IT_LANDMARK, NOT_WEARABLE, PERM_ALL, NULL); }
void LLFloaterWater::onSavePreset(LLUICtrl* ctrl, void* userData) { // get the name LLComboBox* comboBox = sWaterMenu->getChild<LLComboBox>("WaterPresetsCombo"); // don't save the empty name if(comboBox->getSelectedItemLabel() == "") { return; } if (ctrl->getValue().asString() == "save_inventory_item") { // Check if this is already a notecard. if(LLWaterParamManager::instance()->mCurParams.mInventoryID.notNull()) { LLNotifications::instance().add("KittyWLSaveNotecardAlert", LLSD(), LLSD(), saveNotecardCallback); } else { // Make sure we have a ".ww" extension. std::string name = comboBox->getSelectedItemLabel(); if(name.length() > 2 && name.compare(name.length() - 3, 3, ".ww") != 0) { name += ".ww"; } LLPointer<KVFloaterWaterNotecardCreatedCallback> cb = new KVFloaterWaterNotecardCreatedCallback(); // Create a notecard and then save it. create_inventory_item(gAgent.getID(), gAgent.getSessionID(), LLUUID::null, LLTransactionID::tnull, name, "Water settings (Imprudence compatible)", LLAssetType::AT_NOTECARD, LLInventoryType::IT_NOTECARD, NOT_WEARABLE, PERM_ITEM_UNRESTRICTED, cb); } } else { LLWaterParamManager::instance()->mCurParams.mName = comboBox->getSelectedItemLabel(); // check to see if it's a default and shouldn't be overwritten std::set<std::string>::iterator sIt = sDefaultPresets.find( comboBox->getSelectedItemLabel()); if(sIt != sDefaultPresets.end() && !gSavedSettings.getBOOL("WaterEditPresets")) { LLNotifications::instance().add("WLNoEditDefault"); return; } LLNotifications::instance().add("WLSavePresetAlert", LLSD(), LLSD(), saveAlertCallback); } }
// static void LLFloaterGesture::onClickNew(void* data) { std::string title("Gesture: "); title.append("New Gesture"); LLPointer<LLInventoryCallback> cb = new GestureShowCallback(title); create_inventory_item(gAgent.getID(), gAgent.getSessionID(), LLUUID::null, LLTransactionID::tnull, "New Gesture", "", LLAssetType::AT_GESTURE, LLInventoryType::IT_GESTURE, NOT_WEARABLE, PERM_MOVE | PERM_TRANSFER, cb); }
/*virtual*/ void uploadComplete(const LLSD& content) { LLPointer<LLInventoryCallback> cb = new JCImportTransferCallback(data); LLPermissions perm; LLUUID parent_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH); create_inventory_item(gAgent.getID(), gAgent.getSessionID(), gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH), data->tid, data->name, data->description, data->type, LLInventoryType::defaultForAssetType(data->type), data->wear_type, LLFloaterPerms::getNextOwnerPerms(), cb); }
void LLFloaterGesture::onClickNew() { LLPointer<LLInventoryCallback> cb = new GestureShowCallback(); create_inventory_item(gAgent.getID(), gAgent.getSessionID(), LLUUID::null, LLTransactionID::tnull, "New Gesture", "", LLAssetType::AT_GESTURE, LLInventoryType::IT_GESTURE, NOT_WEARABLE, PERM_MOVE | LLFloaterPerms::getNextOwnerPerms("Gestures"), cb); }
void FSLSLBridge :: create_script_inner(LLViewerObject* object) { LLUUID catID = findFSCategory(); LLPointer<LLInventoryCallback> cb = new FSLSLBridgeScriptCallback(); create_inventory_item(gAgent.getID(), gAgent.getSessionID(), catID, //LLUUID::null, LLTransactionID::tnull, mCurrentFullName, mCurrentFullName, LLAssetType::AT_LSL_TEXT, LLInventoryType::IT_LSL, NOT_WEARABLE, mpBridge->getPermissions().getMaskNextOwner(), cb); }
void JCImportInventorycallback(const LLUUID& uuid, void* user_data, S32 result, LLExtStat ext_status) // StoreAssetData callback (fixed) { if(result == LL_ERR_NOERR) { //cmdline_printchat("fired importinvcall for "+uuid.asString()); InventoryImportInfo* data = (InventoryImportInfo*)user_data; LLPointer<LLInventoryCallback> cb = new JCImportTransferCallback(data); LLPermissions perm; LLUUID parent_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH); create_inventory_item(gAgent.getID(), gAgent.getSessionID(), gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH), data->tid, data->name, data->description, data->type, LLInventoryType::defaultForAssetType(data->type), data->wear_type, LLFloaterPerms::getNextOwnerPerms(), cb); }else cmdline_printchat("err: "+std::string(LLAssetStorage::getErrorString(result))); }
void LLFloaterWindLight::onSaveNotecard() { // get the name LLComboBox* comboBox = getChild<LLComboBox>("WLPresetsCombo"); // don't save the empty name if(comboBox->getSelectedItemLabel() == "") return; // Check if this is already a notecard. if(LLWLParamManager::instance()->mCurParams.mInventoryID.notNull()) { LLNotificationsUtil::add("KittyWLSaveNotecardAlert", LLSD(), LLSD(), boost::bind(&LLFloaterWindLight::saveNotecardCallback, this, _1, _2)); } else { // Make sure we have a ".wl" extension. std::string name = comboBox->getSelectedItemLabel(); if(name.length() > 2 && name.compare(name.length() - 3, 3, ".wl") != 0) { name += ".wl"; } LLPointer<KVFloaterWindLightNotecardCreatedCallback> cb = new KVFloaterWindLightNotecardCreatedCallback(); // Create a notecard and then save it. create_inventory_item(gAgent.getID(), gAgent.getSessionID(), gInventory.findCategoryUUIDForType(LLFolderType::FT_NOTECARD), LLTransactionID::tnull, name, "WindLight settings (Kitty Viewer compatible)", LLAssetType::AT_NOTECARD, LLInventoryType::IT_NOTECARD, NOT_WEARABLE, PERM_ITEM_UNRESTRICTED, cb); } }
void upload_new_resource(const LLTransactionID &tid, LLAssetType::EType asset_type, std::string name, std::string desc, S32 compression_info, LLAssetType::EType destination_folder_type, LLInventoryType::EType inv_type, U32 next_owner_perms, U32 group_perms, U32 everyone_perms, const std::string& display_name, LLAssetStorage::LLStoreAssetCallback callback, S32 expected_upload_cost, void *userdata) { if(gDisconnected) { return ; } LLAssetID uuid = tid.makeAssetID(gAgent.getSecureSessionID()); if( LLAssetType::AT_SOUND == asset_type ) { LLViewerStats::getInstance()->incStat(LLViewerStats::ST_UPLOAD_SOUND_COUNT ); } else if( LLAssetType::AT_TEXTURE == asset_type ) { LLViewerStats::getInstance()->incStat(LLViewerStats::ST_UPLOAD_TEXTURE_COUNT ); } else if( LLAssetType::AT_ANIMATION == asset_type) { LLViewerStats::getInstance()->incStat(LLViewerStats::ST_UPLOAD_ANIM_COUNT ); } else if( LLAssetType::AT_LSL_TEXT == asset_type) { LLViewerStats::getInstance()->incStat(LLViewerStats::ST_LSL_SAVE_COUNT ); } if(LLInventoryType::IT_NONE == inv_type) { inv_type = LLInventoryType::defaultForAssetType(asset_type); } LLStringUtil::stripNonprintable(name); LLStringUtil::stripNonprintable(desc); if(name.empty()) { name = "(No Name)"; } if(desc.empty()) { desc = "(No Description)"; } // At this point, we're ready for the upload. std::string upload_message = "Uploading...\n\n"; upload_message.append(display_name); LLUploadDialog::modalUploadDialog(upload_message); llinfos << "*** Uploading: " << llendl; llinfos << "Type: " << LLAssetType::lookup(asset_type) << llendl; llinfos << "UUID: " << uuid << llendl; llinfos << "Name: " << name << llendl; llinfos << "Desc: " << desc << llendl; llinfos << "Expected Upload Cost: " << expected_upload_cost << llendl; lldebugs << "Folder: " << gInventory.findCategoryUUIDForType((destination_folder_type == LLAssetType::AT_NONE) ? asset_type : destination_folder_type) << llendl; lldebugs << "Asset Type: " << LLAssetType::lookup(asset_type) << llendl; if (LLAssetType::AT_LSL_TEXT == asset_type || LLAssetType::AT_NOTECARD == asset_type) { LLResourceData* data = new LLResourceData; data->mAssetInfo.mTransactionID = tid; data->mAssetInfo.mUuid = uuid; data->mAssetInfo.mType = asset_type; data->mAssetInfo.mCreatorID = gAgentID; data->mInventoryType = inv_type; data->mNextOwnerPerm = next_owner_perms; data->mExpectedUploadCost = expected_upload_cost; data->mUserData = userdata; data->mAssetInfo.setName(name); data->mAssetInfo.setDescription(desc); data->mPreferredLocation = destination_folder_type; LLPointer<LLInventoryCallback> cb = new CreateTextUploadCallback(data); create_inventory_item(gAgent.getID(), gAgent.getSessionID(), gInventory.findCategoryUUIDForType((destination_folder_type == LLAssetType::AT_NONE) ? asset_type : destination_folder_type), tid, name, desc, asset_type, inv_type, NOT_WEARABLE, next_owner_perms, cb); return; } std::string url = gAgent.getRegion()->getCapability("NewFileAgentInventory"); BOOL temporary_up = gSavedSettings.getBOOL("EmeraldTemporaryUpload"); gSavedSettings.setBOOL("EmeraldTemporaryUpload",FALSE); if (!url.empty() && temporary_up == FALSE) { llinfos << "New Agent Inventory via capability" << llendl; LLSD body; body["folder_id"] = gInventory.findCategoryUUIDForType((destination_folder_type == LLAssetType::AT_NONE) ? asset_type : destination_folder_type); body["asset_type"] = LLAssetType::lookup(asset_type); body["inventory_type"] = LLInventoryType::lookup(inv_type); body["name"] = name; body["description"] = desc; body["next_owner_mask"] = LLSD::Integer(next_owner_perms); body["group_mask"] = LLSD::Integer(group_perms); body["everyone_mask"] = LLSD::Integer(everyone_perms); if (LLAssetType::AT_SOUND == asset_type || LLAssetType::AT_TEXTURE == asset_type || LLAssetType::AT_ANIMATION == asset_type) { body["expected_upload_cost"] = LLSD::Integer(expected_upload_cost); } else { body["expected_upload_cost"] = LLSD::Integer(0); } //std::ostringstream llsdxml; //LLSDSerialize::toPrettyXML(body, llsdxml); //llinfos << "posting body to capability: " << llsdxml.str() << llendl; LLHTTPClient::post(url, body, new LLNewAgentInventoryResponder(body, uuid, asset_type)); } else { if(temporary_up == FALSE) { llinfos << "NewAgentInventory capability not found, new agent inventory via asset system." << llendl; // check for adequate funds // TODO: do this check on the sim if (LLAssetType::AT_SOUND == asset_type || LLAssetType::AT_TEXTURE == asset_type || LLAssetType::AT_ANIMATION == asset_type) { S32 balance = gStatusBar->getBalance(); if (balance < expected_upload_cost) { // insufficient funds, bail on this upload LLFloaterBuyCurrency::buyCurrency("Uploading costs", expected_upload_cost); return; } } } LLResourceData* data = new LLResourceData; data->mAssetInfo.mTransactionID = tid; data->mAssetInfo.mUuid = uuid; data->mAssetInfo.mType = asset_type; data->mAssetInfo.mCreatorID = gAgentID; data->mInventoryType = inv_type; data->mNextOwnerPerm = next_owner_perms; data->mExpectedUploadCost = expected_upload_cost; data->mUserData = userdata; data->mAssetInfo.setName(name); data->mAssetInfo.setDescription(desc); data->mPreferredLocation = destination_folder_type; LLAssetStorage::LLStoreAssetCallback asset_callback = temporary_up ? &temp_upload_done_callback : &upload_done_callback; if (callback) { asset_callback = callback; } gAssetStorage->storeAssetData(data->mAssetInfo.mTransactionID, data->mAssetInfo.mType, asset_callback, (void*)data, temporary_up, TRUE, temporary_up); } }
// <edit> void upload_done_callback(const LLUUID& uuid, void* user_data, S32 result, LLExtStat ext_status) // StoreAssetData callback (fixed) { LLResourceData* data = (LLResourceData*)user_data; S32 expected_upload_cost = data ? data->mExpectedUploadCost : 0; //LLAssetType::EType pref_loc = data->mPreferredLocation; BOOL is_balance_sufficient = TRUE; if(!data) { LLUploadDialog::modalUploadFinished(); return; } if(result >= 0) { LLFolderType::EType dest_loc = (data->mPreferredLocation == LLFolderType::FT_NONE) ? LLFolderType::assetTypeToFolderType(data->mAssetInfo.mType) : data->mPreferredLocation; if (LLAssetType::AT_SOUND == data->mAssetInfo.mType || LLAssetType::AT_TEXTURE == data->mAssetInfo.mType || LLAssetType::AT_ANIMATION == data->mAssetInfo.mType) { // Charge the user for the upload. LLViewerRegion* region = gAgent.getRegion(); if(!(can_afford_transaction(expected_upload_cost))) { LLFloaterBuyCurrency::buyCurrency( llformat("Uploading %s costs", data->mAssetInfo.getName().c_str()), // *TODO: Translate expected_upload_cost); is_balance_sufficient = FALSE; } else if(region) { // Charge user for upload gStatusBar->debitBalance(expected_upload_cost); LLMessageSystem* msg = gMessageSystem; msg->newMessageFast(_PREHASH_MoneyTransferRequest); msg->nextBlockFast(_PREHASH_AgentData); msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID()); msg->nextBlockFast(_PREHASH_MoneyData); msg->addUUIDFast(_PREHASH_SourceID, gAgent.getID()); msg->addUUIDFast(_PREHASH_DestID, LLUUID::null); msg->addU8("Flags", 0); // we tell the sim how much we were expecting to pay so it // can respond to any discrepancy msg->addS32Fast(_PREHASH_Amount, expected_upload_cost); msg->addU8Fast(_PREHASH_AggregatePermNextOwner, (U8)LLAggregatePermissions::AP_EMPTY); msg->addU8Fast(_PREHASH_AggregatePermInventory, (U8)LLAggregatePermissions::AP_EMPTY); msg->addS32Fast(_PREHASH_TransactionType, TRANS_UPLOAD_CHARGE); msg->addStringFast(_PREHASH_Description, NULL); msg->sendReliable(region->getHost()); } } if(is_balance_sufficient) { // Actually add the upload to inventory llinfos << "Adding " << uuid << " to inventory." << llendl; const LLUUID folder_id = gInventory.findCategoryUUIDForType(dest_loc); if(folder_id.notNull()) { U32 next_owner_perms = data->mNextOwnerPerm; if(PERM_NONE == next_owner_perms) { next_owner_perms = PERM_MOVE | PERM_TRANSFER; } create_inventory_item(gAgent.getID(), gAgent.getSessionID(), folder_id, data->mAssetInfo.mTransactionID, data->mAssetInfo.getName(), data->mAssetInfo.getDescription(), data->mAssetInfo.mType, data->mInventoryType, NOT_WEARABLE, next_owner_perms, LLPointer<LLInventoryCallback>(NULL)); } else { llwarns << "Can't find a folder to put it in" << llendl; } } } else // if(result >= 0) { LLSD args; args["FILE"] = LLInventoryType::lookupHumanReadable(data->mInventoryType); args["REASON"] = std::string(LLAssetStorage::getErrorString(result)); LLNotificationsUtil::add("CannotUploadReason", args); } LLUploadDialog::modalUploadFinished(); delete data; data = NULL; }
void upload_done_callback(const LLUUID& uuid, void* user_data, S32 result, LLExtStat ext_status) // StoreAssetData callback (fixed) { LLResourceData* data = (LLResourceData*)user_data; S32 expected_upload_cost = data ? data->mExpectedUploadCost : 0; //LLAssetType::EType pref_loc = data->mPreferredLocation; BOOL is_balance_sufficient = TRUE; if(result >= 0) { LLAssetType::EType dest_loc = (data->mPreferredLocation == LLAssetType::AT_NONE) ? data->mAssetInfo.mType : data->mPreferredLocation; if (LLAssetType::AT_SOUND == data->mAssetInfo.mType || LLAssetType::AT_TEXTURE == data->mAssetInfo.mType || LLAssetType::AT_ANIMATION == data->mAssetInfo.mType) { // Charge the user for the upload. LLViewerRegion* region = gAgent.getRegion(); if(!(can_afford_transaction(expected_upload_cost))) { LLFloaterBuyCurrency::buyCurrency( llformat("Uploading %s costs", data->mAssetInfo.getName().c_str()), // *TODO: Translate expected_upload_cost); is_balance_sufficient = FALSE; } else if(region) { // Charge user for upload gStatusBar->debitBalance(expected_upload_cost); LLMessageSystem* msg = gMessageSystem; msg->newMessageFast(_PREHASH_MoneyTransferRequest); msg->nextBlockFast(_PREHASH_AgentData); msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID()); msg->nextBlockFast(_PREHASH_MoneyData); msg->addUUIDFast(_PREHASH_SourceID, gAgent.getID()); msg->addUUIDFast(_PREHASH_DestID, LLUUID::null); msg->addU8("Flags", 0); // we tell the sim how much we were expecting to pay so it // can respond to any discrepancy msg->addS32Fast(_PREHASH_Amount, expected_upload_cost); msg->addU8Fast(_PREHASH_AggregatePermNextOwner, (U8)LLAggregatePermissions::AP_EMPTY); msg->addU8Fast(_PREHASH_AggregatePermInventory, (U8)LLAggregatePermissions::AP_EMPTY); msg->addS32Fast(_PREHASH_TransactionType, TRANS_UPLOAD_CHARGE); msg->addStringFast(_PREHASH_Description, NULL); msg->sendReliable(region->getHost()); } } if(is_balance_sufficient) { // Actually add the upload to inventory llinfos << "Adding " << uuid << " to inventory." << llendl; LLUUID folder_id(gInventory.findCategoryUUIDForType(dest_loc)); if(folder_id.notNull()) { U32 next_owner_perms = data->mNextOwnerPerm; if(PERM_NONE == next_owner_perms) { next_owner_perms = PERM_MOVE | PERM_TRANSFER; } create_inventory_item(gAgent.getID(), gAgent.getSessionID(), folder_id, data->mAssetInfo.mTransactionID, data->mAssetInfo.getName(), data->mAssetInfo.getDescription(), data->mAssetInfo.mType, data->mInventoryType, NOT_WEARABLE, next_owner_perms, LLPointer<LLInventoryCallback>(NULL)); } else { llwarns << "Can't find a folder to put it in" << llendl; } } } else // if(result >= 0) { LLSD args; args["FILE"] = LLInventoryType::lookupHumanReadable(data->mInventoryType); args["REASON"] = std::string(LLAssetStorage::getErrorString(result)); LLNotifications::instance().add("CannotUploadReason", args); } LLUploadDialog::modalUploadFinished(); delete data; // *NOTE: This is a pretty big hack. What this does is check the // file picker if there are any more pending uploads. If so, // upload that file. const std::string& next_file = LLFilePicker::instance().getNextFile(); if(is_balance_sufficient && !next_file.empty()) { std::string asset_name = gDirUtilp->getBaseFileName(next_file, true); 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; void *userdata = NULL; upload_new_resource(next_file, asset_name, asset_name, // file 0, LLAssetType::AT_NONE, LLInventoryType::IT_NONE, PERM_NONE, PERM_NONE, PERM_NONE, display_name, callback, expected_upload_cost, // assuming next in a group of uploads is of roughly the same type, i.e. same upload cost userdata); } }
void upload_new_resource(const std::string& src_filename, std::string name, std::string desc, S32 compression_info, LLFolderType::EType destination_folder_type, LLInventoryType::EType inv_type, U32 next_owner_perms, U32 group_perms, U32 everyone_perms, const std::string& display_name, LLAssetStorage::LLStoreAssetCallback callback, S32 expected_upload_cost, void *userdata) { // Generate the temporary UUID. std::string filename = gDirUtilp->getTempFilename(); LLTransactionID tid; LLAssetID uuid; LLSD args; std::string exten = gDirUtilp->getExtension(src_filename); 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; } else if( exten == "bmp") { asset_type = LLAssetType::AT_TEXTURE; if (!LLViewerTextureList::createUploadFile(src_filename, filename, IMG_CODEC_BMP )) { 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; } } else if( exten == "tga") { asset_type = LLAssetType::AT_TEXTURE; if (!LLViewerTextureList::createUploadFile(src_filename, filename, IMG_CODEC_TGA )) { 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; } } else if( exten == "jpg" || exten == "jpeg") { asset_type = LLAssetType::AT_TEXTURE; if (!LLViewerTextureList::createUploadFile(src_filename, filename, IMG_CODEC_JPEG )) { 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; } } else if( exten == "png") { asset_type = LLAssetType::AT_TEXTURE; if (!LLViewerTextureList::createUploadFile(src_filename, filename, IMG_CODEC_PNG )) { 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; } } else if(exten == "wav") { asset_type = LLAssetType::AT_SOUND; // tag it as audio S32 encode_result = 0; llinfos << "Attempting to encode wav as an ogg file" << llendl; 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; } } else if(exten == "ogg") { asset_type = LLAssetType::AT_SOUND; // tag it as audio filename = src_filename; } else if(exten == "tmp") { // This is a generic .lin resource file asset_type = LLAssetType::AT_OBJECT; LLFILE* in = LLFile::fopen(src_filename, "rb"); /* Flawfinder: ignore */ if (in) { // read in the file header char buf[16384]; /* Flawfinder: ignore */ size_t readbytes; S32 version; if (fscanf(in, "LindenResource\nversion %d\n", &version)) { if (2 == version) { // *NOTE: This buffer size is hard coded into scanf() below. char label[MAX_STRING]; /* Flawfinder: ignore */ char value[MAX_STRING]; /* Flawfinder: ignore */ S32 tokens_read; while (fgets(buf, 1024, in)) { label[0] = '\0'; value[0] = '\0'; tokens_read = sscanf( /* Flawfinder: ignore */ buf, "%254s %254s\n", label, value); llinfos << "got: " << label << " = " << value << llendl; if (EOF == tokens_read) { fclose(in); error_message = llformat("corrupt resource file: %s", src_filename.c_str()); args["FILE"] = src_filename; upload_error(error_message, "CorruptResourceFile", filename, args); return; } if (2 == tokens_read) { if (! strcmp("type", label)) { asset_type = (LLAssetType::EType)(atoi(value)); } } else { if (! strcmp("_DATA_", label)) { // below is the data section break; } } // other values are currently discarded } } else { fclose(in); error_message = llformat("unknown linden resource file version in file: %s", src_filename.c_str()); args["FILE"] = src_filename; upload_error(error_message, "UnknownResourceFileVersion", filename, args); return; } } else { // this is an original binary formatted .lin file // start over at the beginning of the file fseek(in, 0, SEEK_SET); const S32 MAX_ASSET_DESCRIPTION_LENGTH = 256; const S32 MAX_ASSET_NAME_LENGTH = 64; S32 header_size = 34 + MAX_ASSET_DESCRIPTION_LENGTH + MAX_ASSET_NAME_LENGTH; S16 type_num; // read in and throw out most of the header except for the type if (fread(buf, header_size, 1, in) != 1) { llwarns << "Short read" << llendl; } memcpy(&type_num, buf + 16, sizeof(S16)); /* Flawfinder: ignore */ asset_type = (LLAssetType::EType)type_num; } // copy the file's data segment into another file for uploading LLFILE* out = LLFile::fopen(filename, "wb"); /* Flawfinder: ignore */ if (out) { while((readbytes = fread(buf, 1, 16384, in))) /* Flawfinder: ignore */ { if (fwrite(buf, 1, readbytes, out) != readbytes) { llwarns << "Short write" << llendl; } } fclose(out); } else { fclose(in); error_message = llformat( "Unable to create output file: %s", filename.c_str()); args["FILE"] = filename; upload_error(error_message, "UnableToCreateOutputFile", filename, args); return; } fclose(in); } else { llinfos << "Couldn't open .lin file " << src_filename << llendl; } } 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; } // <edit> else if (exten == "anim" || exten == "animatn") { asset_type = LLAssetType::AT_ANIMATION; filename = src_filename; } else if(exten == "j2k" || exten == "jp2" || exten == "j2c") { asset_type = LLAssetType::AT_TEXTURE; filename = src_filename; } // </edit> else { // Unknown extension // *TODO: Translate? error_message = llformat("Unknown file extension .%s\nExpected .wav, .tga, .bmp, .jpg, .jpeg, or .bvh", 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(filename, LL_APR_RB, &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) { std::string t_disp_name = display_name; if (t_disp_name.empty()) { t_disp_name = src_filename; } // <edit> hack to create scripts and gestures if(exten == "lsl" || exten == "gesture" || exten == "notecard") // added notecard Oct 15 2009 { LLInventoryType::EType inv_type = LLInventoryType::IT_GESTURE; if(exten == "lsl") inv_type = LLInventoryType::IT_LSL; else if(exten == "gesture") inv_type = LLInventoryType::IT_GESTURE; else if(exten == "notecard") inv_type = LLInventoryType::IT_NOTECARD; create_inventory_item( gAgent.getID(), gAgent.getSessionID(), gInventory.findCategoryUUIDForType(LLFolderType::assetTypeToFolderType(asset_type)), LLTransactionID::tnull, name, uuid.asString(), // fake asset id, but in vfs asset_type, inv_type, NOT_WEARABLE, PERM_ITEM_UNRESTRICTED, new NewResourceItemCallback); } else // </edit> upload_new_resource(tid, asset_type, name, desc, compression_info, // tid destination_folder_type, inv_type, next_owner_perms, group_perms, everyone_perms, display_name, callback, expected_upload_cost, userdata); } else { llwarns << error_message << llendl; LLSD args; args["ERROR_MESSAGE"] = error_message; LLNotificationsUtil::add("ErrorMessage", args); if(LLFile::remove(filename) == -1) { lldebugs << "unable to remove temp file" << llendl; } //AIFIXME? LLFilePicker::instance().reset(); } }
void LLFloaterWindLight::onSavePreset(LLUICtrl* ctrl, void* userData) { // don't save the empty name if(sWindLight->mSkyPresetCombo->getSelectedItemLabel() == "") { return; } if (ctrl->getValue().asString() == "save_inventory_item") { // Check if this is already a notecard and that its not in the trash or purged. LLUUID trash_id; trash_id = gInventory.findCategoryUUIDForType(LLAssetType::AT_TRASH); if(LLWLParamManager::instance()->mCurParams.mInventoryID.notNull() && !gInventory.isObjectDescendentOf(LLWLParamManager::instance()->mCurParams.mInventoryID, trash_id) && gInventory.isObjectDescendentOf(LLWLParamManager::instance()->mCurParams.mInventoryID, gAgent.getInventoryRootID()) ) { LLNotifications::instance().add("KittyWLSaveNotecardAlert", LLSD(), LLSD(), saveNotecardCallback); } else { // Make sure we have a ".wl" extension. std::string name = sWindLight->mSkyPresetCombo->getSelectedItemLabel(); if(name.length() > 2 && name.compare(name.length() - 3, 3, ".wl") != 0) { name += ".wl"; } LLPointer<KVFloaterWindLightNotecardCreatedCallback> cb = new KVFloaterWindLightNotecardCreatedCallback(); // Create a notecard and then save it. create_inventory_item(gAgent.getID(), gAgent.getSessionID(), LLUUID::null, LLTransactionID::tnull, name, "WindLight settings (Imprudence compatible)", LLAssetType::AT_NOTECARD, LLInventoryType::IT_NOTECARD, NOT_WEARABLE, PERM_ITEM_UNRESTRICTED, cb); } } else { // check to see if it's a default and shouldn't be overwritten std::set<std::string>::iterator sIt = sDefaultPresets.find( sWindLight->mSkyPresetCombo->getSelectedItemLabel()); if(sIt != sDefaultPresets.end() && !gSavedSettings.getBOOL("SkyEditPresets")) { LLNotifications::instance().add("WLNoEditDefault"); return; } LLWLParamManager::instance()->mCurParams.mName = sWindLight->mSkyPresetCombo->getSelectedItemLabel(); LLNotifications::instance().add("WLSavePresetAlert", LLSD(), LLSD(), saveAlertCallback); } }
void upload_done_callback(const LLUUID& uuid, void* user_data, S32 result) // StoreAssetData callback (fixed) { LLResourceData* data = (LLResourceData*)user_data; //LLAssetType::EType pref_loc = data->mPreferredLocation; BOOL is_balance_sufficient = TRUE; if(result >= 0) { LLAssetType::EType dest_loc = (data->mPreferredLocation == LLAssetType::AT_NONE) ? data->mAssetInfo.mType : data->mPreferredLocation; if (LLAssetType::AT_SOUND == data->mAssetInfo.mType || LLAssetType::AT_TEXTURE == data->mAssetInfo.mType || LLAssetType::AT_ANIMATION == data->mAssetInfo.mType) { // Charge the user for the upload. LLViewerRegion* region = gAgent.getRegion(); S32 upload_cost = gGlobalEconomy->getPriceUpload(); if(!(can_afford_transaction(upload_cost))) { LLFloaterBuyCurrency::buyCurrency( llformat("Uploading %s costs", data->mAssetInfo.getName().c_str()), upload_cost); is_balance_sufficient = FALSE; } else if(region) { // Charge user for upload gStatusBar->debitBalance(upload_cost); LLMessageSystem* msg = gMessageSystem; msg->newMessageFast(_PREHASH_MoneyTransferRequest); msg->nextBlockFast(_PREHASH_AgentData); msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID()); msg->nextBlockFast(_PREHASH_MoneyData); msg->addUUIDFast(_PREHASH_SourceID, gAgent.getID()); msg->addUUIDFast(_PREHASH_DestID, LLUUID::null); msg->addU8("Flags", 0); msg->addS32Fast(_PREHASH_Amount, upload_cost); msg->addU8Fast(_PREHASH_AggregatePermNextOwner, (U8)LLAggregatePermissions::AP_EMPTY); msg->addU8Fast(_PREHASH_AggregatePermInventory, (U8)LLAggregatePermissions::AP_EMPTY); msg->addS32Fast(_PREHASH_TransactionType, TRANS_UPLOAD_CHARGE); msg->addStringFast(_PREHASH_Description, NULL); msg->sendReliable(region->getHost()); } } if(is_balance_sufficient) { // Actually add the upload to inventory llinfos << "Adding " << uuid << " to inventory." << llendl; LLUUID folder_id(gInventory.findCategoryUUIDForType(dest_loc)); if(folder_id.notNull()) { U32 next_owner_perm = data->mNextOwnerPerm; if(PERM_NONE == next_owner_perm) { next_owner_perm = PERM_MOVE | PERM_TRANSFER; } create_inventory_item(gAgent.getID(), gAgent.getSessionID(), folder_id, data->mAssetInfo.mTransactionID, data->mAssetInfo.getName(), data->mAssetInfo.getDescription(), data->mAssetInfo.mType, data->mInventoryType, NOT_WEARABLE, next_owner_perm, LLPointer<LLInventoryCallback>(NULL)); } else { llwarns << "Can't find a folder to put it in" << llendl; } } } else // if(result >= 0) { LLStringBase<char>::format_map_t args; args["[FILE]"] = LLInventoryType::lookupHumanReadable(data->mInventoryType); args["[REASON]"] = LLString(LLAssetStorage::getErrorString(result)); gViewerWindow->alertXml("CannotUploadReason", args); } LLUploadDialog::modalUploadFinished(); delete data; // *NOTE: This is a pretty big hack. What this does is check the // file picker if there are any more pending uploads. If so, // upload that file. const char* next_file = LLFilePicker::instance().getNextFile(); if(is_balance_sufficient && next_file) { const char* name = LLFilePicker::instance().getDirname(); LLString asset_name = name; LLString::replaceNonstandardASCII( asset_name, '?' ); LLString::replaceChar(asset_name, '|', '?'); LLString::stripNonprintable(asset_name); LLString::trim(asset_name); char* asset_name_str = (char*)asset_name.c_str(); char* end_p = strrchr(asset_name_str, '.'); // strip extension if exists if( !end_p ) { end_p = asset_name_str + strlen( asset_name_str ); /* Flawfinder: ignore */ } S32 len = llmin( (S32) (DB_INV_ITEM_NAME_STR_LEN), (S32) (end_p - asset_name_str) ); asset_name = asset_name.substr( 0, len ); upload_new_resource(next_file, asset_name, asset_name, // file 0, LLAssetType::AT_NONE, LLInventoryType::IT_NONE); } }
void ImportTracker::send_inventory(LLSD& prim) { U32 local_id = prim["LocalID"].asInteger(); if (prim.has("inventory")) { std::string assetpre = asset_dir + gDirUtilp->getDirDelimiter(); LLSD inventory = prim["inventory"]; for (LLSD::array_iterator inv = inventory.beginArray(); inv != inventory.endArray(); ++inv) { LLSD item = (*inv); InventoryImportInfo* data = new InventoryImportInfo; data->localid = local_id; LLTransactionID tid; tid.generate(); LLUUID assetid = tid.makeAssetID(gAgent.getSecureSessionID()); data->tid = tid; data->assetid = assetid; data->type = LLAssetType::lookup(item["type"].asString());////LLAssetType::EType(U32(item["type"].asInteger())); data->name = item["name"].asString(); data->description = item["desc"].asString(); if(item.has("item_id")) { //cmdline_printchat("item id found"); std::string filename = assetpre + item["item_id"].asString() + "." + item["type"].asString(); //S32 file_size; //LLAPRFile infile ; //infile.open(filename, LL_APR_RB, NULL, &file_size); //apr_file_t* fp = infile.getFileHandle(); //if(fp) if(LLFile::isfile(filename)) { //cmdline_printchat("file "+filename+" exists"); data->filename = filename; //infile.close(); }else { //cmdline_printchat("file "+filename+" does not exist"); delete data; continue; } }else { //cmdline_printchat("item id not found"); delete data; continue; } data->wear_type = NOT_WEARABLE; //if(data->type == LLAssetType::AT_LSL_TEXT) { data->inv_type = LLInventoryType::defaultForAssetType(data->type); //printchat("is script"); data->compiled = false; // switch(data->type) { case LLAssetType::AT_TEXTURE: case LLAssetType::AT_TEXTURE_TGA: //cmdline_printchat("case textures"); { std::string url = gAgent.getRegion()->getCapability("NewFileAgentInventory"); S32 file_size; LLAPRFile infile ; infile.open(data->filename, LL_APR_RB, NULL, &file_size); if (infile.getFileHandle()) { //cmdline_printchat("got file handle"); LLVFile file(gVFS, data->assetid, data->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); } LLSD body; body["folder_id"] = gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH); body["asset_type"] = LLAssetType::lookup(data->type); body["inventory_type"] = LLInventoryType::lookup(data->inv_type); body["name"] = data->name; body["description"] = data->description; body["next_owner_mask"] = LLSD::Integer(U32_MAX); body["group_mask"] = LLSD::Integer(U32_MAX); body["everyone_mask"] = LLSD::Integer(U32_MAX); body["expected_upload_cost"] = LLSD::Integer(LLGlobalEconomy::Singleton::getInstance()->getPriceUpload()); //cmdline_printchat("posting "+ data->assetid.asString()); LLHTTPClient::post(url, body, new JCImportInventoryResponder(body, data->assetid, data->type,data)); //error = TRUE; } } break; case LLAssetType::AT_CLOTHING: case LLAssetType::AT_BODYPART: //cmdline_printchat("case cloth/bodypart"); { S32 file_size; LLAPRFile infile ; infile.open(data->filename, LL_APR_RB, NULL, &file_size); if (infile.getFileHandle()) { //cmdline_printchat("got file handle @ cloth"); LLVFile file(gVFS, data->assetid, data->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); } LLFILE* fp = LLFile::fopen(data->filename, "rb"); if(fp)//HACK LOL LOL LOL { LLWearable* wearable = new LLWearable(LLUUID::null); wearable->importFile( fp ); //if (!res) { data->wear_type = wearable->getType(); } delete wearable; } //cmdline_printchat("storing "+data->assetid.asString()); gAssetStorage->storeAssetData(data->tid, data->type, JCImportInventorycallback, (void*)data, FALSE, TRUE, FALSE); } } break; case LLAssetType::AT_NOTECARD: //cmdline_printchat("case notecard"); { //std::string agent_url = gAgent.getRegion()->getCapability("UpdateNotecardAgentInventory"); LLPointer<LLInventoryCallback> cb = new JCPostInvCallback(data); LLPermissions perm; LLUUID parent_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH); create_inventory_item(gAgent.getID(), gAgent.getSessionID(), gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH), data->tid, data->name, data->description, data->type, LLInventoryType::defaultForAssetType(data->type), data->wear_type, LLFloaterPerms::getNextOwnerPerms(), cb); } break; case LLAssetType::AT_LSL_TEXT: { LLPointer<LLInventoryCallback> cb = new JCPostInvCallback(data); LLPermissions perm; LLUUID parent_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH); create_inventory_item(gAgent.getID(), gAgent.getSessionID(), gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH), data->tid, data->name, data->description, data->type, LLInventoryType::defaultForAssetType(data->type), data->wear_type, LLFloaterPerms::getNextOwnerPerms(), cb); } break; case LLAssetType::AT_SCRIPT://this shouldn't happen as this is legacy shit case LLAssetType::AT_GESTURE://we don't import you atm... default: break; } asset_insertions += 1; } } } }