From fc90fee5087c91bb8c4c93b5e9508706e46bd409 Mon Sep 17 00:00:00 2001
From: Andrey Kleshchev <andreykproductengine@lindenlab.com>
Date: Fri, 4 Mar 2022 22:24:59 +0200
Subject: [PATCH] SL-16976 SL-443 Keybindings: Backward compatibility #3

---
 indra/newview/llkeyconflict.cpp | 17 ------------
 indra/newview/llviewerinput.cpp | 49 +++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 17 deletions(-)

diff --git a/indra/newview/llkeyconflict.cpp b/indra/newview/llkeyconflict.cpp
index 4c58c9e68c4..d3ba18525be 100644
--- a/indra/newview/llkeyconflict.cpp
+++ b/indra/newview/llkeyconflict.cpp
@@ -376,23 +376,6 @@ bool LLKeyConflictHandler::loadFromSettings(const ESourceMode &load_mode, const
             LL_ERRS() << "Not implememted mode " << load_mode << LL_ENDL;
             break;
         }
-
-        // verify version
-        if (keys.xml_version < 1)
-        {
-            // Updating from a version that was not aware of LMouse bindings.
-            // Assign defaults.
-            //
-            // mDefaultsMap is always going to have correct version so
-            // registerControl is usable, but using 'destination' just in case.
-            LLKeyConflict &type_data = (*destination)[script_mouse_handler_name];
-            LLKeyData data(CLICK_LEFT, KEY_NONE, MASK_NONE, true);
-            type_data.mKeyBind.replaceKeyData(data, 0);
-
-            // Mark this mode for an update, once user clicks 'OK' in preferences
-            // it should get saved
-            mHasUnsavedChanges = true;
-        }
     }
     return res;
 }
diff --git a/indra/newview/llviewerinput.cpp b/indra/newview/llviewerinput.cpp
index 1a08b1a56cb..43b9cd90bd6 100644
--- a/indra/newview/llviewerinput.cpp
+++ b/indra/newview/llviewerinput.cpp
@@ -1371,6 +1371,55 @@ S32 LLViewerInput::loadBindingsXML(const std::string& filename)
             {
                 mLMouseDefaultHandling[i] = true;
             }
+
+            // fix missing values
+            KeyBinding mouse_binding;
+            mouse_binding.key = "";
+            mouse_binding.mask = "NONE";
+            mouse_binding.mouse = "LMB";
+            mouse_binding.command = script_mouse_handler_name;
+
+            if (keys.third_person.isProvided())
+            {
+                keys.third_person.bindings.add(mouse_binding);
+            }
+
+            if (keys.first_person.isProvided())
+            {
+                keys.first_person.bindings.add(mouse_binding);
+            }
+
+            if (keys.sitting.isProvided())
+            {
+                keys.sitting.bindings.add(mouse_binding);
+            }
+
+            if (keys.edit_avatar.isProvided())
+            {
+                keys.edit_avatar.bindings.add(mouse_binding);
+            }
+
+            // fix version
+            keys.xml_version.set(keybindings_xml_version, true);
+
+            // Write the resulting XML to file
+            LLXMLNodePtr output_node = new LLXMLNode("keys", false);
+            LLXUIParser write_parser;
+            write_parser.writeXUI(output_node, keys);
+
+            if (!output_node->isNull())
+            {
+                // file in app_settings is supposed to be up to date
+                // this is only for the file from user_settings
+                LL_INFOS("ViewerInput") << "Updating file " << filename << " to a newer version" << LL_ENDL;
+                LLFILE *fp = LLFile::fopen(filename, "w");
+                if (fp != NULL)
+                {
+                    LLXMLNode::writeHeaderToFile(fp);
+                    output_node->writeToFile(fp);
+                    fclose(fp);
+                }
+            }
         }
 	}
 	return binding_count;
-- 
GitLab