aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llviewermenufile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/newview/llviewermenufile.cpp')
-rw-r--r--linden/indra/newview/llviewermenufile.cpp278
1 files changed, 155 insertions, 123 deletions
diff --git a/linden/indra/newview/llviewermenufile.cpp b/linden/indra/newview/llviewermenufile.cpp
index 6f2d8e2..5dd760e 100644
--- a/linden/indra/newview/llviewermenufile.cpp
+++ b/linden/indra/newview/llviewermenufile.cpp
@@ -92,6 +92,47 @@ class LLFileEnableUpload : public view_listener_t
92 } 92 }
93}; 93};
94 94
95//============================================================================
96
97#if LL_WINDOWS
98static std::string SOUND_EXTENSIONS = "wav";
99static std::string IMAGE_EXTENSIONS = "tga bmp jpg jpeg png";
100static std::string ANIM_EXTENSIONS = "bvh";
101#ifdef _CORY_TESTING
102static std::string GEOMETRY_EXTENSIONS = "slg";
103#endif
104static std::string XML_EXTENSIONS = "xml";
105static std::string SLOBJECT_EXTENSIONS = "slobject";
106#endif
107static std::string ALL_FILE_EXTENSIONS = "*.*";
108
109std::string build_extensions_string(LLFilePicker::ELoadFilter filter)
110{
111 switch(filter)
112 {
113#if LL_WINDOWS
114 case LLFilePicker::FFLOAD_IMAGE:
115 return IMAGE_EXTENSIONS;
116 case LLFilePicker::FFLOAD_WAV:
117 return SOUND_EXTENSIONS;
118 case LLFilePicker::FFLOAD_ANIM:
119 return ANIM_EXTENSIONS;
120 case LLFilePicker::FFLOAD_SLOBJECT:
121 return SLOBJECT_EXTENSIONS;
122#ifdef _CORY_TESTING
123 case LLFilePicker::FFLOAD_GEOMETRY:
124 return GEOMETRY_EXTENSIONS;
125#endif
126 case LLFilePicker::FFLOAD_XML:
127 return XML_EXTENSIONS;
128 case LLFilePicker::FFLOAD_ALL:
129 return ALL_FILE_EXTENSIONS;
130#endif
131 default:
132 return ALL_FILE_EXTENSIONS;
133 }
134}
135
95/** 136/**
96 char* upload_pick(void* data) 137 char* upload_pick(void* data)
97 138
@@ -100,7 +141,7 @@ class LLFileEnableUpload : public view_listener_t
100 returns the string to the full path filename, else returns NULL. 141 returns the string to the full path filename, else returns NULL.
101 Data is the load filter for the type of file as defined in LLFilePicker. 142 Data is the load filter for the type of file as defined in LLFilePicker.
102**/ 143**/
103const char* upload_pick(void* data) 144const std::string upload_pick(void* data)
104{ 145{
105 if( gAgent.cameraMouselook() ) 146 if( gAgent.cameraMouselook() )
106 { 147 {
@@ -123,23 +164,23 @@ const char* upload_pick(void* data)
123 if (!picker.getOpenFile(type)) 164 if (!picker.getOpenFile(type))
124 { 165 {
125 llinfos << "Couldn't import objects from file" << llendl; 166 llinfos << "Couldn't import objects from file" << llendl;
126 return NULL; 167 return std::string();
127 } 168 }
128 169
129 const char* filename = picker.getFirstFile(); 170
130 const char* ext = strrchr(filename, '.'); 171 const std::string& filename = picker.getFirstFile();
172 std::string ext = gDirUtilp->getExtension(filename);
131 173
132 //strincmp doesn't like NULL pointers 174 //strincmp doesn't like NULL pointers
133 if (ext == NULL) 175 if (ext.empty())
134 { 176 {
135 const char* short_name = strrchr(filename, 177 std::string short_name = gDirUtilp->getBaseFileName(filename);
136 *gDirUtilp->getDirDelimiter().c_str());
137 178
138 // No extension 179 // No extension
139 LLStringBase<char>::format_map_t args; 180 LLStringUtil::format_map_t args;
140 args["[FILE]"] = LLString(short_name + 1); 181 args["[FILE]"] = short_name;
141 gViewerWindow->alertXml("NoFileExtension", args); 182 gViewerWindow->alertXml("NoFileExtension", args);
142 return NULL; 183 return std::string();
143 } 184 }
144 else 185 else
145 { 186 {
@@ -148,8 +189,7 @@ const char* upload_pick(void* data)
148 //if the extension is valid 189 //if the extension is valid
149 190
150 //now grab the set of valid file extensions 191 //now grab the set of valid file extensions
151 const char* valids = build_extensions_string(type); 192 std::string valid_extensions = build_extensions_string(type);
152 std::string valid_extensions = std::string(valids);
153 193
154 BOOL ext_valid = FALSE; 194 BOOL ext_valid = FALSE;
155 195
@@ -165,10 +205,9 @@ const char* upload_pick(void* data)
165 token_iter != tokens.end() && ext_valid != TRUE; 205 token_iter != tokens.end() && ext_valid != TRUE;
166 ++token_iter) 206 ++token_iter)
167 { 207 {
168 const char* cur_token = token_iter->c_str(); 208 const std::string& cur_token = *token_iter;
169 209
170 if (0 == strnicmp(cur_token, ext, strlen(cur_token)) || /* Flawfinder: ignore */ 210 if (cur_token == ext || cur_token == "*.*")
171 0 == strnicmp(cur_token, "*.*", strlen(cur_token))) /* Flawfinder: ignore */
172 { 211 {
173 //valid extension 212 //valid extension
174 //or the acceptable extension is any 213 //or the acceptable extension is any
@@ -180,11 +219,11 @@ const char* upload_pick(void* data)
180 { 219 {
181 //should only get here if the extension exists 220 //should only get here if the extension exists
182 //but is invalid 221 //but is invalid
183 LLStringBase<char>::format_map_t args; 222 LLStringUtil::format_map_t args;
184 args["[EXTENSION]"] = ext; 223 args["[EXTENSION]"] = ext;
185 args["[VALIDS]"] = valids; 224 args["[VALIDS]"] = valid_extensions;
186 gViewerWindow->alertXml("InvalidFileExtension", args); 225 gViewerWindow->alertXml("InvalidFileExtension", args);
187 return NULL; 226 return std::string();
188 } 227 }
189 }//end else (non-null extension) 228 }//end else (non-null extension)
190 229
@@ -195,14 +234,14 @@ const char* upload_pick(void* data)
195 if (type == LLFilePicker::FFLOAD_WAV) 234 if (type == LLFilePicker::FFLOAD_WAV)
196 { 235 {
197 // pre-qualify wavs to make sure the format is acceptable 236 // pre-qualify wavs to make sure the format is acceptable
198 char error_msg[MAX_STRING]; /* Flawfinder: ignore */ 237 std::string error_msg;
199 if (check_for_invalid_wav_formats(filename,error_msg)) 238 if (check_for_invalid_wav_formats(filename,error_msg))
200 { 239 {
201 llinfos << error_msg << ": " << filename << llendl; 240 llinfos << error_msg << ": " << filename << llendl;
202 LLStringBase<char>::format_map_t args; 241 LLStringUtil::format_map_t args;
203 args["[FILE]"] = filename; 242 args["[FILE]"] = filename;
204 gViewerWindow->alertXml( error_msg, args ); 243 gViewerWindow->alertXml( error_msg, args );
205 return NULL; 244 return std::string();
206 } 245 }
207 }//end if a wave/sound file 246 }//end if a wave/sound file
208 247
@@ -214,8 +253,8 @@ class LLFileUploadImage : public view_listener_t
214{ 253{
215 bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata) 254 bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
216 { 255 {
217 const char* filename = upload_pick((void *)LLFilePicker::FFLOAD_IMAGE); 256 std::string filename = upload_pick((void *)LLFilePicker::FFLOAD_IMAGE);
218 if (filename) 257 if (!filename.empty())
219 { 258 {
220 LLFloaterImagePreview* floaterp = new LLFloaterImagePreview(filename); 259 LLFloaterImagePreview* floaterp = new LLFloaterImagePreview(filename);
221 LLUICtrlFactory::getInstance()->buildFloater(floaterp, "floater_image_preview.xml"); 260 LLUICtrlFactory::getInstance()->buildFloater(floaterp, "floater_image_preview.xml");
@@ -228,8 +267,8 @@ class LLFileUploadSound : public view_listener_t
228{ 267{
229 bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata) 268 bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
230 { 269 {
231 const char* filename = upload_pick((void*)LLFilePicker::FFLOAD_WAV); 270 std::string filename = upload_pick((void*)LLFilePicker::FFLOAD_WAV);
232 if (filename) 271 if (!filename.empty())
233 { 272 {
234 LLFloaterNameDesc* floaterp = new LLFloaterNameDesc(filename); 273 LLFloaterNameDesc* floaterp = new LLFloaterNameDesc(filename);
235 LLUICtrlFactory::getInstance()->buildFloater(floaterp, "floater_sound_preview.xml"); 274 LLUICtrlFactory::getInstance()->buildFloater(floaterp, "floater_sound_preview.xml");
@@ -242,8 +281,8 @@ class LLFileUploadAnim : public view_listener_t
242{ 281{
243 bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata) 282 bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
244 { 283 {
245 const char* filename = upload_pick((void*)LLFilePicker::FFLOAD_ANIM); 284 const std::string filename = upload_pick((void*)LLFilePicker::FFLOAD_ANIM);
246 if (filename) 285 if (!filename.empty())
247 { 286 {
248 LLFloaterAnimPreview* floaterp = new LLFloaterAnimPreview(filename); 287 LLFloaterAnimPreview* floaterp = new LLFloaterAnimPreview(filename);
249 LLUICtrlFactory::getInstance()->buildFloater(floaterp, "floater_animation_preview.xml"); 288 LLUICtrlFactory::getInstance()->buildFloater(floaterp, "floater_animation_preview.xml");
@@ -274,27 +313,18 @@ class LLFileUploadBulk : public view_listener_t
274 LLFilePicker& picker = LLFilePicker::instance(); 313 LLFilePicker& picker = LLFilePicker::instance();
275 if (picker.getMultipleOpenFiles()) 314 if (picker.getMultipleOpenFiles())
276 { 315 {
277 const char* filename = picker.getFirstFile(); 316 const std::string& filename = picker.getFirstFile();
278 const char* name = picker.getDirname(); 317 std::string name = gDirUtilp->getBaseFileName(filename, true);
279 318
280 LLString asset_name = name; 319 std::string asset_name = name;
281 LLString::replaceNonstandardASCII( asset_name, '?' ); 320 LLStringUtil::replaceNonstandardASCII( asset_name, '?' );
282 LLString::replaceChar(asset_name, '|', '?'); 321 LLStringUtil::replaceChar(asset_name, '|', '?');
283 LLString::stripNonprintable(asset_name); 322 LLStringUtil::stripNonprintable(asset_name);
284 LLString::trim(asset_name); 323 LLStringUtil::trim(asset_name);
285 324
286 char* asset_name_str = (char*)asset_name.c_str();
287 char* end_p = strrchr(asset_name_str, '.'); // strip extension if exists
288 if( !end_p )
289 {
290 end_p = asset_name_str + strlen( asset_name_str ); /* Flawfinder: ignore */
291 }
292
293 S32 len = llmin( (S32) (DB_INV_ITEM_NAME_STR_LEN), (S32) (end_p - asset_name_str) );
294
295 asset_name = asset_name.substr( 0, len );
296
297 upload_new_resource(filename, asset_name, asset_name, 0, LLAssetType::AT_NONE, LLInventoryType::IT_NONE); // file 325 upload_new_resource(filename, asset_name, asset_name, 0, LLAssetType::AT_NONE, LLInventoryType::IT_NONE); // file
326 // *NOTE: Ew, we don't iterate over the file list here,
327 // we handle the next files in upload_done_callback()
298 } 328 }
299 else 329 else
300 { 330 {
@@ -304,11 +334,11 @@ class LLFileUploadBulk : public view_listener_t
304 } 334 }
305}; 335};
306 336
307void upload_error(const char* error_message, const char* label, const std::string filename, const LLStringBase<char>::format_map_t args) 337void upload_error(const std::string& error_message, const std::string& label, const std::string& filename, const LLStringUtil::format_map_t args)
308{ 338{
309 llwarns << error_message << llendl; 339 llwarns << error_message << llendl;
310 gViewerWindow->alertXml(label, args); 340 gViewerWindow->alertXml(label, args);
311 if(remove(filename.c_str()) == -1) 341 if(LLFile::remove(filename) == -1)
312 { 342 {
313 lldebugs << "unable to remove temp file" << llendl; 343 lldebugs << "unable to remove temp file" << llendl;
314 } 344 }
@@ -403,9 +433,29 @@ class LLFileTakeSnapshotToDisk : public view_listener_t
403 FALSE)) 433 FALSE))
404 { 434 {
405 gViewerWindow->playSnapshotAnimAndSound(); 435 gViewerWindow->playSnapshotAnimAndSound();
436
406 LLImageBase::setSizeOverride(TRUE); 437 LLImageBase::setSizeOverride(TRUE);
407 gViewerWindow->saveImageNumbered(raw); 438 LLPointer<LLImageFormatted> formatted;
439 switch(LLFloaterSnapshot::ESnapshotFormat(gSavedSettings.getS32("SnapshotFormat")))
440 {
441 case LLFloaterSnapshot::SNAPSHOT_FORMAT_JPEG:
442 formatted = new LLImageJPEG(gSavedSettings.getS32("SnapshotQuality"));
443 break;
444 case LLFloaterSnapshot::SNAPSHOT_FORMAT_PNG:
445 formatted = new LLImagePNG;
446 break;
447 case LLFloaterSnapshot::SNAPSHOT_FORMAT_BMP:
448 formatted = new LLImageBMP;
449 break;
450 default:
451 llwarns << "Unknown Local Snapshot format" << llendl;
452 LLImageBase::setSizeOverride(FALSE);
453 return true;
454 }
455
456 formatted->encode(raw, 0);
408 LLImageBase::setSizeOverride(FALSE); 457 LLImageBase::setSizeOverride(FALSE);
458 gViewerWindow->saveImageNumbered(formatted);
409 } 459 }
410 return true; 460 return true;
411 } 461 }
@@ -422,8 +472,8 @@ class LLFileQuit : public view_listener_t
422 472
423void handle_upload(void* data) 473void handle_upload(void* data)
424{ 474{
425 const char* filename = upload_pick(data); 475 const std::string filename = upload_pick(data);
426 if (filename) 476 if (!filename.empty())
427 { 477 {
428 LLFloaterNameDesc* floaterp = new LLFloaterNameDesc(filename); 478 LLFloaterNameDesc* floaterp = new LLFloaterNameDesc(filename);
429 LLUICtrlFactory::getInstance()->buildFloater(floaterp, "floater_name_description.xml"); 479 LLUICtrlFactory::getInstance()->buildFloater(floaterp, "floater_name_description.xml");
@@ -435,10 +485,9 @@ void handle_compress_image(void*)
435 LLFilePicker& picker = LLFilePicker::instance(); 485 LLFilePicker& picker = LLFilePicker::instance();
436 if (picker.getMultipleOpenFiles(LLFilePicker::FFLOAD_IMAGE)) 486 if (picker.getMultipleOpenFiles(LLFilePicker::FFLOAD_IMAGE))
437 { 487 {
438 const char* input_file = picker.getFirstFile(); 488 std::string infile = picker.getFirstFile();
439 while (input_file) 489 while (!infile.empty())
440 { 490 {
441 std::string infile(input_file);
442 std::string outfile = infile + ".j2c"; 491 std::string outfile = infile + ".j2c";
443 492
444 llinfos << "Input: " << infile << llendl; 493 llinfos << "Input: " << infile << llendl;
@@ -457,59 +506,54 @@ void handle_compress_image(void*)
457 llinfos << "Compression failed: " << LLImageBase::getLastError() << llendl; 506 llinfos << "Compression failed: " << LLImageBase::getLastError() << llendl;
458 } 507 }
459 508
460 input_file = picker.getNextFile(); 509 infile = picker.getNextFile();
461 } 510 }
462 } 511 }
463} 512}
464 513
465void upload_new_resource(const LLString& src_filename, std::string name, 514void upload_new_resource(const std::string& src_filename, std::string name,
466 std::string desc, S32 compression_info, 515 std::string desc, S32 compression_info,
467 LLAssetType::EType destination_folder_type, 516 LLAssetType::EType destination_folder_type,
468 LLInventoryType::EType inv_type, 517 LLInventoryType::EType inv_type,
469 U32 next_owner_perm, 518 U32 next_owner_perm,
470 const LLString& display_name, 519 const std::string& display_name,
471 LLAssetStorage::LLStoreAssetCallback callback, 520 LLAssetStorage::LLStoreAssetCallback callback,
472 void *userdata) 521 void *userdata)
473{ 522{
474 // Generate the temporary UUID. 523 // Generate the temporary UUID.
475 LLString filename = gDirUtilp->getTempFilename(); 524 std::string filename = gDirUtilp->getTempFilename();
476 LLTransactionID tid; 525 LLTransactionID tid;
477 LLAssetID uuid; 526 LLAssetID uuid;
478 527
479 LLStringBase<char>::format_map_t args; 528 LLStringUtil::format_map_t args;
529
530 std::string exten = gDirUtilp->getExtension(src_filename);
480 531
481 LLString ext = src_filename.substr(src_filename.find_last_of('.'));
482 LLAssetType::EType asset_type = LLAssetType::AT_NONE; 532 LLAssetType::EType asset_type = LLAssetType::AT_NONE;
483 char error_message[MAX_STRING]; /* Flawfinder: ignore */ 533 std::string error_message;
484 error_message[0] = '\0';
485 LLString temp_str;
486 534
487 BOOL error = FALSE; 535 BOOL error = FALSE;
488 536
489 if (ext.empty()) 537 if (exten.empty())
490 { 538 {
491 LLString::size_type offset = filename.find_last_of(gDirUtilp->getDirDelimiter()); 539 std::string short_name = gDirUtilp->getBaseFileName(filename);
492 if (offset != LLString::npos)
493 offset++;
494 LLString short_name = filename.substr(offset);
495 540
496 // No extension 541 // No extension
497 snprintf(error_message, /* Flawfinder: ignore */ 542 error_message = llformat(
498 MAX_STRING,
499 "No file extension for the file: '%s'\nPlease make sure the file has a correct file extension", 543 "No file extension for the file: '%s'\nPlease make sure the file has a correct file extension",
500 short_name.c_str()); 544 short_name.c_str());
501 args["[FILE]"] = short_name; 545 args["[FILE]"] = short_name;
502 upload_error(error_message, "NofileExtension", filename, args); 546 upload_error(error_message, "NofileExtension", filename, args);
503 return; 547 return;
504 } 548 }
505 else if( LLString::compareInsensitive(ext.c_str(),".bmp") == 0 ) 549 else if( exten == "bmp")
506 { 550 {
507 asset_type = LLAssetType::AT_TEXTURE; 551 asset_type = LLAssetType::AT_TEXTURE;
508 if (!LLViewerImageList::createUploadFile(src_filename, 552 if (!LLViewerImageList::createUploadFile(src_filename,
509 filename, 553 filename,
510 IMG_CODEC_BMP )) 554 IMG_CODEC_BMP ))
511 { 555 {
512 snprintf(error_message, MAX_STRING, "Problem with file %s:\n\n%s\n", /* Flawfinder: ignore */ 556 error_message = llformat( "Problem with file %s:\n\n%s\n",
513 src_filename.c_str(), LLImageBase::getLastError().c_str()); 557 src_filename.c_str(), LLImageBase::getLastError().c_str());
514 args["[FILE]"] = src_filename; 558 args["[FILE]"] = src_filename;
515 args["[ERROR]"] = LLImageBase::getLastError(); 559 args["[ERROR]"] = LLImageBase::getLastError();
@@ -517,14 +561,14 @@ void upload_new_resource(const LLString& src_filename, std::string name,
517 return; 561 return;
518 } 562 }
519 } 563 }
520 else if( LLString::compareInsensitive(ext.c_str(),".tga") == 0 ) 564 else if( exten == "tga")
521 { 565 {
522 asset_type = LLAssetType::AT_TEXTURE; 566 asset_type = LLAssetType::AT_TEXTURE;
523 if (!LLViewerImageList::createUploadFile(src_filename, 567 if (!LLViewerImageList::createUploadFile(src_filename,
524 filename, 568 filename,
525 IMG_CODEC_TGA )) 569 IMG_CODEC_TGA ))
526 { 570 {
527 snprintf(error_message, MAX_STRING, "Problem with file %s:\n\n%s\n", /* Flawfinder: ignore */ 571 error_message = llformat("Problem with file %s:\n\n%s\n",
528 src_filename.c_str(), LLImageBase::getLastError().c_str()); 572 src_filename.c_str(), LLImageBase::getLastError().c_str());
529 args["[FILE]"] = src_filename; 573 args["[FILE]"] = src_filename;
530 args["[ERROR]"] = LLImageBase::getLastError(); 574 args["[ERROR]"] = LLImageBase::getLastError();
@@ -532,14 +576,14 @@ void upload_new_resource(const LLString& src_filename, std::string name,
532 return; 576 return;
533 } 577 }
534 } 578 }
535 else if( LLString::compareInsensitive(ext.c_str(),".jpg") == 0 || LLString::compareInsensitive(ext.c_str(),".jpeg") == 0) 579 else if( exten == "jpg" || exten == "jpeg")
536 { 580 {
537 asset_type = LLAssetType::AT_TEXTURE; 581 asset_type = LLAssetType::AT_TEXTURE;
538 if (!LLViewerImageList::createUploadFile(src_filename, 582 if (!LLViewerImageList::createUploadFile(src_filename,
539 filename, 583 filename,
540 IMG_CODEC_JPEG )) 584 IMG_CODEC_JPEG ))
541 { 585 {
542 snprintf(error_message, MAX_STRING, "Problem with file %s:\n\n%s\n", /* Flawfinder: ignore */ 586 error_message = llformat("Problem with file %s:\n\n%s\n",
543 src_filename.c_str(), LLImageBase::getLastError().c_str()); 587 src_filename.c_str(), LLImageBase::getLastError().c_str());
544 args["[FILE]"] = src_filename; 588 args["[FILE]"] = src_filename;
545 args["[ERROR]"] = LLImageBase::getLastError(); 589 args["[ERROR]"] = LLImageBase::getLastError();
@@ -547,14 +591,14 @@ void upload_new_resource(const LLString& src_filename, std::string name,
547 return; 591 return;
548 } 592 }
549 } 593 }
550 else if( LLString::compareInsensitive(ext.c_str(),".png") == 0 ) 594 else if( exten == "png")
551 { 595 {
552 asset_type = LLAssetType::AT_TEXTURE; 596 asset_type = LLAssetType::AT_TEXTURE;
553 if (!LLViewerImageList::createUploadFile(src_filename, 597 if (!LLViewerImageList::createUploadFile(src_filename,
554 filename, 598 filename,
555 IMG_CODEC_PNG )) 599 IMG_CODEC_PNG ))
556 { 600 {
557 sprintf(error_message, "Problem with file %s:\n\n%s\n", 601 error_message = llformat("Problem with file %s:\n\n%s\n",
558 src_filename.c_str(), LLImageBase::getLastError().c_str()); 602 src_filename.c_str(), LLImageBase::getLastError().c_str());
559 args["[FILE]"] = src_filename; 603 args["[FILE]"] = src_filename;
560 args["[ERROR]"] = LLImageBase::getLastError(); 604 args["[ERROR]"] = LLImageBase::getLastError();
@@ -562,27 +606,27 @@ void upload_new_resource(const LLString& src_filename, std::string name,
562 return; 606 return;
563 } 607 }
564 } 608 }
565 else if(LLString::compareInsensitive(ext.c_str(),".wav") == 0) 609 else if(exten == "wav")
566 { 610 {
567 asset_type = LLAssetType::AT_SOUND; // tag it as audio 611 asset_type = LLAssetType::AT_SOUND; // tag it as audio
568 S32 encode_result = 0; 612 S32 encode_result = 0;
569 613
570 llinfos << "Attempting to encode wav as an ogg file" << llendl; 614 llinfos << "Attempting to encode wav as an ogg file" << llendl;
571 615
572 encode_result = encode_vorbis_file(src_filename.c_str(), filename.c_str()); 616 encode_result = encode_vorbis_file(src_filename, filename);
573 617
574 if (LLVORBISENC_NOERR != encode_result) 618 if (LLVORBISENC_NOERR != encode_result)
575 { 619 {
576 switch(encode_result) 620 switch(encode_result)
577 { 621 {
578 case LLVORBISENC_DEST_OPEN_ERR: 622 case LLVORBISENC_DEST_OPEN_ERR:
579 snprintf(error_message, MAX_STRING, "Couldn't open temporary compressed sound file for writing: %s\n", filename.c_str()); /* Flawfinder: ignore */ 623 error_message = llformat( "Couldn't open temporary compressed sound file for writing: %s\n", filename.c_str());
580 args["[FILE]"] = filename; 624 args["[FILE]"] = filename;
581 upload_error(error_message, "CannotOpenTemporarySoundFile", filename, args); 625 upload_error(error_message, "CannotOpenTemporarySoundFile", filename, args);
582 break; 626 break;
583 627
584 default: 628 default:
585 snprintf(error_message, MAX_STRING, "Unknown vorbis encode failure on: %s\n", src_filename.c_str()); /* Flawfinder: ignore */ 629 error_message = llformat("Unknown vorbis encode failure on: %s\n", src_filename.c_str());
586 args["[FILE]"] = src_filename; 630 args["[FILE]"] = src_filename;
587 upload_error(error_message, "UnknownVorbisEncodeFailure", filename, args); 631 upload_error(error_message, "UnknownVorbisEncodeFailure", filename, args);
588 break; 632 break;
@@ -590,11 +634,11 @@ void upload_new_resource(const LLString& src_filename, std::string name,
590 return; 634 return;
591 } 635 }
592 } 636 }
593 else if(LLString::compareInsensitive(ext.c_str(),".tmp") == 0) 637 else if(exten == "tmp")
594 { 638 {
595 // This is a generic .lin resource file 639 // This is a generic .lin resource file
596 asset_type = LLAssetType::AT_OBJECT; 640 asset_type = LLAssetType::AT_OBJECT;
597 LLFILE* in = LLFile::fopen(src_filename.c_str(), "rb"); /* Flawfinder: ignore */ 641 LLFILE* in = LLFile::fopen(src_filename, "rb"); /* Flawfinder: ignore */
598 if (in) 642 if (in)
599 { 643 {
600 // read in the file header 644 // read in the file header
@@ -624,7 +668,7 @@ void upload_new_resource(const LLString& src_filename, std::string name,
624 if (EOF == tokens_read) 668 if (EOF == tokens_read)
625 { 669 {
626 fclose(in); 670 fclose(in);
627 snprintf(error_message, MAX_STRING, "corrupt resource file: %s", src_filename.c_str()); /* Flawfinder: ignore */ 671 error_message = llformat("corrupt resource file: %s", src_filename.c_str());
628 args["[FILE]"] = src_filename; 672 args["[FILE]"] = src_filename;
629 upload_error(error_message, "CorruptResourceFile", filename, args); 673 upload_error(error_message, "CorruptResourceFile", filename, args);
630 return; 674 return;
@@ -652,7 +696,7 @@ void upload_new_resource(const LLString& src_filename, std::string name,
652 else 696 else
653 { 697 {
654 fclose(in); 698 fclose(in);
655 snprintf(error_message, MAX_STRING, "unknown linden resource file version in file: %s", src_filename.c_str()); /* Flawfinder: ignore */ 699 error_message = llformat("unknown linden resource file version in file: %s", src_filename.c_str());
656 args["[FILE]"] = src_filename; 700 args["[FILE]"] = src_filename;
657 upload_error(error_message, "UnknownResourceFileVersion", filename, args); 701 upload_error(error_message, "UnknownResourceFileVersion", filename, args);
658 return; 702 return;
@@ -679,7 +723,7 @@ void upload_new_resource(const LLString& src_filename, std::string name,
679 } 723 }
680 724
681 // copy the file's data segment into another file for uploading 725 // copy the file's data segment into another file for uploading
682 LLFILE* out = LLFile::fopen(filename.c_str(), "wb"); /* Flawfinder: ignore */ 726 LLFILE* out = LLFile::fopen(filename, "wb"); /* Flawfinder: ignore */
683 if (out) 727 if (out)
684 { 728 {
685 while((read = fread(buf, 1, 16384, in))) /* Flawfinder: ignore */ 729 while((read = fread(buf, 1, 16384, in))) /* Flawfinder: ignore */
@@ -694,7 +738,7 @@ void upload_new_resource(const LLString& src_filename, std::string name,
694 else 738 else
695 { 739 {
696 fclose(in); 740 fclose(in);
697 snprintf(error_message, MAX_STRING, "Unable to create output file: %s", filename.c_str()); /* Flawfinder: ignore */ 741 error_message = llformat( "Unable to create output file: %s", filename.c_str());
698 args["[FILE]"] = filename; 742 args["[FILE]"] = filename;
699 upload_error(error_message, "UnableToCreateOutputFile", filename, args); 743 upload_error(error_message, "UnableToCreateOutputFile", filename, args);
700 return; 744 return;
@@ -707,16 +751,17 @@ void upload_new_resource(const LLString& src_filename, std::string name,
707 llinfos << "Couldn't open .lin file " << src_filename << llendl; 751 llinfos << "Couldn't open .lin file " << src_filename << llendl;
708 } 752 }
709 } 753 }
710 else if (LLString::compareInsensitive(ext.c_str(),".bvh") == 0) 754 else if (exten == "bvh")
711 { 755 {
712 snprintf(error_message, MAX_STRING, "We do not currently support bulk upload of animation files\n"); /* Flawfinder: ignore */ 756 error_message = llformat("We do not currently support bulk upload of animation files\n");
713 upload_error(error_message, "DoNotSupportBulkAnimationUpload", filename, args); 757 upload_error(error_message, "DoNotSupportBulkAnimationUpload", filename, args);
714 return; 758 return;
715 } 759 }
716 else 760 else
717 { 761 {
718 // Unknown extension 762 // Unknown extension
719 snprintf(error_message, MAX_STRING, "Unknown file extension %s\nExpected .wav, .tga, .bmp, .jpg, .jpeg, or .bvh", ext.c_str()); /* Flawfinder: ignore */ 763 // *TODO: Translate?
764 error_message = llformat("Unknown file extension .%s\nExpected .wav, .tga, .bmp, .jpg, .jpeg, or .bvh", exten.c_str());
720 error = TRUE;; 765 error = TRUE;;
721 } 766 }
722 767
@@ -745,14 +790,14 @@ void upload_new_resource(const LLString& src_filename, std::string name,
745 } 790 }
746 else 791 else
747 { 792 {
748 snprintf(error_message, MAX_STRING, "Unable to access output file: %s", filename.c_str()); /* Flawfinder: ignore */ 793 error_message = llformat( "Unable to access output file: %s", filename.c_str());
749 error = TRUE; 794 error = TRUE;
750 } 795 }
751 } 796 }
752 797
753 if (!error) 798 if (!error)
754 { 799 {
755 LLString t_disp_name = display_name; 800 std::string t_disp_name = display_name;
756 if (t_disp_name.empty()) 801 if (t_disp_name.empty())
757 { 802 {
758 t_disp_name = src_filename; 803 t_disp_name = src_filename;
@@ -764,10 +809,10 @@ void upload_new_resource(const LLString& src_filename, std::string name,
764 else 809 else
765 { 810 {
766 llwarns << error_message << llendl; 811 llwarns << error_message << llendl;
767 LLStringBase<char>::format_map_t args; 812 LLStringUtil::format_map_t args;
768 args["[ERROR_MESSAGE]"] = error_message; 813 args["[ERROR_MESSAGE]"] = error_message;
769 gViewerWindow->alertXml("ErrorMessage", args); 814 gViewerWindow->alertXml("ErrorMessage", args);
770 if(LLFile::remove(filename.c_str()) == -1) 815 if(LLFile::remove(filename) == -1)
771 { 816 {
772 lldebugs << "unable to remove temp file" << llendl; 817 lldebugs << "unable to remove temp file" << llendl;
773 } 818 }
@@ -796,7 +841,7 @@ void upload_done_callback(const LLUUID& uuid, void* user_data, S32 result, LLExt
796 { 841 {
797 LLFloaterBuyCurrency::buyCurrency( 842 LLFloaterBuyCurrency::buyCurrency(
798 llformat("Uploading %s costs", 843 llformat("Uploading %s costs",
799 data->mAssetInfo.getName().c_str()), 844 data->mAssetInfo.getName().c_str()), // *TODO: Translate
800 upload_cost); 845 upload_cost);
801 is_balance_sufficient = FALSE; 846 is_balance_sufficient = FALSE;
802 } 847 }
@@ -849,9 +894,9 @@ void upload_done_callback(const LLUUID& uuid, void* user_data, S32 result, LLExt
849 } 894 }
850 else // if(result >= 0) 895 else // if(result >= 0)
851 { 896 {
852 LLStringBase<char>::format_map_t args; 897 LLStringUtil::format_map_t args;
853 args["[FILE]"] = LLInventoryType::lookupHumanReadable(data->mInventoryType); 898 args["[FILE]"] = LLInventoryType::lookupHumanReadable(data->mInventoryType);
854 args["[REASON]"] = LLString(LLAssetStorage::getErrorString(result)); 899 args["[REASON]"] = std::string(LLAssetStorage::getErrorString(result));
855 gViewerWindow->alertXml("CannotUploadReason", args); 900 gViewerWindow->alertXml("CannotUploadReason", args);
856 } 901 }
857 902
@@ -861,27 +906,14 @@ void upload_done_callback(const LLUUID& uuid, void* user_data, S32 result, LLExt
861 // *NOTE: This is a pretty big hack. What this does is check the 906 // *NOTE: This is a pretty big hack. What this does is check the
862 // file picker if there are any more pending uploads. If so, 907 // file picker if there are any more pending uploads. If so,
863 // upload that file. 908 // upload that file.
864 const char* next_file = LLFilePicker::instance().getNextFile(); 909 const std::string& next_file = LLFilePicker::instance().getNextFile();
865 if(is_balance_sufficient && next_file) 910 if(is_balance_sufficient && !next_file.empty())
866 { 911 {
867 const char* name = LLFilePicker::instance().getDirname(); 912 std::string asset_name = gDirUtilp->getBaseFileName(next_file, true);
868 913 LLStringUtil::replaceNonstandardASCII( asset_name, '?' );
869 LLString asset_name = name; 914 LLStringUtil::replaceChar(asset_name, '|', '?');
870 LLString::replaceNonstandardASCII( asset_name, '?' ); 915 LLStringUtil::stripNonprintable(asset_name);
871 LLString::replaceChar(asset_name, '|', '?'); 916 LLStringUtil::trim(asset_name);
872 LLString::stripNonprintable(asset_name);
873 LLString::trim(asset_name);
874
875 char* asset_name_str = (char*)asset_name.c_str();
876 char* end_p = strrchr(asset_name_str, '.'); // strip extension if exists
877 if( !end_p )
878 {
879 end_p = asset_name_str + strlen( asset_name_str ); /* Flawfinder: ignore */
880 }
881
882 S32 len = llmin( (S32) (DB_INV_ITEM_NAME_STR_LEN), (S32) (end_p - asset_name_str) );
883
884 asset_name = asset_name.substr( 0, len );
885 917
886 upload_new_resource(next_file, asset_name, asset_name, // file 918 upload_new_resource(next_file, asset_name, asset_name, // file
887 0, LLAssetType::AT_NONE, LLInventoryType::IT_NONE); 919 0, LLAssetType::AT_NONE, LLInventoryType::IT_NONE);
@@ -894,7 +926,7 @@ void upload_new_resource(const LLTransactionID &tid, LLAssetType::EType asset_ty
894 LLAssetType::EType destination_folder_type, 926 LLAssetType::EType destination_folder_type,
895 LLInventoryType::EType inv_type, 927 LLInventoryType::EType inv_type,
896 U32 next_owner_perm, 928 U32 next_owner_perm,
897 const LLString& display_name, 929 const std::string& display_name,
898 LLAssetStorage::LLStoreAssetCallback callback, 930 LLAssetStorage::LLStoreAssetCallback callback,
899 void *userdata) 931 void *userdata)
900{ 932{
@@ -919,8 +951,8 @@ void upload_new_resource(const LLTransactionID &tid, LLAssetType::EType asset_ty
919 { 951 {
920 inv_type = LLInventoryType::defaultForAssetType(asset_type); 952 inv_type = LLInventoryType::defaultForAssetType(asset_type);
921 } 953 }
922 LLString::stripNonprintable(name); 954 LLStringUtil::stripNonprintable(name);
923 LLString::stripNonprintable(desc); 955 LLStringUtil::stripNonprintable(desc);
924 if(name.empty()) 956 if(name.empty())
925 { 957 {
926 name = "(No Name)"; 958 name = "(No Name)";
@@ -931,7 +963,7 @@ void upload_new_resource(const LLTransactionID &tid, LLAssetType::EType asset_ty
931 } 963 }
932 964
933 // At this point, we're ready for the upload. 965 // At this point, we're ready for the upload.
934 LLString upload_message = "Uploading...\n\n"; 966 std::string upload_message = "Uploading...\n\n";
935 upload_message.append(display_name); 967 upload_message.append(display_name);
936 LLUploadDialog::modalUploadDialog(upload_message); 968 LLUploadDialog::modalUploadDialog(upload_message);
937 969