From d72fcfba57c02f2577f3b4f3d132ddfa515dd894 Mon Sep 17 00:00:00 2001
From: andreykproductengine <andreykproductengine@lindenlab.com>
Date: Thu, 13 Jun 2019 19:00:20 +0300
Subject: [PATCH] SL-11402 Resaving home image if file does not exist

---
 indra/newview/llagent.cpp     | 17 +++++++++++++++++
 indra/newview/llagent.h       |  2 ++
 indra/newview/llappviewer.cpp | 29 ++++++++++++++++++++++++++++-
 3 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/indra/newview/llagent.cpp b/indra/newview/llagent.cpp
index 4bd3ca91573..925cec08713 100644
--- a/indra/newview/llagent.cpp
+++ b/indra/newview/llagent.cpp
@@ -3709,6 +3709,23 @@ BOOL LLAgent::getHomePosGlobal( LLVector3d* pos_global )
 	return TRUE;
 }
 
+bool LLAgent::isInHomeRegion()
+{
+	if(!mHaveHomePosition)
+	{
+		return false;
+	}
+	if (!getRegion())
+	{
+		return false;
+	}
+	if (getRegion()->getHandle() != mHomeRegionHandle)
+	{
+		return false;
+	}
+	return true;
+}
+
 void LLAgent::clearVisualParams(void *data)
 {
 	if (isAgentAvatarValid())
diff --git a/indra/newview/llagent.h b/indra/newview/llagent.h
index ea6f68c482d..5ba1083d8ef 100644
--- a/indra/newview/llagent.h
+++ b/indra/newview/llagent.h
@@ -233,6 +233,8 @@ class LLAgent : public LLOldEvents::LLObservable
 	void			setStartPosition(U32 location_id); // Marks current location as start, sends information to servers
 	void			setHomePosRegion(const U64& region_handle, const LLVector3& pos_region);
 	BOOL			getHomePosGlobal(LLVector3d* pos_global);
+	bool			isInHomeRegion();
+
 private:
     void            setStartPositionSuccess(const LLSD &result);
 
diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp
index f3915b9210d..c8dcbb87c1a 100644
--- a/indra/newview/llappviewer.cpp
+++ b/indra/newview/llappviewer.cpp
@@ -4507,8 +4507,35 @@ void LLAppViewer::saveFinalSnapshot()
 		snap_filename += gDirUtilp->getDirDelimiter();
 		snap_filename += LLStartUp::getScreenLastFilename();
 		// use full pixel dimensions of viewer window (not post-scale dimensions)
-		gViewerWindow->saveSnapshot(snap_filename, gViewerWindow->getWindowWidthRaw(), gViewerWindow->getWindowHeightRaw(), FALSE, TRUE, LLSnapshotModel::SNAPSHOT_TYPE_COLOR, LLSnapshotModel::SNAPSHOT_FORMAT_PNG);
+		gViewerWindow->saveSnapshot(snap_filename,
+									gViewerWindow->getWindowWidthRaw(),
+									gViewerWindow->getWindowHeightRaw(),
+									FALSE,
+									TRUE,
+									LLSnapshotModel::SNAPSHOT_TYPE_COLOR,
+									LLSnapshotModel::SNAPSHOT_FORMAT_PNG);
 		mSavedFinalSnapshot = TRUE;
+
+		if (gAgent.isInHomeRegion())
+		{
+			LLVector3d home;
+			if (gAgent.getHomePosGlobal(&home) && dist_vec(home, gAgent.getPositionGlobal()) < 10)
+			{
+				// We are at home position or close to it, see if we need to create home screenshot
+				// Notes:
+				// 1. It might be beneficial to also replace home if file is too old
+				// 2. This is far from best way/place to update screenshot since location might be not fully loaded,
+				// but we don't have many options
+				std::string snap_home = gDirUtilp->getLindenUserDir();
+				snap_home += gDirUtilp->getDirDelimiter();
+				snap_home += LLStartUp::getScreenHomeFilename();
+				if (!gDirUtilp->fileExists(snap_home))
+				{
+					// We are at home position yet no home image exist, fix it
+					LLFile::copy(snap_filename, snap_home);
+				}
+			}
+		}
 	}
 }
 
-- 
GitLab