aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llvfs/llvfs.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/llvfs.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/llvfs/llvfs.cpp')
-rw-r--r--linden/indra/llvfs/llvfs.cpp112
1 files changed, 32 insertions, 80 deletions
diff --git a/linden/indra/llvfs/llvfs.cpp b/linden/indra/llvfs/llvfs.cpp
index 7903e83..b3d02a5 100644
--- a/linden/indra/llvfs/llvfs.cpp
+++ b/linden/indra/llvfs/llvfs.cpp
@@ -232,7 +232,7 @@ struct LLVFSFileBlock_less
232const S32 LLVFSFileBlock::SERIAL_SIZE = 34; 232const S32 LLVFSFileBlock::SERIAL_SIZE = 34;
233 233
234 234
235LLVFS::LLVFS(const char *index_filename, const char *data_filename, const BOOL read_only, const U32 presize, const BOOL remove_after_crash) 235LLVFS::LLVFS(const std::string& index_filename, const std::string& data_filename, const BOOL read_only, const U32 presize, const BOOL remove_after_crash)
236: mRemoveAfterCrash(remove_after_crash) 236: mRemoveAfterCrash(remove_after_crash)
237{ 237{
238 mDataMutex = new LLMutex(0); 238 mDataMutex = new LLMutex(0);
@@ -244,15 +244,8 @@ LLVFS::LLVFS(const char *index_filename, const char *data_filename, const BOOL r
244 } 244 }
245 mValid = VFSVALID_OK; 245 mValid = VFSVALID_OK;
246 mReadOnly = read_only; 246 mReadOnly = read_only;
247 mIndexFilename = new char[strlen(index_filename) + 1]; /* Flawfinder: ignore */ 247 mIndexFilename = index_filename;
248 mDataFilename = new char[strlen(data_filename) + 1]; /* Flawfinder: ignore */ 248 mDataFilename = data_filename;
249 if (mIndexFilename == NULL || mDataFilename == NULL)
250 {
251 LL_ERRS("VFS") << "Memory Allocation Failure" << LL_ENDL;
252 return;
253 }
254 strcpy(mIndexFilename, index_filename); /* Flawfinder: ignore */
255 strcpy(mDataFilename, data_filename); /* Flawfinder: ignore */
256 249
257 const char *file_mode = mReadOnly ? "rb" : "r+b"; 250 const char *file_mode = mReadOnly ? "rb" : "r+b";
258 251
@@ -276,23 +269,13 @@ LLVFS::LLVFS(const char *index_filename, const char *data_filename, const BOOL r
276 { 269 {
277 LL_WARNS("VFS") << "Can't open VFS data file " << mDataFilename << " attempting to use alternate" << LL_ENDL; 270 LL_WARNS("VFS") << "Can't open VFS data file " << mDataFilename << " attempting to use alternate" << LL_ENDL;
278 271
279 char *temp_index = new char[strlen(mIndexFilename) + 10]; /* Flawfinder: ignore */ 272 std::string temp_index;
280 if (!temp_index) 273 std::string temp_data;
281 {
282 LL_ERRS("VFS") << "Out of the memory in LLVFS::LLVFS()" << LL_ENDL;
283 return;
284 }
285 char *temp_data = new char[strlen(mDataFilename) + 10]; /* Flawfinder: ignore */
286 if (!temp_data)
287 {
288 LL_ERRS("VFS") << "Out of the memory in LLVFS::LLVFS()" << LL_ENDL;
289 return;
290 }
291 274
292 for (U32 count = 0; count < 256; count++) 275 for (U32 count = 0; count < 256; count++)
293 { 276 {
294 sprintf(temp_index, "%s.%u", mIndexFilename, count); /* Flawfinder: ignore */ 277 temp_index = mIndexFilename + llformat(".%u",count);
295 sprintf(temp_data, "%s.%u", mDataFilename, count); /* Flawfinder: ignore */ 278 temp_data = mDataFilename + llformat(".%u", count);
296 279
297 // try just opening, then creating, each alternate 280 // try just opening, then creating, each alternate
298 if ((mDataFP = openAndLock(temp_data, "r+b", FALSE))) 281 if ((mDataFP = openAndLock(temp_data, "r+b", FALSE)))
@@ -312,14 +295,9 @@ LLVFS::LLVFS(const char *index_filename, const char *data_filename, const BOOL r
312 { 295 {
313 LL_WARNS("VFS") << "Couldn't open vfs data file after trying many alternates" << LL_ENDL; 296 LL_WARNS("VFS") << "Couldn't open vfs data file after trying many alternates" << LL_ENDL;
314 mValid = VFSVALID_BAD_CANNOT_CREATE; 297 mValid = VFSVALID_BAD_CANNOT_CREATE;
315 delete[] temp_index;
316 delete[] temp_data;
317 return; 298 return;
318 } 299 }
319 300
320 delete[] mIndexFilename;
321 delete[] mDataFilename;
322
323 mIndexFilename = temp_index; 301 mIndexFilename = temp_index;
324 mDataFilename = temp_data; 302 mDataFilename = temp_data;
325 } 303 }
@@ -335,13 +313,7 @@ LLVFS::LLVFS(const char *index_filename, const char *data_filename, const BOOL r
335 if (!mReadOnly && mRemoveAfterCrash) 313 if (!mReadOnly && mRemoveAfterCrash)
336 { 314 {
337 llstat marker_info; 315 llstat marker_info;
338 char* marker = new char[strlen(mDataFilename) + strlen(".open") + 1]; /* Flawfinder: ignore */ 316 std::string marker = mDataFilename + ".open";
339 if (!marker )
340 {
341 LL_ERRS("VFS") << "Out of memory in LLVFS::LLVFS()" << LL_ENDL;
342 return;
343 }
344 sprintf(marker, "%s.open", mDataFilename); /* Flawfinder: ignore */
345 if (!LLFile::stat(marker, &marker_info)) 317 if (!LLFile::stat(marker, &marker_info))
346 { 318 {
347 // marker exists, kill the lock and the VFS files 319 // marker exists, kill the lock and the VFS files
@@ -366,8 +338,6 @@ LLVFS::LLVFS(const char *index_filename, const char *data_filename, const BOOL r
366 presizeDataFile(presize); 338 presizeDataFile(presize);
367 } 339 }
368 } 340 }
369 delete [] marker;
370 marker = NULL;
371 } 341 }
372 342
373 // determine the real file size 343 // determine the real file size
@@ -590,21 +560,13 @@ LLVFS::LLVFS(const char *index_filename, const char *data_filename, const BOOL r
590 // Open marker file to look for bad shutdowns 560 // Open marker file to look for bad shutdowns
591 if (!mReadOnly && mRemoveAfterCrash) 561 if (!mReadOnly && mRemoveAfterCrash)
592 { 562 {
593 char* marker = new char[strlen(mDataFilename) + strlen(".open") + 1]; 563 std::string marker = mDataFilename + ".open";
594 if (!marker)
595 {
596 LL_ERRS("VFS") << "Out of memory in LLVFS::LLVFS()" << LL_ENDL;
597 return;
598 }
599 sprintf(marker, "%s.open", mDataFilename); /* Flawfinder: ignore */
600 LLFILE* marker_fp = LLFile::fopen(marker, "w"); /* Flawfinder: ignore */ 564 LLFILE* marker_fp = LLFile::fopen(marker, "w"); /* Flawfinder: ignore */
601 if (marker_fp) 565 if (marker_fp)
602 { 566 {
603 fclose(marker_fp); 567 fclose(marker_fp);
604 marker_fp = NULL; 568 marker_fp = NULL;
605 } 569 }
606 delete [] marker;
607 marker = NULL;
608 } 570 }
609 571
610 LL_WARNS("VFS") << "Using index file " << mIndexFilename << LL_ENDL; 572 LL_WARNS("VFS") << "Using index file " << mIndexFilename << LL_ENDL;
@@ -640,23 +602,10 @@ LLVFS::~LLVFS()
640 // Remove marker file 602 // Remove marker file
641 if (!mReadOnly && mRemoveAfterCrash) 603 if (!mReadOnly && mRemoveAfterCrash)
642 { 604 {
643 char* marker_file = new char[strlen(mDataFilename) + strlen(".open") + 1]; 605 std::string marker = mDataFilename + ".open";
644 if (marker_file == NULL) 606 LLFile::remove(marker);
645 {
646 LL_ERRS("VFS") << "Memory Allocation Failure" << LL_ENDL;
647 return;
648 }
649 sprintf(marker_file, "%s.open", mDataFilename); /* Flawfinder: ignore */
650 LLFile::remove(marker_file);
651 delete [] marker_file;
652 marker_file = NULL;
653 } 607 }
654 608
655 delete[] mIndexFilename;
656 mIndexFilename = NULL;
657 delete[] mDataFilename;
658 mDataFilename = NULL;
659
660 delete mDataMutex; 609 delete mDataMutex;
661} 610}
662 611
@@ -2042,31 +1991,30 @@ void LLVFS::dumpStatistics()
2042} 1991}
2043 1992
2044// Debug Only! 1993// Debug Only!
2045LLString get_extension(LLAssetType::EType type) 1994std::string get_extension(LLAssetType::EType type)
2046{ 1995{
2047 LLString extension; 1996 std::string extension;
2048 switch(type) 1997 switch(type)
2049 { 1998 {
2050 case LLAssetType::AT_TEXTURE: 1999 case LLAssetType::AT_TEXTURE:
2051 extension = ".j2c"; 2000 extension = ".jp2"; // formerly ".j2c"
2052 break; 2001 break;
2053 case LLAssetType::AT_SOUND: 2002 case LLAssetType::AT_SOUND:
2054 extension = ".ogg"; 2003 extension = ".ogg";
2055 break; 2004 break;
2056 case LLAssetType::AT_SOUND_WAV: 2005 case LLAssetType::AT_SOUND_WAV:
2057 extension = ".wav"; 2006 extension = ".wav";
2058 break; 2007 break;
2059 case LLAssetType::AT_TEXTURE_TGA: 2008 case LLAssetType::AT_TEXTURE_TGA:
2060 extension = ".tga"; 2009 extension = ".tga";
2061 break; 2010 break;
2062 case LLAssetType::AT_IMAGE_JPEG: 2011 case LLAssetType::AT_ANIMATION:
2063 extension = ".jpeg";
2064 break;
2065 case LLAssetType::AT_ANIMATION:
2066 extension = ".lla"; 2012 extension = ".lla";
2067 break; 2013 break;
2068 default: 2014 default:
2069 extension = ".data"; 2015 // Just use the asset server filename extension in most cases
2016 extension += ".";
2017 extension += LLAssetType::lookup(type);
2070 break; 2018 break;
2071 } 2019 }
2072 return extension; 2020 return extension;
@@ -2085,7 +2033,7 @@ void LLVFS::listFiles()
2085 if (length != BLOCK_LENGTH_INVALID && size > 0) 2033 if (length != BLOCK_LENGTH_INVALID && size > 0)
2086 { 2034 {
2087 LLUUID id = file_spec.mFileID; 2035 LLUUID id = file_spec.mFileID;
2088 LLString extension = get_extension(file_spec.mFileType); 2036 std::string extension = get_extension(file_spec.mFileType);
2089 llinfos << " File: " << id 2037 llinfos << " File: " << id
2090 << " Type: " << LLAssetType::getDesc(file_spec.mFileType) 2038 << " Type: " << LLAssetType::getDesc(file_spec.mFileType)
2091 << " Size: " << size 2039 << " Size: " << size
@@ -2101,6 +2049,7 @@ void LLVFS::dumpFiles()
2101{ 2049{
2102 lockData(); 2050 lockData();
2103 2051
2052 S32 files_extracted = 0;
2104 for (fileblock_map::iterator it = mFileBlocks.begin(); it != mFileBlocks.end(); ++it) 2053 for (fileblock_map::iterator it = mFileBlocks.begin(); it != mFileBlocks.end(); ++it)
2105 { 2054 {
2106 LLVFSFileSpecifier file_spec = it->first; 2055 LLVFSFileSpecifier file_spec = it->first;
@@ -2117,17 +2066,20 @@ void LLVFS::dumpFiles()
2117 getData(id, type, buffer, 0, size); 2066 getData(id, type, buffer, 0, size);
2118 lockData(); 2067 lockData();
2119 2068
2120 LLString extension = get_extension(type); 2069 std::string extension = get_extension(type);
2121 LLString filename = id.asString() + extension; 2070 std::string filename = id.asString() + extension;
2122 llinfos << " Writing " << filename << llendl; 2071 llinfos << " Writing " << filename << llendl;
2123 apr_file_t* file = ll_apr_file_open(filename, LL_APR_WB); 2072 apr_file_t* file = ll_apr_file_open(filename, LL_APR_WB);
2124 ll_apr_file_write(file, buffer, size); 2073 ll_apr_file_write(file, buffer, size);
2125 apr_file_close(file); 2074 apr_file_close(file);
2126 delete[] buffer; 2075 delete[] buffer;
2076 files_extracted++;
2127 } 2077 }
2128 } 2078 }
2129 2079
2130 unlockData(); 2080 unlockData();
2081
2082 llinfos << "Extracted " << files_extracted << " files out of " << mFileBlocks.size() << llendl;
2131} 2083}
2132 2084
2133//============================================================================ 2085//============================================================================
@@ -2135,7 +2087,7 @@ void LLVFS::dumpFiles()
2135//============================================================================ 2087//============================================================================
2136 2088
2137// static 2089// static
2138LLFILE *LLVFS::openAndLock(const char *filename, const char *mode, BOOL read_lock) 2090LLFILE *LLVFS::openAndLock(const std::string& filename, const char* mode, BOOL read_lock)
2139{ 2091{
2140#if LL_WINDOWS 2092#if LL_WINDOWS
2141 2093
@@ -2153,7 +2105,7 @@ LLFILE *LLVFS::openAndLock(const char *filename, const char *mode, BOOL read_loc
2153 fl.l_start = 0; 2105 fl.l_start = 0;
2154 fl.l_len = 1; 2106 fl.l_len = 1;
2155#else // !LL_SOLARIS 2107#else // !LL_SOLARIS
2156 if (strstr(mode, "w")) 2108 if (strchr(mode, 'w') != NULL)
2157 { 2109 {
2158 fp = LLFile::fopen(filename, "rb"); /* Flawfinder: ignore */ 2110 fp = LLFile::fopen(filename, "rb"); /* Flawfinder: ignore */
2159 if (fp) 2111 if (fp)