regedit: Re-implement favourite registry key handling.

Signed-off-by: Hugh McMaster <hugh.mcmaster@outlook.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Hugh McMaster 2017-06-05 00:57:53 +00:00 committed by Alexandre Julliard
parent 1a5561c0cf
commit 27b2519ca4
3 changed files with 57 additions and 44 deletions

View File

@ -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)
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);
}
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);
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);

View File

@ -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

View File

@ -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);