Module: wine Branch: master Commit: 27b2519ca47192349fdcb5e09fe9eee10d00526f URL: http://source.winehq.org/git/wine.git/?a=commit;h=27b2519ca47192349fdcb5e09f...
Author: Hugh McMaster hugh.mcmaster@outlook.com Date: Mon Jun 5 00:57:53 2017 +0000
regedit: Re-implement favourite registry key handling.
Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
programs/regedit/framewnd.c | 77 +++++++++++++++++++++++++++------------------ programs/regedit/regproc.c | 13 -------- programs/regedit/regproc.h | 9 ++++++ 3 files changed, 56 insertions(+), 43 deletions(-)
diff --git a/programs/regedit/framewnd.c b/programs/regedit/framewnd.c index cd7dad0..e654d48 100644 --- a/programs/regedit/framewnd.c +++ b/programs/regedit/framewnd.c @@ -198,38 +198,55 @@ static void UpdateMenuItems(HMENU hMenu) { HeapFree(GetProcessHeap(), 0, keyName); }
-static void OnInitMenuPopup(HWND hWnd, HMENU hMenu, short wItem) +static void add_favourite_key_menu_items(HMENU hMenu) { - if (wItem == 3) { - HKEY hKey; - while(GetMenuItemCount(hMenu)>2) + HKEY hkey; + LONG rc; + DWORD num_values, max_value_len, value_len, type, i; + WCHAR *value_name; + + rc = RegOpenKeyExW(HKEY_CURRENT_USER, favoritesKey, 0, KEY_READ, &hkey); + if (rc != ERROR_SUCCESS) return; + + rc = RegQueryInfoKeyW(hkey, NULL, NULL, NULL, NULL, NULL, NULL, &num_values, + &max_value_len, NULL, NULL, NULL); + if (rc != ERROR_SUCCESS) + { + ERR("RegQueryInfoKey failed: %d\n", rc); + goto exit; + } + + if (!num_values) goto exit; + + max_value_len++; + value_name = HeapAlloc(GetProcessHeap(), 0, max_value_len * sizeof(WCHAR)); + CHECK_ENOUGH_MEMORY(value_name); + + AppendMenuW(hMenu, MF_SEPARATOR, 0, 0); + + for (i = 0; i < num_values; i++) + { + value_len = max_value_len; + rc = RegEnumValueW(hkey, i, value_name, &value_len, NULL, &type, NULL, NULL); + if (rc == ERROR_SUCCESS && type == REG_SZ) + AppendMenuW(hMenu, MF_ENABLED | MF_STRING, ID_FAVORITE_FIRST + i, value_name); + } + + HeapFree(GetProcessHeap(), 0, value_name); +exit: + RegCloseKey(hkey); +} + +static void OnInitMenuPopup(HWND hWnd, HMENU hMenu) +{ + if (hMenu == GetSubMenu(hMenuFrame, ID_FAVORITES_MENU)) + { + while (GetMenuItemCount(hMenu) > 2) DeleteMenu(hMenu, 2, MF_BYPOSITION); - if (RegOpenKeyExW(HKEY_CURRENT_USER, favoritesKey, - 0, KEY_READ, &hKey) == ERROR_SUCCESS) { - WCHAR namebuf[KEY_MAX_LEN]; - BYTE valuebuf[4096]; - int i = 0; - BOOL sep = FALSE; - DWORD ksize, vsize, type; - LONG error; - do { - ksize = KEY_MAX_LEN; - vsize = sizeof(valuebuf); - error = RegEnumValueW(hKey, i, namebuf, &ksize, NULL, &type, valuebuf, &vsize); - if (error != ERROR_SUCCESS) - break; - if (type == REG_SZ) { - if (!sep) { - AppendMenuW(hMenu, MF_SEPARATOR, -1, NULL); - sep = TRUE; - } - AppendMenuW(hMenu, MF_STRING, ID_FAVORITE_FIRST+i, namebuf); - } - i++; - } while(error == ERROR_SUCCESS); - RegCloseKey(hKey); - } + + add_favourite_key_menu_items(hMenu); } + UpdateMenuItems(hMenu); }
@@ -1056,7 +1073,7 @@ LRESULT CALLBACK FrameWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa break; case WM_INITMENUPOPUP: if (!HIWORD(lParam)) - OnInitMenuPopup(hWnd, (HMENU)wParam, LOWORD(lParam)); + OnInitMenuPopup(hWnd, (HMENU)wParam); break; case WM_MENUSELECT: OnMenuSelect(hWnd, LOWORD(wParam), HIWORD(wParam), (HMENU)lParam); diff --git a/programs/regedit/regproc.c b/programs/regedit/regproc.c index 10b4a38..d5be72f 100644 --- a/programs/regedit/regproc.c +++ b/programs/regedit/regproc.c @@ -50,19 +50,6 @@ static HKEY reg_class_keys[] = {
#define ARRAY_SIZE(A) (sizeof(A)/sizeof(*A))
-/* return values */ -#define NOT_ENOUGH_MEMORY 1 - -/* processing macros */ - -/* common check of memory allocation results */ -#define CHECK_ENOUGH_MEMORY(p) \ -if (!(p)) \ -{ \ - output_message(STRING_OUT_OF_MEMORY, __FILE__, __LINE__); \ - exit(NOT_ENOUGH_MEMORY); \ -} - /****************************************************************************** * Allocates memory and converts input from multibyte to wide chars * Returned string must be freed by the caller diff --git a/programs/regedit/regproc.h b/programs/regedit/regproc.h index aff4bee..72e6b38 100644 --- a/programs/regedit/regproc.h +++ b/programs/regedit/regproc.h @@ -24,6 +24,15 @@ #define REG_FORMAT_5 1 #define REG_FORMAT_4 2
+#define NOT_ENOUGH_MEMORY 1 + +#define CHECK_ENOUGH_MEMORY(p) \ +if (!(p)) \ +{ \ + output_message(STRING_OUT_OF_MEMORY, __FILE__, __LINE__); \ + exit(NOT_ENOUGH_MEMORY); \ +} + void __cdecl output_message(unsigned int id, ...);
BOOL export_registry_key(WCHAR *file_name, WCHAR *reg_key_name, DWORD format);