From ff6c503c9a107cafdfcb3248fd46adf76c201092 Mon Sep 17 00:00:00 2001
From: Richard Linden <none@none>
Date: Wed, 7 Apr 2010 10:17:05 -0700
Subject: EXT-4885 -  [DnD] cannot drag slurls from Google Chrome into SL on
 windows

---
 indra/newview/llviewerwindow.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'indra/newview')

diff --git a/indra/newview/llviewerwindow.cpp b/indra/newview/llviewerwindow.cpp
index ae3f680cbf..81033485ee 100644
--- a/indra/newview/llviewerwindow.cpp
+++ b/indra/newview/llviewerwindow.cpp
@@ -838,7 +838,7 @@ LLWindowCallbacks::DragNDropResult LLViewerWindow::handleDragNDrop( LLWindow *wi
 							LLPanelLogin::refreshLocation( true );
 							LLPanelLogin::updateLocationUI();
 						}
-						return LLWindowCallbacks::DND_MOVE;
+						return LLWindowCallbacks::DND_COPY;
 					};
 				}
 
-- 
cgit v1.2.3


From 03b0c60ff5c0f458d6979a14bb3518461970e7a4 Mon Sep 17 00:00:00 2001
From: Xiaohong Bao <bao@lindenlab.com>
Date: Wed, 7 Apr 2010 11:51:41 -0600
Subject: fix for all wierd crashes happening to lltexturecache.cpp, cuased by
 running viewer 2.0 and viewer 1.23 at the same time. Specifically for the
 following jiras: EXT-6692: crash at
 LLTextureCache::readEntryFromHeaderImmediately [secondlife-bin
 lltexturecache.cpp:1145] EXT-6691: crash at
 LLTextureCache::writeEntryToHeaderImmediately [secondlife-bin
 lltexturecache.cpp:1126] possible fix for EXT-6567: crash at
 LLImageBase::allocateData [secondlife-bin llimage.cpp:170]

---
 indra/newview/llappviewer.cpp    | 73 +++++++++++++++++++++++++---------------
 indra/newview/llappviewer.h      |  2 ++
 indra/newview/lltexturecache.cpp | 59 ++++++++++++++++++++++++++------
 indra/newview/lltexturecache.h   |  3 +-
 4 files changed, 97 insertions(+), 40 deletions(-)

(limited to 'indra/newview')

diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp
index 2a355474b1..fa241a49d2 100644
--- a/indra/newview/llappviewer.cpp
+++ b/indra/newview/llappviewer.cpp
@@ -2966,41 +2966,59 @@ void LLAppViewer::migrateCacheDirectory()
 #endif // LL_WINDOWS || LL_DARWIN
 }
 
+//static
+S32 LLAppViewer::getCacheVersion() 
+{
+	static const S32 cache_version = 7;
+
+	return cache_version ;
+}
+
 bool LLAppViewer::initCache()
 {
 	mPurgeCache = false;
-	// Purge cache if user requested it
-	if (gSavedSettings.getBOOL("PurgeCacheOnStartup") ||
-		gSavedSettings.getBOOL("PurgeCacheOnNextStartup"))
+	BOOL disable_texture_cache = FALSE ;
+	BOOL read_only = mSecondInstance ? TRUE : FALSE;
+	LLAppViewer::getTextureCache()->setReadOnly(read_only) ;
+
+	if (gSavedSettings.getS32("LocalCacheVersion") != LLAppViewer::getCacheVersion()) 
 	{
-		gSavedSettings.setBOOL("PurgeCacheOnNextStartup", false);
-		mPurgeCache = true;
+		if(read_only) 
+		{
+			disable_texture_cache = TRUE ; //if the cache version of this viewer is different from the running one, this viewer can not use the texture cache.
+		}
+		else
+		{
+			mPurgeCache = true; // Purge cache if the version number is different.
+			gSavedSettings.setS32("LocalCacheVersion", LLAppViewer::getCacheVersion());
+		}
 	}
-	// Purge cache if it belongs to an old version
-	else
+
+	if(!read_only)
 	{
-		static const S32 cache_version = 6;
-		if (gSavedSettings.getS32("LocalCacheVersion") != cache_version)
+		// Purge cache if user requested it
+		if (gSavedSettings.getBOOL("PurgeCacheOnStartup") ||
+			gSavedSettings.getBOOL("PurgeCacheOnNextStartup"))
 		{
+			gSavedSettings.setBOOL("PurgeCacheOnNextStartup", false);
 			mPurgeCache = true;
-			gSavedSettings.setS32("LocalCacheVersion", cache_version);
 		}
-	}
 	
-	// We have moved the location of the cache directory over time.
-	migrateCacheDirectory();
-
-	// Setup and verify the cache location
-	std::string cache_location = gSavedSettings.getString("CacheLocation");
-	std::string new_cache_location = gSavedSettings.getString("NewCacheLocation");
-	if (new_cache_location != cache_location)
-	{
-		gDirUtilp->setCacheDir(gSavedSettings.getString("CacheLocation"));
-		purgeCache(); // purge old cache
-		gSavedSettings.setString("CacheLocation", new_cache_location);
-		gSavedSettings.setString("CacheLocationTopFolder", gDirUtilp->getBaseFileName(new_cache_location));
-	}
+		// We have moved the location of the cache directory over time.
+		migrateCacheDirectory();
 	
+		// Setup and verify the cache location
+		std::string cache_location = gSavedSettings.getString("CacheLocation");
+		std::string new_cache_location = gSavedSettings.getString("NewCacheLocation");
+		if (new_cache_location != cache_location)
+		{
+			gDirUtilp->setCacheDir(gSavedSettings.getString("CacheLocation"));
+			purgeCache(); // purge old cache
+			gSavedSettings.setString("CacheLocation", new_cache_location);
+			gSavedSettings.setString("CacheLocationTopFolder", gDirUtilp->getBaseFileName(new_cache_location));
+		}
+	}
+
 	if (!gDirUtilp->setCacheDir(gSavedSettings.getString("CacheLocation")))
 	{
 		LL_WARNS("AppCache") << "Unable to set cache location" << LL_ENDL;
@@ -3008,7 +3026,7 @@ bool LLAppViewer::initCache()
 		gSavedSettings.setString("CacheLocationTopFolder", "");
 	}
 	
-	if (mPurgeCache)
+	if (mPurgeCache && !read_only)
 	{
 		LLSplashScreen::update(LLTrans::getString("StartupClearingCache"));
 		purgeCache();
@@ -3017,14 +3035,13 @@ bool LLAppViewer::initCache()
 	LLSplashScreen::update(LLTrans::getString("StartupInitializingTextureCache"));
 	
 	// Init the texture cache
-	// Allocate 80% of the cache size for textures
-	BOOL read_only = mSecondInstance ? TRUE : FALSE;
+	// Allocate 80% of the cache size for textures	
 	const S32 MB = 1024*1024;
 	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);
-	S64 extra = LLAppViewer::getTextureCache()->initCache(LL_PATH_CACHE, texture_cache_size, read_only);
+	S64 extra = LLAppViewer::getTextureCache()->initCache(LL_PATH_CACHE, texture_cache_size, disable_texture_cache);
 	texture_cache_size -= extra;
 
 	LLSplashScreen::update(LLTrans::getString("StartupInitializingVFS"));
diff --git a/indra/newview/llappviewer.h b/indra/newview/llappviewer.h
index 27e8bec1d5..5acd6e11c4 100644
--- a/indra/newview/llappviewer.h
+++ b/indra/newview/llappviewer.h
@@ -102,6 +102,8 @@ public:
 	static LLImageDecodeThread* getImageDecodeThread() { return sImageDecodeThread; }
 	static LLTextureFetch* getTextureFetch() { return sTextureFetch; }
 
+	static S32 getCacheVersion() ;
+
 	const std::string& getSerialNumber() { return mSerialNumber; }
 	
 	bool getPurgeCache() const { return mPurgeCache; }
diff --git a/indra/newview/lltexturecache.cpp b/indra/newview/lltexturecache.cpp
index 651070a2ea..df79725474 100644
--- a/indra/newview/lltexturecache.cpp
+++ b/indra/newview/lltexturecache.cpp
@@ -742,7 +742,7 @@ LLTextureCache::LLTextureCache(bool threaded)
 	  mHeaderMutex(NULL),
 	  mListMutex(NULL),
 	  mHeaderAPRFile(NULL),
-	  mReadOnly(FALSE),
+	  mReadOnly(TRUE), //do not allow to change the texture cache until setReadOnly() is called.
 	  mTexturesSizeTotal(0),
 	  mDoPurge(FALSE)
 {
@@ -929,13 +929,16 @@ U32 LLTextureCache::sCacheMaxEntries = MAX_REASONABLE_FILE_SIZE / TEXTURE_CACHE_
 S64 LLTextureCache::sCacheMaxTexturesSize = 0; // no limit
 const char* entries_filename = "texture.entries";
 const char* cache_filename = "texture.cache";
-const char* textures_dirname = "textures";
+const char* old_textures_dirname = "textures";
+//change the location of the texture cache to prevent from being deleted by old version viewers.
+const char* textures_dirname = "texturecache";
 
 void LLTextureCache::setDirNames(ELLPath location)
 {
 	std::string delem = gDirUtilp->getDirDelimiter();
-	mHeaderEntriesFileName = gDirUtilp->getExpandedFilename(location, entries_filename);
-	mHeaderDataFileName = gDirUtilp->getExpandedFilename(location, cache_filename);
+
+	mHeaderEntriesFileName = gDirUtilp->getExpandedFilename(location, textures_dirname, entries_filename);
+	mHeaderDataFileName = gDirUtilp->getExpandedFilename(location, textures_dirname, cache_filename);
 	mTexturesDirName = gDirUtilp->getExpandedFilename(location, textures_dirname);
 }
 
@@ -947,16 +950,38 @@ void LLTextureCache::purgeCache(ELLPath location)
 	{
 		setDirNames(location);
 		llassert_always(mHeaderAPRFile == NULL);
-		LLAPRFile::remove(mHeaderEntriesFileName, getLocalAPRFilePool());
-		LLAPRFile::remove(mHeaderDataFileName, getLocalAPRFilePool());
+
+		//remove the legacy cache if exists
+		std::string texture_dir = mTexturesDirName ;
+		mTexturesDirName = gDirUtilp->getExpandedFilename(location, old_textures_dirname);
+		if(LLFile::isdir(mTexturesDirName))
+		{
+			std::string file_name = gDirUtilp->getExpandedFilename(location, entries_filename);
+			LLAPRFile::remove(file_name, getLocalAPRFilePool());
+
+			file_name = gDirUtilp->getExpandedFilename(location, cache_filename);
+			LLAPRFile::remove(file_name, getLocalAPRFilePool());
+
+			purgeAllTextures(true);
+		}
+		mTexturesDirName = texture_dir ;
 	}
+
+	//remove the current texture cache.
 	purgeAllTextures(true);
 }
 
-S64 LLTextureCache::initCache(ELLPath location, S64 max_size, BOOL read_only)
+//is called in the main thread before initCache(...) is called.
+void LLTextureCache::setReadOnly(BOOL read_only)
 {
-	mReadOnly = read_only;
-	
+	mReadOnly = read_only ;
+}
+
+//called in the main thread.
+S64 LLTextureCache::initCache(ELLPath location, S64 max_size, BOOL disable_texture_cache)
+{
+	llassert_always(getPending() == 0) ; //should not start accessing the texture cache before initialized.
+
 	S64 header_size = (max_size * 2) / 10;
 	S64 max_entries = header_size / TEXTURE_CACHE_ENTRY_SIZE;
 	sCacheMaxEntries = (S32)(llmin((S64)sCacheMaxEntries, max_entries));
@@ -968,6 +993,15 @@ S64 LLTextureCache::initCache(ELLPath location, S64 max_size, BOOL read_only)
 		sCacheMaxTexturesSize = max_size;
 	max_size -= sCacheMaxTexturesSize;
 	
+	if(disable_texture_cache) //the texture cache is disabled
+	{
+		llinfos << "The texture cache is disabled!" << llendl ;
+		setReadOnly(TRUE) ;
+		purgeAllTextures(true); 
+
+		return max_size ;
+	}
+
 	LL_INFOS("TextureCache") << "Headers: " << sCacheMaxEntries
 			<< " Textures size: " << sCacheMaxTexturesSize/(1024*1024) << " MB" << LL_ENDL;
 
@@ -976,6 +1010,7 @@ S64 LLTextureCache::initCache(ELLPath location, S64 max_size, BOOL read_only)
 	if (!mReadOnly)
 	{
 		LLFile::mkdir(mTexturesDirName);
+		
 		const char* subdirs = "0123456789abcdef";
 		for (S32 i=0; i<16; i++)
 		{
@@ -986,6 +1021,8 @@ S64 LLTextureCache::initCache(ELLPath location, S64 max_size, BOOL read_only)
 	readHeaderCache();
 	purgeTextures(true); // calc mTexturesSize and make some room in the texture cache if we need it
 
+	llassert_always(getPending() == 0) ; //should not start accessing the texture cache before initialized.
+
 	return max_size; // unused cache space
 }
 
@@ -1462,9 +1499,9 @@ void LLTextureCache::purgeAllTextures(bool purge_directories)
 		}
 		if (purge_directories)
 		{
-			gDirUtilp->deleteFilesInDir(mTexturesDirName,mask);
+			gDirUtilp->deleteFilesInDir(mTexturesDirName, mask);
 			LLFile::rmdir(mTexturesDirName);
-		}
+		}		
 	}
 	mHeaderIDMap.clear();
 	mTexturesSizeMap.clear();
diff --git a/indra/newview/lltexturecache.h b/indra/newview/lltexturecache.h
index ca8815ee7e..5dc06ff401 100644
--- a/indra/newview/lltexturecache.h
+++ b/indra/newview/lltexturecache.h
@@ -110,7 +110,8 @@ public:
 	/*virtual*/ S32 update(U32 max_time_ms);	
 	
 	void purgeCache(ELLPath location);
-	S64 initCache(ELLPath location, S64 maxsize, BOOL read_only);
+	void setReadOnly(BOOL read_only) ;
+	S64 initCache(ELLPath location, S64 maxsize, BOOL disable_texture_cache);
 
 	handle_t readFromCache(const std::string& local_filename, const LLUUID& id, U32 priority, S32 offset, S32 size,
 						   ReadResponder* responder);
-- 
cgit v1.2.3