Port Viewer 2 indra/llvfs
This introduces some API changes, like the new LLDirIterator, that causes changes elsewhere. It also include Log Linden's cache changes that aren't in viewer-development yet that increase the maximum cache size to ~10 GB.
This commit is contained in:
@@ -178,6 +178,7 @@
|
||||
#include "llviewerthrottle.h"
|
||||
#include "llparcel.h"
|
||||
|
||||
#include "lldiriterator.h"
|
||||
#include "llavatarnamecache.h"
|
||||
#include "llinventoryview.h"
|
||||
|
||||
@@ -2952,8 +2953,10 @@ void LLAppViewer::migrateCacheDirectory()
|
||||
// Migrate inventory cache to avoid pain to inventory database after mass update
|
||||
S32 file_count = 0;
|
||||
std::string file_name;
|
||||
std::string mask = delimiter + "*.*";
|
||||
while (gDirUtilp->getNextFileInDir(old_cache_dir, mask, file_name, false))
|
||||
std::string mask = "*.*";
|
||||
|
||||
LLDirIterator iter(old_cache_dir, mask);
|
||||
while (iter.next(file_name))
|
||||
{
|
||||
if (file_name == "." || file_name == "..") continue;
|
||||
std::string source_path = old_cache_dir + delimiter + file_name;
|
||||
@@ -2987,6 +2990,44 @@ void LLAppViewer::migrateCacheDirectory()
|
||||
#endif // LL_WINDOWS || LL_DARWIN
|
||||
}
|
||||
|
||||
void dumpVFSCaches()
|
||||
{
|
||||
llinfos << "======= Static VFS ========" << llendl;
|
||||
gStaticVFS->listFiles();
|
||||
#if LL_WINDOWS
|
||||
llinfos << "======= Dumping static VFS to StaticVFSDump ========" << llendl;
|
||||
WCHAR w_str[MAX_PATH];
|
||||
GetCurrentDirectory(MAX_PATH, w_str);
|
||||
S32 res = LLFile::mkdir("StaticVFSDump");
|
||||
if (res == -1)
|
||||
{
|
||||
if (errno != EEXIST)
|
||||
{
|
||||
llwarns << "Couldn't create dir StaticVFSDump" << llendl;
|
||||
}
|
||||
}
|
||||
SetCurrentDirectory(utf8str_to_utf16str("StaticVFSDump").c_str());
|
||||
gStaticVFS->dumpFiles();
|
||||
SetCurrentDirectory(w_str);
|
||||
#endif
|
||||
llinfos << "========= Dynamic VFS ====" << llendl;
|
||||
gVFS->listFiles();
|
||||
#if LL_WINDOWS
|
||||
llinfos << "========= Dumping dynamic VFS to VFSDump ====" << llendl;
|
||||
res = LLFile::mkdir("VFSDump");
|
||||
if (res == -1)
|
||||
{
|
||||
if (errno != EEXIST)
|
||||
{
|
||||
llwarns << "Couldn't create dir VFSDump" << llendl;
|
||||
}
|
||||
}
|
||||
SetCurrentDirectory(utf8str_to_utf16str("VFSDump").c_str());
|
||||
gVFS->dumpFiles();
|
||||
SetCurrentDirectory(w_str);
|
||||
#endif
|
||||
}
|
||||
|
||||
//static
|
||||
U32 LLAppViewer::getTextureCacheVersion()
|
||||
{
|
||||
@@ -3017,11 +3058,12 @@ bool LLAppViewer::initCache()
|
||||
if (gSavedSettings.getBOOL("PurgeCacheOnStartup") ||
|
||||
gSavedSettings.getBOOL("PurgeCacheOnNextStartup"))
|
||||
{
|
||||
gSavedSettings.setBOOL("PurgeCacheOnNextStartup", false);
|
||||
mPurgeCache = true;
|
||||
gSavedSettings.setBOOL("PurgeCacheOnNextStartup", false);
|
||||
mPurgeCache = true;
|
||||
// STORM-1141 force purgeAllTextures to get called to prevent a crash here. -brad
|
||||
texture_cache_mismatch = true;
|
||||
}
|
||||
// Bullshit, mPurgeCache already causes the same and doing it twice just leads to loads of warnings. --Aleric
|
||||
//texture_cache_mismatch = true;
|
||||
}
|
||||
|
||||
// We have moved the location of the cache directory over time.
|
||||
migrateCacheDirectory();
|
||||
@@ -3047,38 +3089,53 @@ bool LLAppViewer::initCache()
|
||||
{
|
||||
LLSplashScreen::update("Clearing cache...");
|
||||
purgeCache();
|
||||
// <edit>
|
||||
texture_cache_mismatch = false;
|
||||
// </edit>
|
||||
}
|
||||
|
||||
LLSplashScreen::update("Initializing Texture Cache...");
|
||||
|
||||
// Init the texture cache
|
||||
// Allocate 80% of the cache size for textures
|
||||
const S32 MB = 1024*1024;
|
||||
const S32 MB = 1024 * 1024;
|
||||
const S64 MIN_CACHE_SIZE = 64 * MB;
|
||||
const S64 MAX_CACHE_SIZE = 9984ll * MB;
|
||||
const S64 MAX_VFS_SIZE = 1024 * MB; // 1 GB
|
||||
|
||||
S64 cache_size = (S64)(gSavedSettings.getU32("CacheSize")) * MB;
|
||||
const S64 MAX_CACHE_SIZE = 1024*MB;
|
||||
cache_size = llmin(cache_size, MAX_CACHE_SIZE);
|
||||
S64 texture_cache_size = ((cache_size * 8)/10);
|
||||
cache_size = llclamp(cache_size, MIN_CACHE_SIZE, MAX_CACHE_SIZE);
|
||||
|
||||
S64 texture_cache_size = ((cache_size * 8) / 10);
|
||||
S64 vfs_size = cache_size - texture_cache_size;
|
||||
|
||||
if (vfs_size > MAX_VFS_SIZE)
|
||||
{
|
||||
// Give the texture cache more space, since the VFS can't be bigger than 1GB.
|
||||
// This happens when the user's CacheSize setting is greater than 5GB.
|
||||
vfs_size = MAX_VFS_SIZE;
|
||||
texture_cache_size = cache_size - MAX_VFS_SIZE;
|
||||
}
|
||||
|
||||
S64 extra = LLAppViewer::getTextureCache()->initCache(LL_PATH_CACHE, texture_cache_size, texture_cache_mismatch);
|
||||
texture_cache_size -= extra;
|
||||
|
||||
LLSplashScreen::update("Initializing VFS...");
|
||||
|
||||
// Init the VFS
|
||||
S64 vfs_size = cache_size - texture_cache_size;
|
||||
const S64 MAX_VFS_SIZE = 1024 * MB; // 1 GB
|
||||
vfs_size = llmin(vfs_size, MAX_VFS_SIZE);
|
||||
vfs_size = llmin(vfs_size + extra, MAX_VFS_SIZE);
|
||||
vfs_size = (vfs_size / MB) * MB; // make sure it is MB aligned
|
||||
U32 vfs_size_u32 = (U32)vfs_size;
|
||||
U32 old_vfs_size = gSavedSettings.getU32("VFSOldSize") * MB;
|
||||
bool resize_vfs = (vfs_size_u32 != old_vfs_size);
|
||||
if (resize_vfs)
|
||||
{
|
||||
gSavedSettings.setU32("VFSOldSize", vfs_size_u32/MB);
|
||||
gSavedSettings.setU32("VFSOldSize", vfs_size_u32 / MB);
|
||||
}
|
||||
LL_INFOS("AppCache") << "VFS CACHE SIZE: " << vfs_size/(1024*1024) << " MB" << LL_ENDL;
|
||||
LL_INFOS("AppCache") << "VFS CACHE SIZE: " << vfs_size / (1024*1024) << " MB" << LL_ENDL;
|
||||
|
||||
// This has to happen BEFORE starting the vfs
|
||||
//time_t ltime;
|
||||
// time_t ltime;
|
||||
srand(time(NULL)); // Flawfinder: ignore
|
||||
U32 old_salt = gSavedSettings.getU32("VFSSalt");
|
||||
U32 new_salt;
|
||||
@@ -3099,10 +3156,10 @@ bool LLAppViewer::initCache()
|
||||
do
|
||||
{
|
||||
new_salt = rand();
|
||||
} while( new_salt == old_salt );
|
||||
} while(new_salt == old_salt);
|
||||
}
|
||||
|
||||
old_vfs_data_file = gDirUtilp->getExpandedFilename(LL_PATH_CACHE,VFS_DATA_FILE_BASE) + llformat("%u",old_salt);
|
||||
old_vfs_data_file = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, VFS_DATA_FILE_BASE) + llformat("%u",old_salt);
|
||||
|
||||
// make sure this file exists
|
||||
llstat s;
|
||||
@@ -3111,15 +3168,15 @@ bool LLAppViewer::initCache()
|
||||
{
|
||||
// doesn't exist, look for a data file
|
||||
std::string mask;
|
||||
mask = gDirUtilp->getDirDelimiter();
|
||||
mask += VFS_DATA_FILE_BASE;
|
||||
mask = VFS_DATA_FILE_BASE;
|
||||
mask += "*";
|
||||
|
||||
std::string dir;
|
||||
dir = gDirUtilp->getExpandedFilename(LL_PATH_CACHE,"");
|
||||
dir = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "");
|
||||
|
||||
std::string found_file;
|
||||
if (gDirUtilp->getNextFileInDir(dir, mask, found_file, false))
|
||||
LLDirIterator iter(dir, mask);
|
||||
if (iter.next(found_file))
|
||||
{
|
||||
old_vfs_data_file = dir + gDirUtilp->getDirDelimiter() + found_file;
|
||||
|
||||
@@ -3132,7 +3189,7 @@ bool LLAppViewer::initCache()
|
||||
}
|
||||
}
|
||||
|
||||
old_vfs_index_file = gDirUtilp->getExpandedFilename(LL_PATH_CACHE,VFS_INDEX_FILE_BASE) + llformat("%u",old_salt);
|
||||
old_vfs_index_file = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, VFS_INDEX_FILE_BASE) + llformat("%u",old_salt);
|
||||
|
||||
stat_result = LLFile::stat(old_vfs_index_file, &s);
|
||||
if (stat_result)
|
||||
@@ -3145,27 +3202,25 @@ bool LLAppViewer::initCache()
|
||||
|
||||
// Just in case, nuke any other old cache files in the directory.
|
||||
std::string dir;
|
||||
dir = gDirUtilp->getExpandedFilename(LL_PATH_CACHE,"");
|
||||
dir = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "");
|
||||
|
||||
std::string mask;
|
||||
mask = gDirUtilp->getDirDelimiter();
|
||||
mask += VFS_DATA_FILE_BASE;
|
||||
mask = VFS_DATA_FILE_BASE;
|
||||
mask += "*";
|
||||
|
||||
gDirUtilp->deleteFilesInDir(dir, mask);
|
||||
|
||||
mask = gDirUtilp->getDirDelimiter();
|
||||
mask += VFS_INDEX_FILE_BASE;
|
||||
mask = VFS_INDEX_FILE_BASE;
|
||||
mask += "*";
|
||||
|
||||
gDirUtilp->deleteFilesInDir(dir, mask);
|
||||
}
|
||||
|
||||
new_vfs_data_file = gDirUtilp->getExpandedFilename(LL_PATH_CACHE,VFS_DATA_FILE_BASE) + llformat("%u",new_salt);
|
||||
new_vfs_index_file = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, VFS_INDEX_FILE_BASE) + llformat("%u",new_salt);
|
||||
new_vfs_data_file = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, VFS_DATA_FILE_BASE) + llformat("%u", new_salt);
|
||||
new_vfs_index_file = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, VFS_INDEX_FILE_BASE) + llformat("%u", new_salt);
|
||||
|
||||
static_vfs_data_file = gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS,"static_data.db2");
|
||||
static_vfs_index_file = gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS,"static_index.db2");
|
||||
static_vfs_data_file = gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "static_data.db2");
|
||||
static_vfs_index_file = gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "static_index.db2");
|
||||
|
||||
if (resize_vfs)
|
||||
{
|
||||
@@ -3187,36 +3242,44 @@ bool LLAppViewer::initCache()
|
||||
gSavedSettings.setU32("VFSSalt", new_salt);
|
||||
|
||||
// Don't remove VFS after viewer crashes. If user has corrupt data, they can reinstall. JC
|
||||
gVFS = new LLVFS(new_vfs_index_file, new_vfs_data_file, false, vfs_size_u32, false);
|
||||
if( VFSVALID_BAD_CORRUPT == gVFS->getValidState() )
|
||||
gVFS = LLVFS::createLLVFS(new_vfs_index_file, new_vfs_data_file, false, vfs_size_u32, false);
|
||||
if (!gVFS)
|
||||
{
|
||||
// Try again with fresh files
|
||||
// (The constructor deletes corrupt files when it finds them.)
|
||||
LL_WARNS("AppCache") << "VFS corrupt, deleted. Making new VFS." << LL_ENDL;
|
||||
delete gVFS;
|
||||
gVFS = new LLVFS(new_vfs_index_file, new_vfs_data_file, false, vfs_size_u32, false);
|
||||
return false;
|
||||
}
|
||||
|
||||
gStaticVFS = new LLVFS(static_vfs_index_file, static_vfs_data_file, true, 0, false);
|
||||
gStaticVFS = LLVFS::createLLVFS(static_vfs_index_file, static_vfs_data_file, true, 0, false);
|
||||
if (!gStaticVFS)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
BOOL success = gVFS->isValid() && gStaticVFS->isValid();
|
||||
if( !success )
|
||||
if (!success)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
LLVFile::initClass();
|
||||
|
||||
#ifndef LL_RELEASE_FOR_DOWNLOAD
|
||||
if (gSavedSettings.getBOOL("DumpVFSCaches"))
|
||||
{
|
||||
dumpVFSCaches();
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void LLAppViewer::purgeCache()
|
||||
{
|
||||
LL_INFOS("AppCache") << "Purging Cache and Texture Cache..." << llendl;
|
||||
LL_INFOS("AppCache") << "Purging Cache and Texture Cache..." << LL_ENDL;
|
||||
LLAppViewer::getTextureCache()->purgeCache(LL_PATH_CACHE);
|
||||
std::string mask = gDirUtilp->getDirDelimiter() + "*.*";
|
||||
gDirUtilp->deleteFilesInDir(gDirUtilp->getExpandedFilename(LL_PATH_CACHE,""),mask);
|
||||
std::string mask = "*.*";
|
||||
gDirUtilp->deleteFilesInDir(gDirUtilp->getExpandedFilename(LL_PATH_CACHE, ""), mask);
|
||||
}
|
||||
|
||||
const std::string& LLAppViewer::getSecondLifeTitle() const
|
||||
|
||||
Reference in New Issue
Block a user