regedit: Convert key renaming to unicode.

This commit is contained in:
Alexander Nicolaysen Sørnes 2008-08-30 23:50:24 +02:00 committed by Alexandre Julliard
parent 4a3d8d8cb0
commit 6b7ebf0881
3 changed files with 34 additions and 28 deletions

View File

@ -25,6 +25,7 @@
#include <stdio.h> #include <stdio.h>
#include "main.h" #include "main.h"
#include "regproc.h"
#include "wine/debug.h" #include "wine/debug.h"
#include "wine/unicode.h" #include "wine/unicode.h"
@ -219,13 +220,13 @@ LPWSTR GetItemFullPathW(HWND hwndTV, HTREEITEM hItem, BOOL bFull) {
return ret; return ret;
} }
static LPTSTR GetPathFullPath(HWND hwndTV, LPTSTR path) { static LPWSTR GetPathFullPath(HWND hwndTV, LPWSTR path) {
LPTSTR parts[2]; LPWSTR parts[2];
LPTSTR ret; LPWSTR ret;
parts[0] = GetPathRoot(hwndTV, 0, TRUE); parts[0] = GetPathRootW(hwndTV, 0, TRUE);
parts[1] = path; parts[1] = path;
ret = CombinePaths((LPCTSTR *)parts, 2); ret = CombinePathsW((LPCWSTR*)parts, 2);
HeapFree(GetProcessHeap(), 0, parts[0]); HeapFree(GetProcessHeap(), 0, parts[0]);
return ret; return ret;
} }
@ -424,19 +425,22 @@ LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa
case TVN_ENDLABELEDIT: { case TVN_ENDLABELEDIT: {
HKEY hRootKey; HKEY hRootKey;
LPNMTVDISPINFO dispInfo = (LPNMTVDISPINFO)lParam; LPNMTVDISPINFO dispInfo = (LPNMTVDISPINFO)lParam;
LPCTSTR path = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hRootKey); WCHAR* itemText = GetWideString(dispInfo->item.pszText);
BOOL res = RenameKey(hWnd, hRootKey, path, dispInfo->item.pszText); LPWSTR path = GetItemPathW(g_pChildWnd->hTreeWnd, 0, &hRootKey);
BOOL res = RenameKey(hWnd, hRootKey, path, itemText);
if (res) { if (res) {
TVITEMEX item; TVITEMEXW item;
LPTSTR fullPath = GetPathFullPath(g_pChildWnd->hTreeWnd, LPWSTR fullPath = GetPathFullPath(g_pChildWnd->hTreeWnd,
dispInfo->item.pszText); itemText);
item.mask = TVIF_HANDLE | TVIF_TEXT; item.mask = TVIF_HANDLE | TVIF_TEXT;
item.hItem = TreeView_GetSelection(g_pChildWnd->hTreeWnd); item.hItem = TreeView_GetSelection(g_pChildWnd->hTreeWnd);
item.pszText = dispInfo->item.pszText; item.pszText = itemText;
SendMessage( g_pChildWnd->hTreeWnd, TVM_SETITEMW, 0, (LPARAM)&item ); SendMessageW( g_pChildWnd->hTreeWnd, TVM_SETITEMW, 0, (LPARAM)&item );
SendMessage(hStatusBar, SB_SETTEXT, 0, (LPARAM)fullPath); SendMessageW(hStatusBar, SB_SETTEXTW, 0, (LPARAM)fullPath);
HeapFree(GetProcessHeap(), 0, fullPath); HeapFree(GetProcessHeap(), 0, fullPath);
} }
HeapFree(GetProcessHeap(), 0, path);
HeapFree(GetProcessHeap(), 0, itemText);
return res; return res;
} }
default: default:

View File

@ -30,6 +30,7 @@
#include <shellapi.h> #include <shellapi.h>
#include <shlwapi.h> #include <shlwapi.h>
#include "wine/unicode.h"
#include "main.h" #include "main.h"
#include "regproc.h" #include "regproc.h"
#include "resource.h" #include "resource.h"
@ -536,10 +537,10 @@ done:
} }
BOOL RenameKey(HWND hwnd, HKEY hRootKey, LPCTSTR keyPath, LPCTSTR newName) BOOL RenameKey(HWND hwnd, HKEY hRootKey, LPCWSTR keyPath, LPCWSTR newName)
{ {
LPTSTR parentPath = 0; LPWSTR parentPath = 0;
LPCTSTR srcSubKey = 0; LPCWSTR srcSubKey = 0;
HKEY parentKey = 0; HKEY parentKey = 0;
HKEY destKey = 0; HKEY destKey = 0;
BOOL result = FALSE; BOOL result = FALSE;
@ -548,17 +549,18 @@ BOOL RenameKey(HWND hwnd, HKEY hRootKey, LPCTSTR keyPath, LPCTSTR newName)
if (!keyPath || !newName) return FALSE; if (!keyPath || !newName) return FALSE;
if (!strrchr(keyPath, '\\')) { if (!strrchrW(keyPath, '\\')) {
parentKey = hRootKey; parentKey = hRootKey;
srcSubKey = keyPath; srcSubKey = keyPath;
} else { } else {
LPTSTR srcSubKey_copy; LPWSTR srcSubKey_copy;
parentPath = strdup(keyPath); parentPath = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(keyPath)+1)*sizeof(WCHAR));
srcSubKey_copy = strrchr(parentPath, '\\'); lstrcpyW(parentPath, keyPath);
srcSubKey_copy = strrchrW(parentPath, '\\');
*srcSubKey_copy = 0; *srcSubKey_copy = 0;
srcSubKey = srcSubKey_copy + 1; srcSubKey = srcSubKey_copy + 1;
lRet = RegOpenKeyEx(hRootKey, parentPath, 0, KEY_READ | KEY_CREATE_SUB_KEY, &parentKey); lRet = RegOpenKeyExW(hRootKey, parentPath, 0, KEY_READ | KEY_CREATE_SUB_KEY, &parentKey);
if (lRet != ERROR_SUCCESS) { if (lRet != ERROR_SUCCESS) {
error_code_messagebox(hwnd, lRet); error_code_messagebox(hwnd, lRet);
goto done; goto done;
@ -566,9 +568,9 @@ BOOL RenameKey(HWND hwnd, HKEY hRootKey, LPCTSTR keyPath, LPCTSTR newName)
} }
/* The following fails if the old name is the same as the new name. */ /* The following fails if the old name is the same as the new name. */
if (!strcmp(srcSubKey, newName)) goto done; if (!lstrcmpW(srcSubKey, newName)) goto done;
lRet = RegCreateKeyEx(parentKey, newName, 0, NULL, REG_OPTION_NON_VOLATILE, lRet = RegCreateKeyExW(parentKey, newName, 0, NULL, REG_OPTION_NON_VOLATILE,
KEY_WRITE, NULL /* FIXME */, &destKey, &disposition); KEY_WRITE, NULL /* FIXME */, &destKey, &disposition);
if (disposition == REG_OPENED_EXISTING_KEY) if (disposition == REG_OPENED_EXISTING_KEY)
lRet = ERROR_FILE_EXISTS; /* FIXME: we might want a better error message than this */ lRet = ERROR_FILE_EXISTS; /* FIXME: we might want a better error message than this */
@ -578,15 +580,15 @@ BOOL RenameKey(HWND hwnd, HKEY hRootKey, LPCTSTR keyPath, LPCTSTR newName)
} }
/* FIXME: SHCopyKey does not copy the security attributes */ /* FIXME: SHCopyKey does not copy the security attributes */
lRet = SHCopyKey(parentKey, srcSubKey, destKey, 0); lRet = SHCopyKeyW(parentKey, srcSubKey, destKey, 0);
if (lRet != ERROR_SUCCESS) { if (lRet != ERROR_SUCCESS) {
RegCloseKey(destKey); RegCloseKey(destKey);
RegDeleteKey(parentKey, newName); RegDeleteKeyW(parentKey, newName);
error_code_messagebox(hwnd, lRet); error_code_messagebox(hwnd, lRet);
goto done; goto done;
} }
lRet = SHDeleteKey(hRootKey, keyPath); lRet = SHDeleteKeyW(hRootKey, keyPath);
if (lRet != ERROR_SUCCESS) { if (lRet != ERROR_SUCCESS) {
error_code_messagebox(hwnd, lRet); error_code_messagebox(hwnd, lRet);
goto done; goto done;
@ -598,7 +600,7 @@ done:
RegCloseKey(destKey); RegCloseKey(destKey);
if (parentKey) { if (parentKey) {
RegCloseKey(parentKey); RegCloseKey(parentKey);
free(parentPath); HeapFree(GetProcessHeap(), 0, parentPath);
} }
return result; return result;
} }

View File

@ -146,7 +146,7 @@ extern BOOL ModifyValue(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, LPCWSTR value
extern BOOL DeleteKey(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath); extern BOOL DeleteKey(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath);
extern BOOL DeleteValue(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, LPCWSTR valueName, BOOL showMessageBox); extern BOOL DeleteValue(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, LPCWSTR valueName, BOOL showMessageBox);
extern BOOL RenameValue(HWND hwnd, HKEY hRootKey, LPCWSTR keyPath, LPCWSTR oldName, LPCWSTR newName); extern BOOL RenameValue(HWND hwnd, HKEY hRootKey, LPCWSTR keyPath, LPCWSTR oldName, LPCWSTR newName);
extern BOOL RenameKey(HWND hwnd, HKEY hRootKey, LPCTSTR keyPath, LPCTSTR newName); extern BOOL RenameKey(HWND hwnd, HKEY hRootKey, LPCWSTR keyPath, LPCWSTR newName);
extern void error(HWND hwnd, INT resId, ...); extern void error(HWND hwnd, INT resId, ...);
/* hexedit.c */ /* hexedit.c */