Readd texture purge thread, as it was not breaking Vista.

meow-7.2.2
Nicky 2015-08-17 22:40:05 +02:00
parent 1ab7c288ed
commit c59f9a1e51
6 changed files with 147 additions and 1 deletions

View File

@ -0,0 +1,110 @@
// <FS:ND> Thread to purge old texture cache in the background.
// The cache dir will be search for directories named *.old_texturecache, then each of this directories
// will be deleted.
// The thread will be started each time the viewer starts, just in case there is directories so huge,
// the user quit the viewer before the old cache was fully cleared.
void deleteFilesInDirectory( std::wstring aDir )
{
if( aDir == L"." || aDir == L".." || aDir.empty() )
return;
if( aDir[ aDir.size() -1 ] != '\\' || aDir[ aDir.size() -1 ] != '/' )
aDir += L"\\";
WIN32_FIND_DATA oFindData;
HANDLE hFindHandle = ::FindFirstFile( (aDir + L"*.*").c_str(), &oFindData );
if( INVALID_HANDLE_VALUE == hFindHandle )
return;
do
{
if( ! (oFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) )
{
std::wstring strFile = aDir + oFindData.cFileName;
if( oFindData.dwFileAttributes & FILE_ATTRIBUTE_READONLY )
::SetFileAttributes( strFile.c_str(), FILE_ATTRIBUTE_NORMAL );
::DeleteFile( ( aDir + oFindData.cFileName ).c_str() );
}
} while( ::FindNextFile( hFindHandle, &oFindData ) );
::FindClose( hFindHandle );
}
void deleteCacheDirectory( std::wstring aDir )
{
if( aDir == L"." || aDir == L".." || aDir.empty() )
return;
if( aDir[ aDir.size() -1 ] != '\\' || aDir[ aDir.size() -1 ] != '/' )
aDir += L"\\";
wchar_t aCacheDirs[] = L"0123456789abcdef";
for( int i = 0; i < _countof( aCacheDirs ); ++i )
{
deleteFilesInDirectory( aDir + aCacheDirs[i] );
::RemoveDirectory( (aDir + aCacheDirs[i]).c_str() );
}
deleteFilesInDirectory( aDir );
::RemoveDirectory( aDir.c_str() );
}
DWORD WINAPI purgeThread( LPVOID lpParameter )
{
wchar_t *pDir = reinterpret_cast< wchar_t* >( lpParameter );
if( !pDir )
return 0;
std::wstring strPath = pDir;
free( pDir );
if( strPath.empty() )
return 0;
if( strPath[ strPath.size() -1 ] != '\\' || strPath[ strPath.size() -1 ] != '/' )
strPath += L"\\";
WIN32_FIND_DATA oFindData;
HANDLE hFindHandle = ::FindFirstFile( ( strPath + L"*.old_texturecache" ).c_str(), &oFindData );
std::vector< std::wstring > vctDirs;
if( INVALID_HANDLE_VALUE == hFindHandle )
return 0;
do
{
if( oFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
vctDirs.push_back( strPath + oFindData.cFileName );
} while( ::FindNextFile( hFindHandle, &oFindData ) );
::FindClose( hFindHandle );
for( auto dir : vctDirs )
deleteCacheDirectory( dir );
return 0;
}
void LLAppViewerWin32::startCachePurge()
{
if( isSecondInstance() )
return;
std::wstring strCacheDir = wstringize( gDirUtilp->getExpandedFilename( LL_PATH_CACHE, "" ) );
HANDLE hThread = CreateThread( nullptr, 0, purgeThread, _wcsdup( strCacheDir.c_str() ), 0, nullptr );
if( !hThread )
{
LL_WARNS("CachePurge") << "CreateThread failed: " << GetLastError() << LL_ENDL;
}
else
SetThreadPriority( hThread, THREAD_MODE_BACKGROUND_BEGIN );
}
// </FS:ND>

View File

@ -5132,6 +5132,10 @@ bool LLAppViewer::initCache()
}
// </FS:Ansariel>
// <FS:ND> For Windows, purging the cache can take an extraordinary amount of time. Rename the cache dir and purge it using another thread.
startCachePurge();
// </FS:ND>
LLSplashScreen::update(LLTrans::getString("StartupInitializingTextureCache"));
// Init the texture cache

View File

@ -350,6 +350,11 @@ public:
void setSaveSettingsOnExit(bool state) {mSaveSettingsOnExit = state; };
bool mSaveSettingsOnExit;
// </FS:Zi>
// <FS:ND> For Windows, purging the cache can take an extraordinary amount of time. Rename the cache dir and purge it using another thread.
private:
virtual void startCachePurge() {}
// </FS:ND>
};
// consts from viewer.h

View File

@ -937,3 +937,5 @@ std::string LLAppViewerWin32::generateSerialNumber()
}
return serial_md5;
}
#include "fsappviewerwin32.cpp"

View File

@ -63,6 +63,11 @@ private:
std::string mCmdLine;
bool mIsConsoleAllocated;
// <FS:ND> For Windows, purging the cache can take an extraordinary amount of time. Rename the cache dir and purge it using another thread.
virtual void startCachePurge();
// </FS:ND>
};
#endif // LL_LLAPPVIEWERWIN32_H

View File

@ -1542,6 +1542,25 @@ void LLTextureCache::purgeAllTextures(bool purge_directories)
{
if (!mReadOnly)
{
// <FS:ND> Windows can be really slow deleting a huge texture cache.
// In case of a full purge rename the directory and then purge this using a low priority background thread.
#if LL_WINDOWS
bool bOldPurge = true;
if( purge_directories )
{
std::string strNewName = mCacheParentDirName + gDirUtilp->getDirDelimiter() + LLUUID::generateNewID().asString() + ".old_texturecache";
if( LLFile::isdir( mTexturesDirName ) )
bOldPurge = ( 0 != LLFile::rename( mTexturesDirName, strNewName ) );
if( bOldPurge )
{
LL_WARNS() << "Rename of " << mTexturesDirName << " to " << strNewName << " failed" << LL_ENDL;
}
}
if( !purge_directories || bOldPurge )
#endif
// </FS:ND>
{
const char* subdirs = "0123456789abcdef";
std::string delem = gDirUtilp->getDirDelimiter();
std::string mask = "*";
@ -1565,7 +1584,8 @@ void LLTextureCache::purgeAllTextures(bool purge_directories)
{
gDirUtilp->deleteFilesInDir(mTexturesDirName, mask);
LLFile::rmdir(mTexturesDirName);
}
}
}
}
mHeaderIDMap.clear();
mTexturesSizeMap.clear();