aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llvfs/lldir.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/llvfs/lldir.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 '')
-rw-r--r--linden/indra/llvfs/lldir.cpp112
1 files changed, 86 insertions, 26 deletions
diff --git a/linden/indra/llvfs/lldir.cpp b/linden/indra/llvfs/lldir.cpp
index 246595a..6d6b7aa 100644
--- a/linden/indra/llvfs/lldir.cpp
+++ b/linden/indra/llvfs/lldir.cpp
@@ -59,8 +59,19 @@ LLDir_Linux gDirUtil;
59 59
60LLDir *gDirUtilp = (LLDir *)&gDirUtil; 60LLDir *gDirUtilp = (LLDir *)&gDirUtil;
61 61
62LLDir::LLDir() 62LLDir::LLDir()
63: mDirDelimiter("/") // fallback to forward slash if not overridden 63: mAppName(""),
64 mExecutablePathAndName(""),
65 mExecutableFilename(""),
66 mExecutableDir(""),
67 mAppRODataDir(""),
68 mOSUserDir(""),
69 mOSUserAppDir(""),
70 mLindenUserDir(""),
71 mOSCacheDir(""),
72 mCAFile(""),
73 mTempDir(""),
74 mDirDelimiter("/") // fallback to forward slash if not overridden
64{ 75{
65} 76}
66 77
@@ -90,7 +101,7 @@ S32 LLDir::deleteFilesInDir(const std::string &dirname, const std::string &mask)
90 S32 retry_count = 0; 101 S32 retry_count = 0;
91 while (retry_count < 5) 102 while (retry_count < 5)
92 { 103 {
93 if (0 != LLFile::remove(fullpath.c_str())) 104 if (0 != LLFile::remove(fullpath))
94 { 105 {
95 result = errno; 106 result = errno;
96 llwarns << "Problem removing " << fullpath << " - errorcode: " 107 llwarns << "Problem removing " << fullpath << " - errorcode: "
@@ -205,13 +216,20 @@ const std::string LLDir::getCacheDir(bool get_default) const
205 if (mCacheDir.empty() || get_default) 216 if (mCacheDir.empty() || get_default)
206 { 217 {
207 std::string res; 218 std::string res;
208 if (getOSUserAppDir().empty()) 219 if (getOSCacheDir().empty())
209 { 220 {
210 res = "data"; 221 if (getOSUserAppDir().empty())
222 {
223 res = "data";
224 }
225 else
226 {
227 res = getOSUserAppDir() + mDirDelimiter + "cache";
228 }
211 } 229 }
212 else 230 else
213 { 231 {
214 res = getOSUserAppDir() + mDirDelimiter + "cache"; 232 res = getOSCacheDir() + mDirDelimiter + "SecondLife";
215 } 233 }
216 return res; 234 return res;
217 } 235 }
@@ -221,6 +239,12 @@ const std::string LLDir::getCacheDir(bool get_default) const
221 } 239 }
222} 240}
223 241
242const std::string &LLDir::getOSCacheDir() const
243{
244 return mOSCacheDir;
245}
246
247
224const std::string &LLDir::getCAFile() const 248const std::string &LLDir::getCAFile() const
225{ 249{
226 return mCAFile; 250 return mCAFile;
@@ -350,6 +374,9 @@ std::string LLDir::getExpandedFilename(ELLPath location, const std::string& subd
350 prefix += mDirDelimiter; 374 prefix += mDirDelimiter;
351 prefix += "browser_profile"; 375 prefix += "browser_profile";
352 break; 376 break;
377
378 case LL_PATH_EXECUTABLE:
379 prefix = getExecutableDir();
353 380
354 default: 381 default:
355 llassert(0); 382 llassert(0);
@@ -395,6 +422,40 @@ std::string LLDir::getExpandedFilename(ELLPath location, const std::string& subd
395 return expanded_filename; 422 return expanded_filename;
396} 423}
397 424
425std::string LLDir::getBaseFileName(const std::string& filepath, bool strip_exten) const
426{
427 std::size_t offset = filepath.find_last_of(getDirDelimiter());
428 offset = (offset == std::string::npos) ? 0 : offset+1;
429 std::string res = filepath.substr(offset, std::string::npos);
430 if (strip_exten)
431 {
432 offset = res.find_last_of('.');
433 if (offset != std::string::npos &&
434 offset != 0) // if basename STARTS with '.', don't strip
435 {
436 res = res.substr(0, offset);
437 }
438 }
439 return res;
440}
441
442std::string LLDir::getDirName(const std::string& filepath) const
443{
444 std::size_t offset = filepath.find_last_of(getDirDelimiter());
445 S32 len = (offset == std::string::npos) ? 0 : offset;
446 std::string dirname = filepath.substr(0, len);
447 return dirname;
448}
449
450std::string LLDir::getExtension(const std::string& filepath) const
451{
452 std::string basename = getBaseFileName(filepath, false);
453 std::size_t offset = basename.find_last_of('.');
454 std::string exten = (offset == std::string::npos || offset == 0) ? "" : basename.substr(offset+1);
455 LLStringUtil::toLower(exten);
456 return exten;
457}
458
398std::string LLDir::findSkinnedFilename(const std::string &filename) const 459std::string LLDir::findSkinnedFilename(const std::string &filename) const
399{ 460{
400 return findSkinnedFilename("", "", filename); 461 return findSkinnedFilename("", "", filename);
@@ -419,11 +480,10 @@ std::string LLDir::findSkinnedFilename(const std::string &subdir1, const std::st
419 return found_file; 480 return found_file;
420} 481}
421 482
422
423std::string LLDir::getTempFilename() const 483std::string LLDir::getTempFilename() const
424{ 484{
425 LLUUID random_uuid; 485 LLUUID random_uuid;
426 char uuid_str[64]; /* Flawfinder: ignore */ 486 std::string uuid_str;
427 487
428 random_uuid.generate(); 488 random_uuid.generate();
429 random_uuid.toString(uuid_str); 489 random_uuid.toString(uuid_str);
@@ -443,15 +503,15 @@ void LLDir::setLindenUserDir(const std::string &first, const std::string &last)
443 { 503 {
444 // some platforms have case-sensitive filesystems, so be 504 // some platforms have case-sensitive filesystems, so be
445 // utterly consistent with our firstname/lastname case. 505 // utterly consistent with our firstname/lastname case.
446 LLString firstlower(first); 506 std::string firstlower(first);
447 LLString::toLower(firstlower); 507 LLStringUtil::toLower(firstlower);
448 LLString lastlower(last); 508 std::string lastlower(last);
449 LLString::toLower(lastlower); 509 LLStringUtil::toLower(lastlower);
450 mLindenUserDir = getOSUserAppDir(); 510 mLindenUserDir = getOSUserAppDir();
451 mLindenUserDir += mDirDelimiter; 511 mLindenUserDir += mDirDelimiter;
452 mLindenUserDir += firstlower.c_str(); 512 mLindenUserDir += firstlower;
453 mLindenUserDir += "_"; 513 mLindenUserDir += "_";
454 mLindenUserDir += lastlower.c_str(); 514 mLindenUserDir += lastlower;
455 } 515 }
456 else 516 else
457 { 517 {
@@ -480,15 +540,15 @@ void LLDir::setPerAccountChatLogsDir(const std::string &first, const std::string
480 { 540 {
481 // some platforms have case-sensitive filesystems, so be 541 // some platforms have case-sensitive filesystems, so be
482 // utterly consistent with our firstname/lastname case. 542 // utterly consistent with our firstname/lastname case.
483 LLString firstlower(first); 543 std::string firstlower(first);
484 LLString::toLower(firstlower); 544 LLStringUtil::toLower(firstlower);
485 LLString lastlower(last); 545 std::string lastlower(last);
486 LLString::toLower(lastlower); 546 LLStringUtil::toLower(lastlower);
487 mPerAccountChatLogsDir = getChatLogsDir(); 547 mPerAccountChatLogsDir = getChatLogsDir();
488 mPerAccountChatLogsDir += mDirDelimiter; 548 mPerAccountChatLogsDir += mDirDelimiter;
489 mPerAccountChatLogsDir += firstlower.c_str(); 549 mPerAccountChatLogsDir += firstlower;
490 mPerAccountChatLogsDir += "_"; 550 mPerAccountChatLogsDir += "_";
491 mPerAccountChatLogsDir += lastlower.c_str(); 551 mPerAccountChatLogsDir += lastlower;
492 } 552 }
493 else 553 else
494 { 554 {
@@ -531,13 +591,13 @@ bool LLDir::setCacheDir(const std::string &path)
531 } 591 }
532 else 592 else
533 { 593 {
534 LLFile::mkdir(path.c_str()); 594 LLFile::mkdir(path);
535 std::string tempname = path + mDirDelimiter + "temp"; 595 std::string tempname = path + mDirDelimiter + "temp";
536 LLFILE* file = LLFile::fopen(tempname.c_str(),"wt"); 596 LLFILE* file = LLFile::fopen(tempname,"wt");
537 if (file) 597 if (file)
538 { 598 {
539 fclose(file); 599 fclose(file);
540 LLFile::remove(tempname.c_str()); 600 LLFile::remove(tempname);
541 mCacheDir = path; 601 mCacheDir = path;
542 return true; 602 return true;
543 } 603 }
@@ -570,15 +630,15 @@ void dir_exists_or_crash(const std::string &dir_name)
570#if LL_WINDOWS 630#if LL_WINDOWS
571 // *FIX: lame - it doesn't do the same thing on windows. not so 631 // *FIX: lame - it doesn't do the same thing on windows. not so
572 // important since we don't deploy simulator to windows boxes. 632 // important since we don't deploy simulator to windows boxes.
573 LLFile::mkdir(dir_name.c_str(), 0700); 633 LLFile::mkdir(dir_name, 0700);
574#else 634#else
575 struct stat dir_stat; 635 struct stat dir_stat;
576 if(0 != LLFile::stat(dir_name.c_str(), &dir_stat)) 636 if(0 != LLFile::stat(dir_name, &dir_stat))
577 { 637 {
578 S32 stat_rv = errno; 638 S32 stat_rv = errno;
579 if(ENOENT == stat_rv) 639 if(ENOENT == stat_rv)
580 { 640 {
581 if(0 != LLFile::mkdir(dir_name.c_str(), 0700)) // octal 641 if(0 != LLFile::mkdir(dir_name, 0700)) // octal
582 { 642 {
583 llerrs << "Unable to create directory: " << dir_name << llendl; 643 llerrs << "Unable to create directory: " << dir_name << llendl;
584 } 644 }