aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llwearable.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-09-06 18:24:57 -0500
committerJacek Antonelli2008-09-06 18:25:07 -0500
commit798d367d54a6c6379ad355bd8345fa40e31e7fe9 (patch)
tree1921f1708cd0240648c97bc02df2c2ab5f2fc41e /linden/indra/newview/llwearable.cpp
parentSecond Life viewer sources 1.20.15 (diff)
downloadmeta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.zip
meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.gz
meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.bz2
meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.xz
Second Life viewer sources 1.21.0-RC
Diffstat (limited to 'linden/indra/newview/llwearable.cpp')
-rw-r--r--linden/indra/newview/llwearable.cpp69
1 files changed, 30 insertions, 39 deletions
diff --git a/linden/indra/newview/llwearable.cpp b/linden/indra/newview/llwearable.cpp
index 27811e8..a746ebd 100644
--- a/linden/indra/newview/llwearable.cpp
+++ b/linden/indra/newview/llwearable.cpp
@@ -52,7 +52,7 @@
52S32 LLWearable::sCurrentDefinitionVersion = 1; 52S32 LLWearable::sCurrentDefinitionVersion = 1;
53 53
54// static 54// static
55const char* LLWearable::sTypeName[ WT_COUNT ] = 55const std::string LLWearable::sTypeName[ WT_COUNT+1 ] =
56{ 56{
57 "shape", 57 "shape",
58 "skin", 58 "skin",
@@ -66,11 +66,12 @@ const char* LLWearable::sTypeName[ WT_COUNT ] =
66 "gloves", 66 "gloves",
67 "undershirt", 67 "undershirt",
68 "underpants", 68 "underpants",
69 "skirt" 69 "skirt",
70 "invalid"
70}; 71};
71 72
72// static 73// static
73const char* LLWearable::sTypeLabel[ WT_COUNT ] = 74const std::string LLWearable::sTypeLabel[ WT_COUNT+1 ] =
74{ 75{
75 "Shape", 76 "Shape",
76 "Skin", 77 "Skin",
@@ -84,7 +85,8 @@ const char* LLWearable::sTypeLabel[ WT_COUNT ] =
84 "Gloves", 85 "Gloves",
85 "Undershirt", 86 "Undershirt",
86 "Underpants", 87 "Underpants",
87 "Skirt" 88 "Skirt",
89 "invalid"
88}; 90};
89 91
90 92
@@ -136,7 +138,7 @@ LLWearable::~LLWearable()
136 138
137 139
138// static 140// static
139EWearableType LLWearable::typeNameToType( const LLString& type_name ) 141EWearableType LLWearable::typeNameToType( const std::string& type_name )
140{ 142{
141 for( S32 i = 0; i < WT_COUNT; i++ ) 143 for( S32 i = 0; i < WT_COUNT; i++ )
142 { 144 {
@@ -149,37 +151,35 @@ EWearableType LLWearable::typeNameToType( const LLString& type_name )
149} 151}
150 152
151 153
152const char* terse_F32_to_string( F32 f, char s[MAX_STRING] ) /* Flawfinder: ignore */ 154std::string terse_F32_to_string( F32 f )
153{ 155{
154 char* r = s; 156 std::string r = llformat( "%.2f", f );
155 S32 len = snprintf( s, MAX_STRING, "%.2f", f ); /* Flawfinder: ignore */
156 157
157 // "1.20" -> "1.2" 158 // "1.20" -> "1.2"
158 // "24.00" -> "24." 159 // "24.00" -> "24."
159 while( '0' == r[len - 1] ) 160 S32 len = r.length();
161 while( len > 0 && '0' == r[len - 1] )
160 { 162 {
161 len--; 163 r.erase(len-1, 1);
162 r[len] = '\0'; 164 len--;
163 } 165 }
164 166
165 if( '.' == r[len - 1] ) 167 if( '.' == r[len - 1] )
166 { 168 {
167 // "24." -> "24" 169 // "24." -> "24"
168 len--; 170 r.erase(len-1, 1);
169 r[len] = '\0';
170 } 171 }
171 else 172 else
172 if( ('-' == r[0]) && ('0' == r[1]) ) 173 if( ('-' == r[0]) && ('0' == r[1]) )
173 { 174 {
174 // "-0.59" -> "-.59" 175 // "-0.59" -> "-.59"
175 r++; 176 r.erase(1, 1);
176 r[0] = '-';
177 } 177 }
178 else 178 else
179 if( '0' == r[0] ) 179 if( '0' == r[0] )
180 { 180 {
181 // "0.59" -> ".59" 181 // "0.59" -> ".59"
182 r++; 182 r.erase(0, 1);
183 } 183 }
184 184
185 return r; 185 return r;
@@ -231,13 +231,12 @@ BOOL LLWearable::exportFile( LLFILE* file )
231 return FALSE; 231 return FALSE;
232 } 232 }
233 233
234 char s[ MAX_STRING ]; /* Flawfinder: ignore */
235 for (param_map_t::iterator iter = mVisualParamMap.begin(); 234 for (param_map_t::iterator iter = mVisualParamMap.begin();
236 iter != mVisualParamMap.end(); ++iter) 235 iter != mVisualParamMap.end(); ++iter)
237 { 236 {
238 S32 param_id = iter->first; 237 S32 param_id = iter->first;
239 F32 param_weight = iter->second; 238 F32 param_weight = iter->second;
240 if( fprintf( file, "%d %s\n", param_id, terse_F32_to_string( param_weight, s ) ) < 0 ) 239 if( fprintf( file, "%d %s\n", param_id, terse_F32_to_string( param_weight ).c_str() ) < 0 )
241 { 240 {
242 return FALSE; 241 return FALSE;
243 } 242 }
@@ -311,7 +310,7 @@ BOOL LLWearable::importFile( LLFILE* file )
311 return FALSE; 310 return FALSE;
312 } 311 }
313 mName = text_buffer; 312 mName = text_buffer;
314 LLString::truncate(mName, DB_INV_ITEM_NAME_STR_LEN ); 313 LLStringUtil::truncate(mName, DB_INV_ITEM_NAME_STR_LEN );
315 } 314 }
316 315
317 // description 316 // description
@@ -334,7 +333,7 @@ BOOL LLWearable::importFile( LLFILE* file )
334 return FALSE; 333 return FALSE;
335 } 334 }
336 mDescription = text_buffer; 335 mDescription = text_buffer;
337 LLString::truncate(mDescription, DB_INV_ITEM_DESC_STR_LEN ); 336 LLStringUtil::truncate(mDescription, DB_INV_ITEM_DESC_STR_LEN );
338 } 337 }
339 338
340 // permissions 339 // permissions
@@ -848,10 +847,10 @@ void LLWearable::saveNewAsset()
848// llinfos << "LLWearable::saveNewAsset() type: " << getTypeName() << llendl; 847// llinfos << "LLWearable::saveNewAsset() type: " << getTypeName() << llendl;
849 //llinfos << *this << llendl; 848 //llinfos << *this << llendl;
850 849
851 char new_asset_id_string[UUID_STR_LENGTH]; /* Flawfinder: ignore */ 850 std::string new_asset_id_string;
852 mAssetID.toString(new_asset_id_string); 851 mAssetID.toString(new_asset_id_string);
853 char filename[LL_MAX_PATH]; /* Flawfinder: ignore */ 852 std::string filename;
854 snprintf(filename, LL_MAX_PATH, "%s.wbl", gDirUtilp->getExpandedFilename(LL_PATH_CACHE,new_asset_id_string).c_str()); /* Flawfinder: ignore */ 853 filename = gDirUtilp->getExpandedFilename(LL_PATH_CACHE,new_asset_id_string) + ".wbl";
855 LLFILE* fp = LLFile::fopen(filename, "wb"); /* Flawfinder: ignore */ 854 LLFILE* fp = LLFile::fopen(filename, "wb"); /* Flawfinder: ignore */
856 BOOL successful_save = FALSE; 855 BOOL successful_save = FALSE;
857 if(fp && exportFile(fp)) 856 if(fp && exportFile(fp))
@@ -865,14 +864,10 @@ void LLWearable::saveNewAsset()
865 } 864 }
866 if(!successful_save) 865 if(!successful_save)
867 { 866 {
868 char buffer[2*MAX_STRING]; /* Flawfinder: ignore */ 867 std::string buffer = llformat("Unable to save '%s' to wearable file.", mName.c_str());
869 snprintf(buffer, /* Flawfinder: ignore */
870 sizeof(buffer),
871 "Unable to save '%s' to wearable file.",
872 mName.c_str());
873 llwarns << buffer << llendl; 868 llwarns << buffer << llendl;
874 869
875 LLStringBase<char>::format_map_t args; 870 LLStringUtil::format_map_t args;
876 args["[NAME]"] = mName; 871 args["[NAME]"] = mName;
877 gViewerWindow->alertXml("CannotSaveWearableOutOfSpace", args); 872 gViewerWindow->alertXml("CannotSaveWearableOutOfSpace", args);
878 return; 873 return;
@@ -910,7 +905,7 @@ void LLWearable::saveNewAsset()
910void LLWearable::onSaveNewAssetComplete(const LLUUID& new_asset_id, void* userdata, S32 status, LLExtStat ext_status) // StoreAssetData callback (fixed) 905void LLWearable::onSaveNewAssetComplete(const LLUUID& new_asset_id, void* userdata, S32 status, LLExtStat ext_status) // StoreAssetData callback (fixed)
911{ 906{
912 LLWearableSaveData* data = (LLWearableSaveData*)userdata; 907 LLWearableSaveData* data = (LLWearableSaveData*)userdata;
913 const char* type_name = LLWearable::typeToTypeName(data->mType); 908 const std::string& type_name = LLWearable::typeToTypeName(data->mType);
914 if(0 == status) 909 if(0 == status)
915 { 910 {
916 // Success 911 // Success
@@ -918,22 +913,18 @@ void LLWearable::onSaveNewAssetComplete(const LLUUID& new_asset_id, void* userda
918 } 913 }
919 else 914 else
920 { 915 {
921 char buffer[2*MAX_STRING]; /* Flawfinder: ignore */ 916 std::string buffer = llformat("Unable to save %s to central asset store.", type_name.c_str());
922 snprintf(buffer, /* Flawfinder: ignore */
923 sizeof(buffer),
924 "Unable to save %s to central asset store.",
925 type_name);
926 llwarns << buffer << " Status: " << status << llendl; 917 llwarns << buffer << " Status: " << status << llendl;
927 LLStringBase<char>::format_map_t args; 918 LLStringUtil::format_map_t args;
928 args["[NAME]"] = type_name; 919 args["[NAME]"] = type_name;
929 gViewerWindow->alertXml("CannotSaveToAssetStore", args); 920 gViewerWindow->alertXml("CannotSaveToAssetStore", args);
930 } 921 }
931 922
932 // Delete temp file 923 // Delete temp file
933 char new_asset_id_string[UUID_STR_LENGTH]; /* Flawfinder: ignore */ 924 std::string new_asset_id_string;
934 new_asset_id.toString(new_asset_id_string); 925 new_asset_id.toString(new_asset_id_string);
935 char src_filename[LL_MAX_PATH]; /* Flawfinder: ignore */ 926 std::string src_filename;
936 snprintf(src_filename, LL_MAX_PATH, "%s.wbl", gDirUtilp->getExpandedFilename(LL_PATH_CACHE,new_asset_id_string).c_str()); /* Flawfinder: ignore */ 927 src_filename = gDirUtilp->getExpandedFilename(LL_PATH_CACHE,new_asset_id_string) + ".wbl";
937 LLFile::remove(src_filename); 928 LLFile::remove(src_filename);
938 929
939 // delete the context data 930 // delete the context data