regedit: Convert AddEntryToTree to unicode.

This commit is contained in:
Alexander Nicolaysen Sørnes 2008-08-22 00:12:09 +02:00 committed by Alexandre Julliard
parent a6a4109dd4
commit 74cae34da8
1 changed files with 37 additions and 30 deletions

View File

@ -232,26 +232,30 @@ BOOL DeleteNode(HWND hwndTV, HTREEITEM hItem)
} }
/* Add an entry to the tree. Only give hKey for root nodes (HKEY_ constants) */ /* Add an entry to the tree. Only give hKey for root nodes (HKEY_ constants) */
static HTREEITEM AddEntryToTree(HWND hwndTV, HTREEITEM hParent, LPTSTR label, HKEY hKey, DWORD dwChildren) static HTREEITEM AddEntryToTree(HWND hwndTV, HTREEITEM hParent, LPWSTR label, HKEY hKey, DWORD dwChildren)
{ {
TVINSERTSTRUCT tvins; TVINSERTSTRUCT tvins;
CHAR* labelA = GetMultiByteString(label);
HTREEITEM ret;
if (hKey) { if (hKey) {
if (RegQueryInfoKey(hKey, 0, 0, 0, &dwChildren, 0, 0, 0, 0, 0, 0, 0) != ERROR_SUCCESS) { if (RegQueryInfoKeyW(hKey, 0, 0, 0, &dwChildren, 0, 0, 0, 0, 0, 0, 0) != ERROR_SUCCESS) {
dwChildren = 0; dwChildren = 0;
} }
} }
tvins.u.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN | TVIF_PARAM; tvins.u.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN | TVIF_PARAM;
tvins.u.item.pszText = label; tvins.u.item.pszText = labelA;
tvins.u.item.cchTextMax = lstrlen(label); tvins.u.item.cchTextMax = lstrlen(labelA);
tvins.u.item.iImage = Image_Closed; tvins.u.item.iImage = Image_Closed;
tvins.u.item.iSelectedImage = Image_Open; tvins.u.item.iSelectedImage = Image_Open;
tvins.u.item.cChildren = dwChildren; tvins.u.item.cChildren = dwChildren;
tvins.u.item.lParam = (LPARAM)hKey; tvins.u.item.lParam = (LPARAM)hKey;
tvins.hInsertAfter = (HTREEITEM)(hKey ? TVI_LAST : TVI_SORT); tvins.hInsertAfter = (HTREEITEM)(hKey ? TVI_LAST : TVI_SORT);
tvins.hParent = hParent; tvins.hParent = hParent;
return TreeView_InsertItem(hwndTV, &tvins); ret = TreeView_InsertItem(hwndTV, &tvins);
HeapFree(GetProcessHeap(), 0, labelA);
return ret;
} }
static BOOL match_string(LPCTSTR sstring1, LPCTSTR sstring2, int mode) static BOOL match_string(LPCTSTR sstring1, LPCTSTR sstring2, int mode)
@ -388,20 +392,20 @@ static BOOL RefreshTreeItem(HWND hwndTV, HTREEITEM hItem)
{ {
HKEY hRoot, hKey, hSubKey; HKEY hRoot, hKey, hSubKey;
HTREEITEM childItem; HTREEITEM childItem;
LPTSTR KeyPath; LPWSTR KeyPath;
DWORD dwCount, dwIndex, dwMaxSubKeyLen; DWORD dwCount, dwIndex, dwMaxSubKeyLen;
LPSTR Name; LPWSTR Name;
TVITEM tvItem; TVITEM tvItem;
hRoot = NULL; hRoot = NULL;
KeyPath = GetItemPath(hwndTV, hItem, &hRoot); KeyPath = GetItemPathW(hwndTV, hItem, &hRoot);
if (!KeyPath || !hRoot) if (!KeyPath || !hRoot)
return FALSE; return FALSE;
if (*KeyPath) { if (*KeyPath) {
if (RegOpenKeyEx(hRoot, KeyPath, 0, KEY_READ, &hKey) != ERROR_SUCCESS) { if (RegOpenKeyExW(hRoot, KeyPath, 0, KEY_READ, &hKey) != ERROR_SUCCESS) {
WINE_TRACE("RegOpenKeyEx failed, \"%s\" was probably removed.\n", KeyPath); WINE_TRACE("RegOpenKeyEx failed, %s was probably removed.\n", wine_dbgstr_w(KeyPath));
return FALSE; return FALSE;
} }
} else { } else {
@ -409,7 +413,7 @@ static BOOL RefreshTreeItem(HWND hwndTV, HTREEITEM hItem)
} }
HeapFree(GetProcessHeap(), 0, KeyPath); HeapFree(GetProcessHeap(), 0, KeyPath);
if (RegQueryInfoKey(hKey, 0, 0, 0, &dwCount, &dwMaxSubKeyLen, 0, 0, 0, 0, 0, 0) != ERROR_SUCCESS) { if (RegQueryInfoKeyW(hKey, 0, 0, 0, &dwCount, &dwMaxSubKeyLen, 0, 0, 0, 0, 0, 0) != ERROR_SUCCESS) {
return FALSE; return FALSE;
} }
@ -428,7 +432,7 @@ static BOOL RefreshTreeItem(HWND hwndTV, HTREEITEM hItem)
} }
dwMaxSubKeyLen++; /* account for the \0 terminator */ dwMaxSubKeyLen++; /* account for the \0 terminator */
if (!(Name = HeapAlloc(GetProcessHeap(), 0, dwMaxSubKeyLen * sizeof(TCHAR)))) { if (!(Name = HeapAlloc(GetProcessHeap(), 0, dwMaxSubKeyLen * sizeof(WCHAR)))) {
return FALSE; return FALSE;
} }
tvItem.cchTextMax = dwMaxSubKeyLen; tvItem.cchTextMax = dwMaxSubKeyLen;
@ -440,38 +444,43 @@ static BOOL RefreshTreeItem(HWND hwndTV, HTREEITEM hItem)
for (dwIndex = 0; dwIndex < dwCount; dwIndex++) { for (dwIndex = 0; dwIndex < dwCount; dwIndex++) {
DWORD cName = dwMaxSubKeyLen, dwSubCount; DWORD cName = dwMaxSubKeyLen, dwSubCount;
BOOL found; BOOL found;
CHAR* NameA;
found = FALSE; found = FALSE;
if (RegEnumKeyEx(hKey, dwIndex, Name, &cName, 0, 0, 0, NULL) != ERROR_SUCCESS) { if (RegEnumKeyExW(hKey, dwIndex, Name, &cName, 0, 0, 0, NULL) != ERROR_SUCCESS) {
continue; continue;
} }
/* Find the number of children of the node. */ /* Find the number of children of the node. */
dwSubCount = 0; dwSubCount = 0;
if (RegOpenKeyEx(hKey, Name, 0, KEY_QUERY_VALUE, &hSubKey) == ERROR_SUCCESS) { if (RegOpenKeyExW(hKey, Name, 0, KEY_QUERY_VALUE, &hSubKey) == ERROR_SUCCESS) {
if (RegQueryInfoKey(hSubKey, 0, 0, 0, &dwSubCount, 0, 0, 0, 0, 0, 0, 0) != ERROR_SUCCESS) { if (RegQueryInfoKey(hSubKey, 0, 0, 0, &dwSubCount, 0, 0, 0, 0, 0, 0, 0) != ERROR_SUCCESS) {
dwSubCount = 0; dwSubCount = 0;
} }
RegCloseKey(hSubKey); RegCloseKey(hSubKey);
} }
NameA = GetMultiByteString(Name);
/* Check if the node is already in there. */ /* Check if the node is already in there. */
for (childItem = TreeView_GetChild(hwndTV, hItem); childItem; for (childItem = TreeView_GetChild(hwndTV, hItem); childItem;
childItem = TreeView_GetNextSibling(hwndTV, childItem)) { childItem = TreeView_GetNextSibling(hwndTV, childItem)) {
tvItem.mask = TVIF_TEXT; tvItem.mask = TVIF_TEXT;
tvItem.hItem = childItem; tvItem.hItem = childItem;
if (!TreeView_GetItem(hwndTV, &tvItem)) { if (!TreeView_GetItem(hwndTV, &tvItem)) {
HeapFree(GetProcessHeap(), 0, NameA);
return FALSE; return FALSE;
} }
if (!stricmp(tvItem.pszText, Name)) { if (!stricmp(tvItem.pszText, NameA)) {
found = TRUE; found = TRUE;
HeapFree(GetProcessHeap(), 0, NameA);
break; break;
} }
} }
if (found == FALSE) { if (found == FALSE) {
WINE_TRACE("New subkey %s\n", Name); WINE_TRACE("New subkey %s\n", NameA);
AddEntryToTree(hwndTV, hItem, Name, NULL, dwSubCount); AddEntryToTree(hwndTV, hItem, Name, NULL, dwSubCount);
} }
} }
@ -527,9 +536,7 @@ HTREEITEM InsertNode(HWND hwndTV, HTREEITEM hItem, LPWSTR name)
if (!hItem) hItem = TreeView_GetSelection(hwndTV); if (!hItem) hItem = TreeView_GetSelection(hwndTV);
if (!hItem) return FALSE; if (!hItem) return FALSE;
if (TreeView_GetItemState(hwndTV, hItem, TVIS_EXPANDEDONCE)) { if (TreeView_GetItemState(hwndTV, hItem, TVIS_EXPANDEDONCE)) {
char* nameA = GetMultiByteString(name); hNewItem = AddEntryToTree(hwndTV, hItem, name, 0, 0);
hNewItem = AddEntryToTree(hwndTV, hItem, nameA, 0, 0);
HeapFree(GetProcessHeap(), 0, nameA);
} else { } else {
item.mask = TVIF_CHILDREN | TVIF_HANDLE; item.mask = TVIF_CHILDREN | TVIF_HANDLE;
item.hItem = hItem; item.hItem = hItem;
@ -568,7 +575,7 @@ static BOOL InitTreeViewItems(HWND hwndTV, LPTSTR pHostName)
{ {
TVINSERTSTRUCT tvins; TVINSERTSTRUCT tvins;
HTREEITEM hRoot; HTREEITEM hRoot;
static TCHAR hkcr[] = {'H','K','E','Y','_','C','L','A','S','S','E','S','_','R','O','O','T',0}, static WCHAR hkcr[] = {'H','K','E','Y','_','C','L','A','S','S','E','S','_','R','O','O','T',0},
hkcu[] = {'H','K','E','Y','_','C','U','R','R','E','N','T','_','U','S','E','R',0}, hkcu[] = {'H','K','E','Y','_','C','U','R','R','E','N','T','_','U','S','E','R',0},
hklm[] = {'H','K','E','Y','_','L','O','C','A','L','_','M','A','C','H','I','N','E',0}, hklm[] = {'H','K','E','Y','_','L','O','C','A','L','_','M','A','C','H','I','N','E',0},
hku[] = {'H','K','E','Y','_','U','S','E','R','S',0}, hku[] = {'H','K','E','Y','_','U','S','E','R','S',0},
@ -646,8 +653,8 @@ BOOL UpdateExpandingTree(HWND hwndTV, HTREEITEM hItem, int state)
{ {
DWORD dwCount, dwIndex, dwMaxSubKeyLen; DWORD dwCount, dwIndex, dwMaxSubKeyLen;
HKEY hRoot, hNewKey, hKey; HKEY hRoot, hNewKey, hKey;
LPTSTR keyPath; LPWSTR keyPath;
LPTSTR Name; LPWSTR Name;
LONG errCode; LONG errCode;
HCURSOR hcursorOld; HCURSOR hcursorOld;
@ -658,32 +665,32 @@ BOOL UpdateExpandingTree(HWND hwndTV, HTREEITEM hItem, int state)
} }
expanding = TRUE; expanding = TRUE;
hcursorOld = SetCursor(LoadCursor(NULL, IDC_WAIT)); hcursorOld = SetCursor(LoadCursor(NULL, IDC_WAIT));
SendMessage(hwndTV, WM_SETREDRAW, FALSE, 0); SendMessageW(hwndTV, WM_SETREDRAW, FALSE, 0);
keyPath = GetItemPath(hwndTV, hItem, &hRoot); keyPath = GetItemPathW(hwndTV, hItem, &hRoot);
if (!keyPath) goto done; if (!keyPath) goto done;
if (*keyPath) { if (*keyPath) {
errCode = RegOpenKeyEx(hRoot, keyPath, 0, KEY_READ, &hNewKey); errCode = RegOpenKeyExW(hRoot, keyPath, 0, KEY_READ, &hNewKey);
if (errCode != ERROR_SUCCESS) goto done; if (errCode != ERROR_SUCCESS) goto done;
} else { } else {
hNewKey = hRoot; hNewKey = hRoot;
} }
errCode = RegQueryInfoKey(hNewKey, 0, 0, 0, &dwCount, &dwMaxSubKeyLen, 0, 0, 0, 0, 0, 0); errCode = RegQueryInfoKeyW(hNewKey, 0, 0, 0, &dwCount, &dwMaxSubKeyLen, 0, 0, 0, 0, 0, 0);
if (errCode != ERROR_SUCCESS) goto done; if (errCode != ERROR_SUCCESS) goto done;
dwMaxSubKeyLen++; /* account for the \0 terminator */ dwMaxSubKeyLen++; /* account for the \0 terminator */
Name = HeapAlloc(GetProcessHeap(), 0, dwMaxSubKeyLen * sizeof(TCHAR)); Name = HeapAlloc(GetProcessHeap(), 0, dwMaxSubKeyLen * sizeof(WCHAR));
if (!Name) goto done; if (!Name) goto done;
for (dwIndex = 0; dwIndex < dwCount; dwIndex++) { for (dwIndex = 0; dwIndex < dwCount; dwIndex++) {
DWORD cName = dwMaxSubKeyLen, dwSubCount; DWORD cName = dwMaxSubKeyLen, dwSubCount;
errCode = RegEnumKeyEx(hNewKey, dwIndex, Name, &cName, 0, 0, 0, 0); errCode = RegEnumKeyExW(hNewKey, dwIndex, Name, &cName, 0, 0, 0, 0);
if (errCode != ERROR_SUCCESS) continue; if (errCode != ERROR_SUCCESS) continue;
errCode = RegOpenKeyEx(hNewKey, Name, 0, KEY_QUERY_VALUE, &hKey); errCode = RegOpenKeyExW(hNewKey, Name, 0, KEY_QUERY_VALUE, &hKey);
if (errCode == ERROR_SUCCESS) { if (errCode == ERROR_SUCCESS) {
errCode = RegQueryInfoKey(hKey, 0, 0, 0, &dwSubCount, 0, 0, 0, 0, 0, 0, 0); errCode = RegQueryInfoKeyW(hKey, 0, 0, 0, &dwSubCount, 0, 0, 0, 0, 0, 0, 0);
RegCloseKey(hKey); RegCloseKey(hKey);
} }
if (errCode != ERROR_SUCCESS) dwSubCount = 0; if (errCode != ERROR_SUCCESS) dwSubCount = 0;