From 3b03ffbd70bff48a747f9f3a45056069724fc42f Mon Sep 17 00:00:00 2001
From: Ima Mechanique <ima.mechanique@secondlife.com>
Date: Sat, 9 Nov 2013 11:39:53 +0000
Subject: [PATCH] Changing method openKeywordFile to loadKeywordFileIntoLLSD to
 load cached/default syntax file and method to access sKeyWordsXML.

loadKeywordFileIntoLLSD was taken almost verbatim from LLKeywords::loadIntoLLSD which can be removed later.
I know the name is long but I wanted to remember where it came from and why it is how it is.
Removed a little cruft also.
---
 indra/newview/llsyntaxid.cpp | 47 ++++++++++++++++++++++++++++++------
 indra/newview/llsyntaxid.h   |  4 ++-
 2 files changed, 42 insertions(+), 9 deletions(-)

diff --git a/indra/newview/llsyntaxid.cpp b/indra/newview/llsyntaxid.cpp
index 0249607834e..00e60865465 100644
--- a/indra/newview/llsyntaxid.cpp
+++ b/indra/newview/llsyntaxid.cpp
@@ -248,7 +248,7 @@ void LLSyntaxIdLSL::initialise()
 				LL_WARNS("LSLSyntax")
 						<< "Filename is cached, no need to download!"
 						<< LL_ENDL;
-				openKeywordsFile();
+				loadKeywordsFileIntoLLSD();
 			}
 		}
 		else
@@ -256,27 +256,58 @@ void LLSyntaxIdLSL::initialise()
 			LL_WARNS("LSLSyntax")
 					<< "ID is null so SyntaxID does not need to be processed!"
 					<< LL_ENDL;
-			openKeywordsFile();
+			loadKeywordsFileIntoLLSD();
 		}
-		// TODO add a signal here to tell the editor the hash has changed?
+		mFileNameCurrent = mFileNameNew;
+		mSyntaxIdCurrent = mSyntaxIdNew;
 	}
 	else
 	{
 		LL_WARNS("LSLSyntax")
 				<< "No change to Syntax! Nothing to see here. Move along now!"
 				<< LL_ENDL;
-
 	}
-	//LLEnvManagerNew::instance().setRegionChangeCallback(boost::bind(&LLSyntaxIdLSL::checkSyntaxIdChange(), this));
 }
 
 //-----------------------------------------------------------------------------
-// openKeywordsFile
+// loadKeywordsFileIntoLLSD
 //-----------------------------------------------------------------------------
-void LLSyntaxIdLSL::openKeywordsFile()
+/**
+ * @brief	Load xml serialised LLSD
+ * @desc	Opens the specified filespec and attempts to deserialise the
+ *			contained data to the specified LLSD object.
+ * @return	Returns boolean true/false indicating success or failure.
+ */
+bool LLSyntaxIdLSL::loadKeywordsFileIntoLLSD()
 {
 	LL_WARNS("LSLSyntax")
 			<< "Trying to open default or cached keyword file ;-)"
 			<< LL_ENDL;
-	// TODO Open the file and load LLSD into sKeywordsXml
+
+	bool loaded = false;
+	LLSD content;
+	llifstream file;
+	file.open(mFullFileSpec);
+	if (file.is_open())
+	{
+		loaded = (bool)LLSDSerialize::fromXML(content, file);
+		if (!loaded)
+		{
+			LL_WARNS("LSLSyntax") << "Unable to deserialise file: " << filename << LL_ENDL;
+
+			// Is this the right thing to do, or should we leave the old content
+			// even if it isn't entirely accurate anymore?
+			sKeywordsXml = LLSD.emptyMap();
+		}
+		else
+		{
+			sKeywordsXml = content;
+			LL_INFOS("LSLSyntax") << "Deserialised file: " << filename << LL_ENDL;
+		}
+	}
+	else
+	{
+		LL_WARNS("LSLSyntax") << "Unable to open file: " << filename << LL_ENDL;
+	}
+	return loaded;
 }
diff --git a/indra/newview/llsyntaxid.h b/indra/newview/llsyntaxid.h
index d9f25728635..50013a83801 100644
--- a/indra/newview/llsyntaxid.h
+++ b/indra/newview/llsyntaxid.h
@@ -39,6 +39,7 @@ class LLSyntaxIdLSL
 	bool			checkSyntaxIdChanged();
 	std::string		getFileNameCurrent()	const { return mFileNameCurrent; }
 	ELLPath			getFilePath()			const { return mFilePath; }
+	LLSD			getKeywordsXML()		const { return sKeywordsXml; }
 	LLUUID			getSyntaxId()			const { return mSyntaxIdCurrent; }
 
 	void			initialise();
@@ -50,7 +51,8 @@ class LLSyntaxIdLSL
 	std::string		buildFileNameNew();
 	std::string		buildFullFileSpec();
 	void			fetchKeywordsFile();
-	void			openKeywordsFile();
+	//void			openKeywordsFile();
+	bool			loadKeywordsFileIntoLLSD();
 	void			setSyntaxId(LLUUID SyntaxId) { mSyntaxIdCurrent = SyntaxId; }
 	void			setFileNameCurrent(std::string& name) { mFileNameCurrent = name; }
 	void			setFileNameDefault(std::string& name) { mFileNameDefault = name; }
-- 
GitLab