[PATCH] regedit: Make FindPathInTree return tree root on invalid path

Jakub Bartmiński jakub.bartm at gmail.com
Mon Apr 3 14:39:46 CDT 2017


Fixes https://bugs.winehq.org/show_bug.cgi?id=39856

FindPathInTree currently returns the first child of a tree when given
an invalid path. Because of this, if the 'LastKey' entry is invalid
(as a result of a language change, or being manually edited), the
registry defaults to a different key than on Windows.

Signed-off-by: Jakub Bartmiński <jakub.bartm at gmail.com>
---
 programs/regedit/treeview.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/programs/regedit/treeview.c b/programs/regedit/treeview.c
index 378657d..4b5e1ca 100644
--- a/programs/regedit/treeview.c
+++ b/programs/regedit/treeview.c
@@ -132,13 +132,16 @@ static LPWSTR get_path_component(LPCWSTR *lplpKeyName) {
 HTREEITEM FindPathInTree(HWND hwndTV, LPCWSTR lpKeyName) {
     TVITEMEXW tvi;
     WCHAR buf[261]; /* tree view has 260 character limitation on item name */
-    HTREEITEM hItem, hOldItem;
+    HTREEITEM hRoot, hItem, hOldItem;
+    BOOL valid_path;
 
     buf[260] = '\0';
-    hItem = (HTREEITEM)SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_ROOT, 0);
+    hRoot = (HTREEITEM)SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_ROOT, 0);
+    hItem = hRoot;
     SendMessageW(hwndTV, TVM_EXPAND, TVE_EXPAND, (LPARAM)hItem );
     hItem = (HTREEITEM)SendMessageW(hwndTV, TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)hItem);
     hOldItem = hItem;
+    valid_path = FALSE;
     while(1) {
         LPWSTR lpItemName = get_path_component(&lpKeyName);
 
@@ -150,6 +153,7 @@ HTREEITEM FindPathInTree(HWND hwndTV, LPCWSTR lpKeyName) {
                 tvi.cchTextMax = 260;
                 SendMessageW(hwndTV, TVM_GETITEMW, 0, (LPARAM) &tvi);
                 if (!lstrcmpiW(tvi.pszText, lpItemName)) {
+                     valid_path = TRUE;
                      SendMessageW(hwndTV, TVM_EXPAND, TVE_EXPAND, (LPARAM)hItem );
                      if (!lpKeyName)
                      {
@@ -164,10 +168,10 @@ HTREEITEM FindPathInTree(HWND hwndTV, LPCWSTR lpKeyName) {
             }
             HeapFree(GetProcessHeap(), 0, lpItemName);
             if (!hItem)
-                return hOldItem;
+                return valid_path ? hOldItem : hRoot;
         }
         else
-            return hItem;
+            return valid_path ? hItem : hRoot;
     }
 }
 
-- 
1.9.1




More information about the wine-patches mailing list