From c8f761fe939fdfe15474ae8e4e6826a1ba4bcdd6 Mon Sep 17 00:00:00 2001
From: Mnikolenko Productengine <mnikolenko@productengine.com>
Date: Mon, 10 Jan 2022 18:52:18 +0200
Subject: SL-15083 Add 'DiskCacheVersion' to keep 'filesystem cache' in check

---
 indra/newview/app_settings/settings.xml | 11 +++++++++++
 indra/newview/llappviewer.cpp           | 17 ++++++++++++++++-
 indra/newview/llappviewer.h             |  1 +
 3 files changed, 28 insertions(+), 1 deletion(-)

(limited to 'indra/newview')

diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml
index 91370f7da3..94d6448c5f 100644
--- a/indra/newview/app_settings/settings.xml
+++ b/indra/newview/app_settings/settings.xml
@@ -5795,6 +5795,17 @@
       <key>Value</key>
       <integer>0</integer>
     </map>
+    <key>DiskCacheVersion</key>
+    <map>
+      <key>Comment</key>
+      <string>Version number of disk cache</string>
+      <key>Persist</key>
+      <integer>1</integer>
+      <key>Type</key>
+      <string>S32</string>
+      <key>Value</key>
+      <integer>0</integer>
+    </map>
     <key>LocalFileSystemBrowsingEnabled</key>
     <map>
       <key>Comment</key>
diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp
index f3f74ee3af..26fa93f492 100644
--- a/indra/newview/llappviewer.cpp
+++ b/indra/newview/llappviewer.cpp
@@ -4178,6 +4178,15 @@ U32 LLAppViewer::getTextureCacheVersion()
 	return TEXTURE_CACHE_VERSION ;
 }
 
+//static
+U32 LLAppViewer::getDiskCacheVersion()
+{
+    // Viewer disk cache version intorduced in Simple Cache Viewer, change if the cache format changes.
+    const U32 DISK_CACHE_VERSION = 1;
+
+    return DISK_CACHE_VERSION ;
+}
+
 //static
 U32 LLAppViewer::getObjectCacheVersion()
 {
@@ -4258,7 +4267,13 @@ bool LLAppViewer::initCache()
 
 	if (!read_only)
 	{
-		if (mPurgeCache)
+        if (gSavedSettings.getS32("DiskCacheVersion") != LLAppViewer::getDiskCacheVersion())
+        {
+            LLDiskCache::getInstance()->clearCache();
+            gSavedSettings.setS32("DiskCacheVersion", LLAppViewer::getDiskCacheVersion());
+        }
+        
+        if (mPurgeCache)
 		{
 			LLSplashScreen::update(LLTrans::getString("StartupClearingCache"));
 			purgeCache();
diff --git a/indra/newview/llappviewer.h b/indra/newview/llappviewer.h
index 0f06889d20..271307f2a3 100644
--- a/indra/newview/llappviewer.h
+++ b/indra/newview/llappviewer.h
@@ -122,6 +122,7 @@ public:
 
 	static U32 getTextureCacheVersion() ;
 	static U32 getObjectCacheVersion() ;
+    static U32 getDiskCacheVersion() ;
 
 	const std::string& getSerialNumber() { return mSerialNumber; }
 	
-- 
cgit v1.2.3