Annotation of /trunk/indra/newview/llwearablelist.cpp
Parent Directory
|
Revision Log
Revision 137 - (view) (download)
| 1 : | mjm | 135 | /** |
| 2 : | * @file llwearablelist.cpp | ||
| 3 : | * @brief LLWearableList class implementation | ||
| 4 : | * | ||
| 5 : | * $LicenseInfo:firstyear=2002&license=viewergpl$ | ||
| 6 : | * | ||
| 7 : | mjm | 137 | * Copyright (c) 2002-2010, Linden Research, Inc. |
| 8 : | mjm | 135 | * |
| 9 : | * Second Life Viewer Source Code | ||
| 10 : | * The source code in this file ("Source Code") is provided by Linden Lab | ||
| 11 : | * to you under the terms of the GNU General Public License, version 2.0 | ||
| 12 : | * ("GPL"), unless you have obtained a separate licensing agreement | ||
| 13 : | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
| 14 : | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
| 15 : | * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 | ||
| 16 : | * | ||
| 17 : | * There are special exceptions to the terms and conditions of the GPL as | ||
| 18 : | * it is applied to this Source Code. View the full text of the exception | ||
| 19 : | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
| 20 : | * online at | ||
| 21 : | * http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
| 22 : | * | ||
| 23 : | * By copying, modifying or distributing this software, you acknowledge | ||
| 24 : | * that you have read and understood your obligations described above, | ||
| 25 : | * and agree to abide by those obligations. | ||
| 26 : | * | ||
| 27 : | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
| 28 : | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
| 29 : | * COMPLETENESS OR PERFORMANCE. | ||
| 30 : | * $/LicenseInfo$ | ||
| 31 : | */ | ||
| 32 : | |||
| 33 : | #include "llviewerprecompiledheaders.h" | ||
| 34 : | |||
| 35 : | #include "llwearablelist.h" | ||
| 36 : | |||
| 37 : | #include "message.h" | ||
| 38 : | #include "llassetstorage.h" | ||
| 39 : | #include "llagent.h" | ||
| 40 : | #include "llvoavatar.h" | ||
| 41 : | #include "llviewerinventory.h" | ||
| 42 : | //#include "llfloaterchat.h" | ||
| 43 : | #include "llviewerstats.h" | ||
| 44 : | #include "llnotify.h" | ||
| 45 : | |||
| 46 : | // Globals | ||
| 47 : | LLWearableList gWearableList; // Globally constructed; be careful that there's no dependency with gAgent. | ||
| 48 : | |||
| 49 : | |||
| 50 : | struct LLWearableArrivedData | ||
| 51 : | { | ||
| 52 : | LLWearableArrivedData( | ||
| 53 : | LLAssetType::EType asset_type, | ||
| 54 : | const std::string& wearable_name, | ||
| 55 : | void(*asset_arrived_callback)(LLWearable*, void* userdata), | ||
| 56 : | void* userdata ) | ||
| 57 : | : | ||
| 58 : | mAssetType( asset_type ), | ||
| 59 : | mCallback( asset_arrived_callback ), | ||
| 60 : | mUserdata( userdata ), | ||
| 61 : | mName( wearable_name ), | ||
| 62 : | mRetries(0) | ||
| 63 : | {} | ||
| 64 : | |||
| 65 : | LLAssetType::EType mAssetType; | ||
| 66 : | void (*mCallback)(LLWearable*, void* userdata); | ||
| 67 : | void* mUserdata; | ||
| 68 : | std::string mName; | ||
| 69 : | S32 mRetries; | ||
| 70 : | }; | ||
| 71 : | |||
| 72 : | |||
| 73 : | |||
| 74 : | //////////////////////////////////////////////////////////////////////////// | ||
| 75 : | // LLWearableList | ||
| 76 : | |||
| 77 : | LLWearableList::~LLWearableList() | ||
| 78 : | { | ||
| 79 : | for_each(mList.begin(), mList.end(), DeletePairedPointer()); | ||
| 80 : | mList.clear(); | ||
| 81 : | } | ||
| 82 : | |||
| 83 : | void LLWearableList::getAsset( const LLAssetID& assetID, const std::string& wearable_name, LLAssetType::EType asset_type, void(*asset_arrived_callback)(LLWearable*, void* userdata), void* userdata ) | ||
| 84 : | { | ||
| 85 : | llassert( (asset_type == LLAssetType::AT_CLOTHING) || (asset_type == LLAssetType::AT_BODYPART) ); | ||
| 86 : | LLWearable* instance = get_if_there(mList, assetID, (LLWearable*)NULL ); | ||
| 87 : | if( instance ) | ||
| 88 : | { | ||
| 89 : | asset_arrived_callback( instance, userdata ); | ||
| 90 : | } | ||
| 91 : | else | ||
| 92 : | { | ||
| 93 : | gAssetStorage->getAssetData( | ||
| 94 : | assetID, | ||
| 95 : | asset_type, | ||
| 96 : | LLWearableList::processGetAssetReply, | ||
| 97 : | (void*)new LLWearableArrivedData( asset_type, wearable_name, asset_arrived_callback, userdata ), | ||
| 98 : | TRUE); | ||
| 99 : | } | ||
| 100 : | } | ||
| 101 : | |||
| 102 : | // static | ||
| 103 : | void LLWearableList::processGetAssetReply( const char* filename, const LLAssetID& uuid, void* userdata, S32 status, LLExtStat ext_status ) | ||
| 104 : | { | ||
| 105 : | BOOL isNewWearable = FALSE; | ||
| 106 : | LLWearableArrivedData* data = (LLWearableArrivedData*) userdata; | ||
| 107 : | LLWearable* wearable = NULL; // NULL indicates failure | ||
| 108 : | |||
| 109 : | if( !filename ) | ||
| 110 : | { | ||
| 111 : | LL_WARNS("Wearable") << "Bad Wearable Asset: missing file." << LL_ENDL; | ||
| 112 : | } | ||
| 113 : | else | ||
| 114 : | if( status >= 0 ) | ||
| 115 : | { | ||
| 116 : | // read the file | ||
| 117 : | LLFILE* fp = LLFile::fopen(std::string(filename), "rb"); /*Flawfinder: ignore*/ | ||
| 118 : | if( !fp ) | ||
| 119 : | { | ||
| 120 : | LL_WARNS("Wearable") << "Bad Wearable Asset: unable to open file: '" << filename << "'" << LL_ENDL; | ||
| 121 : | } | ||
| 122 : | else | ||
| 123 : | { | ||
| 124 : | wearable = new LLWearable(uuid); | ||
| 125 : | bool res = wearable->importFile( fp ); | ||
| 126 : | if (!res) | ||
| 127 : | { | ||
| 128 : | if (wearable->getType() == WT_COUNT) | ||
| 129 : | { | ||
| 130 : | isNewWearable = TRUE; | ||
| 131 : | } | ||
| 132 : | delete wearable; | ||
| 133 : | wearable = NULL; | ||
| 134 : | } | ||
| 135 : | |||
| 136 : | fclose( fp ); | ||
| 137 : | if(filename) | ||
| 138 : | { | ||
| 139 : | LLFile::remove(std::string(filename)); | ||
| 140 : | } | ||
| 141 : | } | ||
| 142 : | } | ||
| 143 : | else | ||
| 144 : | { | ||
| 145 : | if(filename) | ||
| 146 : | { | ||
| 147 : | LLFile::remove(std::string(filename)); | ||
| 148 : | } | ||
| 149 : | LLViewerStats::getInstance()->incStat( LLViewerStats::ST_DOWNLOAD_FAILED ); | ||
| 150 : | |||
| 151 : | LL_WARNS("Wearable") << "Wearable download failed: " << LLAssetStorage::getErrorString( status ) << " " << uuid << LL_ENDL; | ||
| 152 : | switch( status ) | ||
| 153 : | { | ||
| 154 : | case LL_ERR_ASSET_REQUEST_NOT_IN_DATABASE: | ||
| 155 : | { | ||
| 156 : | // Fail | ||
| 157 : | break; | ||
| 158 : | } | ||
| 159 : | default: | ||
| 160 : | { | ||
| 161 : | static const S32 MAX_RETRIES = 3; | ||
| 162 : | if (data->mRetries < MAX_RETRIES) | ||
| 163 : | { | ||
| 164 : | // Try again | ||
| 165 : | data->mRetries++; | ||
| 166 : | gAssetStorage->getAssetData(uuid, | ||
| 167 : | data->mAssetType, | ||
| 168 : | LLWearableList::processGetAssetReply, | ||
| 169 : | userdata); // re-use instead of deleting. | ||
| 170 : | return; | ||
| 171 : | } | ||
| 172 : | else | ||
| 173 : | { | ||
| 174 : | // Fail | ||
| 175 : | break; | ||
| 176 : | } | ||
| 177 : | } | ||
| 178 : | } | ||
| 179 : | } | ||
| 180 : | |||
| 181 : | if (wearable) // success | ||
| 182 : | { | ||
| 183 : | gWearableList.mList[ uuid ] = wearable; | ||
| 184 : | LL_DEBUGS("Wearable") << "processGetAssetReply()" << LL_ENDL; | ||
| 185 : | LL_DEBUGS("Wearable") << wearable << LL_ENDL; | ||
| 186 : | } | ||
| 187 : | else | ||
| 188 : | { | ||
| 189 : | LLSD args; | ||
| 190 : | // *TODO:translate | ||
| 191 : | args["TYPE"] = LLAssetType::lookupHumanReadable(data->mAssetType); | ||
| 192 : | if (isNewWearable) | ||
| 193 : | { | ||
| 194 : | LLNotifications::instance().add("InvalidWearable"); | ||
| 195 : | } | ||
| 196 : | else if (data->mName.empty()) | ||
| 197 : | { | ||
| 198 : | LLNotifications::instance().add("FailedToFindWearableUnnamed", args); | ||
| 199 : | } | ||
| 200 : | else | ||
| 201 : | { | ||
| 202 : | args["DESC"] = data->mName; | ||
| 203 : | LLNotifications::instance().add("FailedToFindWearable", args); | ||
| 204 : | } | ||
| 205 : | } | ||
| 206 : | // Always call callback; wearable will be NULL if we failed | ||
| 207 : | { | ||
| 208 : | if( data->mCallback ) | ||
| 209 : | { | ||
| 210 : | data->mCallback( wearable, data->mUserdata ); | ||
| 211 : | } | ||
| 212 : | } | ||
| 213 : | delete data; | ||
| 214 : | } | ||
| 215 : | |||
| 216 : | |||
| 217 : | // Creates a new wearable just like the old_wearable but with data copied over from item | ||
| 218 : | LLWearable* LLWearableList::createWearableMatchedToInventoryItem( LLWearable* old_wearable, LLViewerInventoryItem* item ) | ||
| 219 : | { | ||
| 220 : | lldebugs << "LLWearableList::createWearableMatchedToInventoryItem()" << llendl; | ||
| 221 : | |||
| 222 : | LLTransactionID tid; | ||
| 223 : | LLAssetID new_asset_id; | ||
| 224 : | new_asset_id = tid.makeAssetID(gAgent.getSecureSessionID()); | ||
| 225 : | |||
| 226 : | LLWearable* wearable = new LLWearable( tid ); | ||
| 227 : | wearable->copyDataFrom( old_wearable ); | ||
| 228 : | |||
| 229 : | wearable->setName( item->getName() ); | ||
| 230 : | wearable->setDescription( item->getDescription() ); | ||
| 231 : | wearable->setPermissions( item->getPermissions() ); | ||
| 232 : | wearable->setSaleInfo( item->getSaleInfo() ); | ||
| 233 : | |||
| 234 : | mList[ new_asset_id ] = wearable; | ||
| 235 : | |||
| 236 : | // Send to the dataserver | ||
| 237 : | wearable->saveNewAsset(); | ||
| 238 : | |||
| 239 : | return wearable; | ||
| 240 : | } | ||
| 241 : | |||
| 242 : | LLWearable* LLWearableList::createCopyFromAvatar( LLWearable* old_wearable, const std::string& new_name ) | ||
| 243 : | { | ||
| 244 : | lldebugs << "LLWearableList::createCopyFromAvatar()" << llendl; | ||
| 245 : | |||
| 246 : | LLTransactionID tid; | ||
| 247 : | LLAssetID new_asset_id; | ||
| 248 : | tid.generate(); | ||
| 249 : | new_asset_id = tid.makeAssetID(gAgent.getSecureSessionID()); | ||
| 250 : | |||
| 251 : | LLWearable* wearable = new LLWearable( tid ); | ||
| 252 : | wearable->copyDataFrom( old_wearable ); | ||
| 253 : | LLPermissions perm(old_wearable->getPermissions()); | ||
| 254 : | perm.setOwnerAndGroup(LLUUID::null, gAgent.getID(), LLUUID::null, true); | ||
| 255 : | wearable->setPermissions(perm); | ||
| 256 : | wearable->readFromAvatar(); // update from the avatar | ||
| 257 : | |||
| 258 : | if (!new_name.empty()) wearable->setName(new_name); | ||
| 259 : | |||
| 260 : | mList[ new_asset_id ] = wearable; | ||
| 261 : | |||
| 262 : | // Send to the dataserver | ||
| 263 : | wearable->saveNewAsset(); | ||
| 264 : | |||
| 265 : | return wearable; | ||
| 266 : | } | ||
| 267 : | |||
| 268 : | |||
| 269 : | LLWearable* LLWearableList::createCopy( LLWearable* old_wearable ) | ||
| 270 : | { | ||
| 271 : | lldebugs << "LLWearableList::createCopy()" << llendl; | ||
| 272 : | |||
| 273 : | LLTransactionID tid; | ||
| 274 : | LLAssetID new_asset_id; | ||
| 275 : | tid.generate(); | ||
| 276 : | new_asset_id = tid.makeAssetID(gAgent.getSecureSessionID()); | ||
| 277 : | |||
| 278 : | LLWearable* wearable = new LLWearable( tid ); | ||
| 279 : | wearable->copyDataFrom( old_wearable ); | ||
| 280 : | LLPermissions perm(old_wearable->getPermissions()); | ||
| 281 : | perm.setOwnerAndGroup(LLUUID::null, gAgent.getID(), LLUUID::null, true); | ||
| 282 : | wearable->setPermissions(perm); | ||
| 283 : | mList[ new_asset_id ] = wearable; | ||
| 284 : | |||
| 285 : | // Send to the dataserver | ||
| 286 : | wearable->saveNewAsset(); | ||
| 287 : | |||
| 288 : | return wearable; | ||
| 289 : | } | ||
| 290 : | |||
| 291 : | LLWearable* LLWearableList::createNewWearable( EWearableType type ) | ||
| 292 : | { | ||
| 293 : | lldebugs << "LLWearableList::createNewWearable()" << llendl; | ||
| 294 : | |||
| 295 : | LLTransactionID tid; | ||
| 296 : | LLAssetID new_asset_id; | ||
| 297 : | tid.generate(); | ||
| 298 : | new_asset_id = tid.makeAssetID(gAgent.getSecureSessionID()); | ||
| 299 : | |||
| 300 : | LLWearable* wearable = new LLWearable( tid ); | ||
| 301 : | wearable->setType( type ); | ||
| 302 : | |||
| 303 : | std::string name = "New "; | ||
| 304 : | name.append( wearable->getTypeLabel() ); | ||
| 305 : | wearable->setName( name ); | ||
| 306 : | |||
| 307 : | LLPermissions perm; | ||
| 308 : | perm.init(gAgent.getID(), gAgent.getID(), LLUUID::null, LLUUID::null); | ||
| 309 : | perm.initMasks(PERM_ALL, PERM_ALL, PERM_NONE, PERM_NONE, PERM_MOVE | PERM_TRANSFER); | ||
| 310 : | wearable->setPermissions(perm); | ||
| 311 : | |||
| 312 : | // Description and sale info have default values. | ||
| 313 : | |||
| 314 : | wearable->setParamsToDefaults(); | ||
| 315 : | wearable->setTexturesToDefaults(); | ||
| 316 : | |||
| 317 : | mList[ new_asset_id ] = wearable; | ||
| 318 : | |||
| 319 : | // Send to the dataserver | ||
| 320 : | wearable->saveNewAsset(); | ||
| 321 : | |||
| 322 : | return wearable; | ||
| 323 : | } |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

