Commit 27b2519c authored by Hugh McMaster's avatar Hugh McMaster Committed by Alexandre Julliard

regedit: Re-implement favourite registry key handling.

parent 1a5561c0
...@@ -198,38 +198,55 @@ static void UpdateMenuItems(HMENU hMenu) { ...@@ -198,38 +198,55 @@ static void UpdateMenuItems(HMENU hMenu) {
HeapFree(GetProcessHeap(), 0, keyName); 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;
HKEY hKey; LONG rc;
while(GetMenuItemCount(hMenu)>2) DWORD num_values, max_value_len, value_len, type, i;
DeleteMenu(hMenu, 2, MF_BYPOSITION); WCHAR *value_name;
if (RegOpenKeyExW(HKEY_CURRENT_USER, favoritesKey,
0, KEY_READ, &hKey) == ERROR_SUCCESS) { rc = RegOpenKeyExW(HKEY_CURRENT_USER, favoritesKey, 0, KEY_READ, &hkey);
WCHAR namebuf[KEY_MAX_LEN]; if (rc != ERROR_SUCCESS) return;
BYTE valuebuf[4096];
int i = 0; rc = RegQueryInfoKeyW(hkey, NULL, NULL, NULL, NULL, NULL, NULL, &num_values,
BOOL sep = FALSE; &max_value_len, NULL, NULL, NULL);
DWORD ksize, vsize, type; if (rc != ERROR_SUCCESS)
LONG error; {
do { ERR("RegQueryInfoKey failed: %d\n", rc);
ksize = KEY_MAX_LEN; goto exit;
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); if (!num_values) goto exit;
RegCloseKey(hKey);
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);
add_favourite_key_menu_items(hMenu);
} }
UpdateMenuItems(hMenu); UpdateMenuItems(hMenu);
} }
...@@ -1056,7 +1073,7 @@ LRESULT CALLBACK FrameWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa ...@@ -1056,7 +1073,7 @@ LRESULT CALLBACK FrameWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa
break; break;
case WM_INITMENUPOPUP: case WM_INITMENUPOPUP:
if (!HIWORD(lParam)) if (!HIWORD(lParam))
OnInitMenuPopup(hWnd, (HMENU)wParam, LOWORD(lParam)); OnInitMenuPopup(hWnd, (HMENU)wParam);
break; break;
case WM_MENUSELECT: case WM_MENUSELECT:
OnMenuSelect(hWnd, LOWORD(wParam), HIWORD(wParam), (HMENU)lParam); OnMenuSelect(hWnd, LOWORD(wParam), HIWORD(wParam), (HMENU)lParam);
......
...@@ -50,19 +50,6 @@ static HKEY reg_class_keys[] = { ...@@ -50,19 +50,6 @@ static HKEY reg_class_keys[] = {
#define ARRAY_SIZE(A) (sizeof(A)/sizeof(*A)) #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 * Allocates memory and converts input from multibyte to wide chars
* Returned string must be freed by the caller * Returned string must be freed by the caller
......
...@@ -24,6 +24,15 @@ ...@@ -24,6 +24,15 @@
#define REG_FORMAT_5 1 #define REG_FORMAT_5 1
#define REG_FORMAT_4 2 #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, ...); void __cdecl output_message(unsigned int id, ...);
BOOL export_registry_key(WCHAR *file_name, WCHAR *reg_key_name, DWORD format); BOOL export_registry_key(WCHAR *file_name, WCHAR *reg_key_name, DWORD format);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment