llwearablelist.cpp

Go to the documentation of this file.
00001 
00032 #include "llviewerprecompiledheaders.h"
00033 
00034 #include "llwearablelist.h"
00035 
00036 #include "message.h"
00037 #include "llassetstorage.h"
00038 #include "llagent.h"
00039 #include "llvoavatar.h"
00040 #include "llviewerinventory.h"
00041 //#include "llfloaterchat.h"
00042 #include "llviewerstats.h"
00043 #include "llnotify.h"
00044 
00045 // Globals
00046 LLWearableList gWearableList;
00047 
00048 
00049 struct LLWearableArrivedData
00050 {
00051         LLWearableArrivedData( 
00052                 LLAssetType::EType asset_type,
00053                 const LLString& wearable_name,
00054                 void(*asset_arrived_callback)(LLWearable*, void* userdata),
00055                 void* userdata ) 
00056                 :
00057                 mAssetType( asset_type ),
00058                 mCallback( asset_arrived_callback ), 
00059                 mUserdata( userdata ),
00060                 mName( wearable_name )
00061                 {}
00062 
00063         LLAssetType::EType mAssetType;
00064         void    (*mCallback)(LLWearable*, void* userdata);
00065         void*   mUserdata;
00066         LLString mName;
00067 };
00068 
00069 
00070 
00072 // LLWearableList
00073 
00074 LLWearableList::~LLWearableList()
00075 {
00076         mList.deleteAllData();
00077 }
00078 
00079 void LLWearableList::getAsset( const LLAssetID& assetID, const LLString& wearable_name, LLAssetType::EType asset_type, void(*asset_arrived_callback)(LLWearable*, void* userdata), void* userdata )
00080 {
00081         llassert( (asset_type == LLAssetType::AT_CLOTHING) || (asset_type == LLAssetType::AT_BODYPART) );
00082         LLWearable* instance = mList.getIfThere( assetID );
00083         if( instance )
00084         {
00085                 asset_arrived_callback( instance, userdata );
00086         }
00087         else
00088         {
00089                 gAssetStorage->getAssetData(
00090                         assetID,
00091                         asset_type,
00092                         LLWearableList::processGetAssetReply,
00093                         (void*)new LLWearableArrivedData( asset_type, wearable_name, asset_arrived_callback, userdata ),
00094                         TRUE);
00095         }
00096 }
00097 
00098 // static
00099 void LLWearableList::processGetAssetReply( const char* filename, const LLAssetID& uuid, void* userdata, S32 status, LLExtStat ext_status )
00100 {
00101         BOOL success = FALSE;
00102         LLWearableArrivedData* data = (LLWearableArrivedData*) userdata;
00103 
00104         if( !filename )
00105         {
00106                 llinfos << "Bad Wearable Asset: missing file." << llendl;
00107         }
00108         else
00109         if( status >= 0 )
00110         {
00111                 // read the file
00112                 FILE* fp = LLFile::fopen(filename, "rb");               /*Flawfinder: ignore*/
00113                 if( !fp )
00114                 {
00115                         llinfos << "Bad Wearable Asset: unable to open file: '" << filename << "'" << llendl;
00116                 }
00117                 else
00118                 {
00119                         LLWearable *wearable = new LLWearable(uuid);
00120                         if( wearable->importFile( fp ) )
00121                         {
00122 //                              llinfos << "processGetAssetReply()" << llendl;
00123 //                              wearable->dump();
00124 
00125                                 gWearableList.mList[ uuid ] = wearable;
00126                                 if( data->mCallback )
00127                                 {
00128                                         data->mCallback( wearable, data->mUserdata );
00129                                 }
00130                                 success = TRUE;
00131                         }
00132                         else
00133                         {
00134                                 LLString::format_map_t args;
00135                                 // *TODO:translate
00136                                 args["[TYPE]"] = LLAssetType::lookupHumanReadable(data->mAssetType);
00137                                 if (data->mName.empty())
00138                                 {
00139                                         LLNotifyBox::showXml("FailedToLoadWearableUnnamed", args);
00140                                 }
00141                                 else
00142                                 {
00143                                         args["[DESC]"] = data->mName;
00144                                         LLNotifyBox::showXml("FailedToLoadWearable", args);
00145                                 }
00146                                 delete wearable;
00147                         }
00148 
00149                         fclose( fp );
00150                         if(filename)
00151                         {
00152                                 LLFile::remove(filename);
00153                         }
00154                 }
00155         }
00156         else
00157         {
00158                 if(filename)
00159                 {
00160                         LLFile::remove(filename);
00161                 }
00162                 if( gViewerStats )
00163                 {
00164                         gViewerStats->incStat( LLViewerStats::ST_DOWNLOAD_FAILED );
00165                 }
00166 
00167                 llwarns << "Wearable download failed: " << LLAssetStorage::getErrorString( status ) << " " << uuid << llendl;
00168                 switch( status )
00169                 {
00170                   case LL_ERR_ASSET_REQUEST_NOT_IN_DATABASE:
00171                   {
00172                           LLString::format_map_t args;
00173                           // *TODO:translate
00174                           args["[TYPE]"] = LLAssetType::lookupHumanReadable(data->mAssetType);
00175                           if (data->mName.empty())
00176                           {
00177                                   LLNotifyBox::showXml("FailedToFindWearableUnnamed", args);
00178                           }
00179                           else
00180                           {
00181                                   args["[DESC]"] = data->mName;
00182                                   LLNotifyBox::showXml("FailedToFindWearable", args);
00183                           }
00184 
00185                           // Asset does not exist in the database.
00186                           // Can't load asset, so return NULL
00187                           if( data->mCallback )
00188                           {
00189                                   data->mCallback( NULL, data->mUserdata );
00190                           }
00191                           break;
00192                   }
00193                   default:
00194                   {
00195                           // Try again
00196                           gAssetStorage->getAssetData(uuid,
00197                                                                                   data->mAssetType,
00198                                                                                   LLWearableList::processGetAssetReply,
00199                                                                                   userdata);  // re-use instead of deleting.
00200                           return;
00201                   }
00202                 }
00203         }
00204 
00205         delete data;
00206 }
00207 
00208 
00209 LLWearable* LLWearableList::createLegacyWearableFromAvatar( EWearableType type )
00210 {
00211         llinfos << "LLWearableList::createLegacyWearableFromAvatar" << llendl;
00212         
00213         LLTransactionID tid;
00214         LLAssetID new_asset_id;
00215         tid.generate();
00216         new_asset_id = tid.makeAssetID(gAgent.getSecureSessionID());
00217         
00218         LLWearable* wearable = new LLWearable( tid );
00219         wearable->setType( type );
00220         wearable->setName( wearable->getTypeLabel() );
00221         wearable->setDescription( "Recovered from lost asset." );
00222 
00223         LLVOAvatar* avatar = gAgent.getAvatarObject();
00224         LLPermissions perm;
00225         perm.init( avatar->getID(), avatar->getID(), LLUUID::null, LLUUID::null );
00226         perm.initMasks(PERM_TRANSFER, PERM_TRANSFER, PERM_NONE, PERM_NONE, PERM_MOVE | PERM_TRANSFER);
00227         wearable->setPermissions( perm );
00228         
00229         // Save info is the default.
00230 
00231         wearable->readFromAvatar();
00232         
00233         mList[ new_asset_id ] = wearable;
00234 
00235         // Send to the dataserver
00236         wearable->saveNewAsset();
00237 
00238         return wearable;
00239 }
00240 
00241 
00242 // Creates a new wearable just like the old_wearable but with data copied over from item
00243 LLWearable* LLWearableList::createWearableMatchedToInventoryItem( LLWearable* old_wearable, LLViewerInventoryItem* item )
00244 {
00245         lldebugs << "LLWearableList::createWearableMatchedToInventoryItem()" << llendl;
00246 
00247         LLTransactionID tid;
00248         LLAssetID new_asset_id;
00249         new_asset_id = tid.makeAssetID(gAgent.getSecureSessionID());
00250 
00251         LLWearable* wearable = new LLWearable( tid );
00252         wearable->copyDataFrom( old_wearable );
00253 
00254         wearable->setName( item->getName() );
00255         wearable->setDescription( item->getDescription() );
00256         wearable->setPermissions( item->getPermissions() );
00257         wearable->setSaleInfo( item->getSaleInfo() );
00258 
00259         mList[ new_asset_id ] = wearable;
00260 
00261         // Send to the dataserver
00262         wearable->saveNewAsset();
00263 
00264         return wearable;
00265 }
00266 
00267 LLWearable* LLWearableList::createCopyFromAvatar( LLWearable* old_wearable, const std::string& new_name )
00268 {
00269         lldebugs << "LLWearableList::createCopyFromAvatar()" << llendl;
00270 
00271         LLTransactionID tid;
00272         LLAssetID new_asset_id;
00273         tid.generate();
00274         new_asset_id = tid.makeAssetID(gAgent.getSecureSessionID());
00275         
00276         LLWearable* wearable = new LLWearable( tid );
00277         wearable->copyDataFrom( old_wearable );
00278         LLPermissions perm(old_wearable->getPermissions());
00279         perm.setOwnerAndGroup(LLUUID::null, gAgent.getID(), LLUUID::null, true);
00280         wearable->setPermissions(perm);
00281         wearable->readFromAvatar();  // update from the avatar
00282    
00283         if (!new_name.empty()) wearable->setName(new_name);
00284 
00285         mList[ new_asset_id ] = wearable;
00286 
00287         // Send to the dataserver
00288         wearable->saveNewAsset();
00289 
00290         return wearable;
00291 }
00292 
00293 
00294 LLWearable* LLWearableList::createCopy( LLWearable* old_wearable )
00295 {
00296         lldebugs << "LLWearableList::createCopy()" << llendl;
00297 
00298         LLTransactionID tid;
00299         LLAssetID new_asset_id;
00300         tid.generate();
00301         new_asset_id = tid.makeAssetID(gAgent.getSecureSessionID());
00302         
00303         LLWearable* wearable = new LLWearable( tid );
00304         wearable->copyDataFrom( old_wearable );
00305         LLPermissions perm(old_wearable->getPermissions());
00306         perm.setOwnerAndGroup(LLUUID::null, gAgent.getID(), LLUUID::null, true);
00307         wearable->setPermissions(perm);
00308         mList[ new_asset_id ] = wearable;
00309 
00310         // Send to the dataserver
00311         wearable->saveNewAsset();
00312 
00313         return wearable;
00314 }
00315 
00316 LLWearable* LLWearableList::createNewWearable( EWearableType type )
00317 {
00318         lldebugs << "LLWearableList::createNewWearable()" << llendl;
00319 
00320         LLTransactionID tid;
00321         LLAssetID new_asset_id;
00322         tid.generate();
00323         new_asset_id = tid.makeAssetID(gAgent.getSecureSessionID());
00324         
00325         LLWearable* wearable = new LLWearable( tid );
00326         wearable->setType( type );
00327         
00328         LLString name = "New ";
00329         name.append( wearable->getTypeLabel() );
00330         wearable->setName( name );
00331 
00332         LLPermissions perm;
00333         perm.init(gAgent.getID(), gAgent.getID(), LLUUID::null, LLUUID::null);
00334         perm.initMasks(PERM_ALL, PERM_ALL, PERM_NONE, PERM_NONE, PERM_MOVE | PERM_TRANSFER);
00335         wearable->setPermissions(perm);
00336 
00337         // Description and sale info have default values.
00338         
00339         wearable->setParamsToDefaults();
00340         wearable->setTexturesToDefaults();
00341 
00342         mList[ new_asset_id ] = wearable;
00343 
00344         // Send to the dataserver
00345         wearable->saveNewAsset();
00346 
00347         return wearable;
00348 }

Generated on Thu Jul 1 06:09:45 2010 for Second Life Viewer by  doxygen 1.4.7