regedit: Convert deletion to unicode.

This commit is contained in:
Alexander Nicolaysen Sørnes 2008-08-09 02:25:34 +02:00 committed by Alexandre Julliard
parent e0df1b9e57
commit 04929756e7
5 changed files with 44 additions and 21 deletions

View file

@ -386,22 +386,23 @@ done:
return result;
}
BOOL DeleteKey(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath)
BOOL DeleteKey(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath)
{
BOOL result = FALSE;
LONG lRet;
HKEY hKey;
lRet = RegOpenKeyEx(hKeyRoot, keyPath, 0, KEY_READ|KEY_SET_VALUE, &hKey);
CHAR* keyPathA = GetMultiByteString(keyPath);
lRet = RegOpenKeyExW(hKeyRoot, keyPath, 0, KEY_READ|KEY_SET_VALUE, &hKey);
if (lRet != ERROR_SUCCESS) {
error_code_messagebox(hwnd, lRet);
return FALSE;
}
if (messagebox(hwnd, MB_YESNO | MB_ICONEXCLAMATION, IDS_DELETE_BOX_TITLE, IDS_DELETE_BOX_TEXT, keyPath) != IDYES)
if (messagebox(hwnd, MB_YESNO | MB_ICONEXCLAMATION, IDS_DELETE_BOX_TITLE, IDS_DELETE_BOX_TEXT, keyPathA) != IDYES)
goto done;
lRet = SHDeleteKey(hKeyRoot, keyPath);
lRet = SHDeleteKeyW(hKeyRoot, keyPath);
if (lRet != ERROR_SUCCESS) {
error(hwnd, IDS_BAD_KEY, keyPath);
goto done;
@ -410,24 +411,33 @@ BOOL DeleteKey(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath)
done:
RegCloseKey(hKey);
HeapFree(GetProcessHeap(), 0, keyPathA);
return result;
}
BOOL DeleteValue(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath, LPCTSTR valueName, BOOL showMessageBox)
BOOL DeleteValue(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, LPCWSTR valueName, BOOL showMessageBox)
{
BOOL result = FALSE;
LONG lRet;
HKEY hKey;
LPCSTR visibleValueName = valueName ? valueName : g_pszDefaultValueName;
LPCWSTR visibleValueName = valueName ? valueName : g_pszDefaultValueNameW;
WCHAR empty = 0;
lRet = RegOpenKeyEx(hKeyRoot, keyPath, 0, KEY_READ | KEY_SET_VALUE, &hKey);
lRet = RegOpenKeyExW(hKeyRoot, keyPath, 0, KEY_READ | KEY_SET_VALUE, &hKey);
if (lRet != ERROR_SUCCESS) return FALSE;
if (showMessageBox)
if (messagebox(hwnd, MB_YESNO | MB_ICONEXCLAMATION, IDS_DELETE_BOX_TITLE, IDS_DELETE_BOX_TEXT, visibleValueName) != IDYES)
{
LPSTR visibleValueNameA = GetMultiByteString(visibleValueName);
if (messagebox(hwnd, MB_YESNO | MB_ICONEXCLAMATION, IDS_DELETE_BOX_TITLE, IDS_DELETE_BOX_TEXT, visibleValueNameA) != IDYES)
{
HeapFree(GetProcessHeap(), 0, visibleValueNameA);
goto done;
}
HeapFree(GetProcessHeap(), 0, visibleValueNameA);
}
lRet = RegDeleteValue(hKey, valueName ? valueName : "");
lRet = RegDeleteValueW(hKey, valueName ? valueName : &empty);
if (lRet != ERROR_SUCCESS && valueName) {
error(hwnd, IDS_BAD_VALUE, valueName);
}

View file

@ -675,29 +675,38 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
break;
case ID_EDIT_DELETE:
if (GetFocus() == g_pChildWnd->hTreeWnd) {
WCHAR* keyPathW = GetWideString(keyPath);
if (keyPath == 0 || *keyPath == 0) {
MessageBeep(MB_ICONHAND);
} else if (DeleteKey(hWnd, hKeyRoot, keyPath)) {
} else if (DeleteKey(hWnd, hKeyRoot, keyPathW)) {
DeleteNode(g_pChildWnd->hTreeWnd, 0);
}
HeapFree(GetProcessHeap(), 0, keyPathW);
} else if (GetFocus() == g_pChildWnd->hListWnd) {
curIndex = ListView_GetNextItem(g_pChildWnd->hListWnd, -1, LVNI_SELECTED);
while(curIndex != -1) {
WCHAR* valueNameW;
WCHAR* keyPathW;
valueName = GetItemText(g_pChildWnd->hListWnd, curIndex);
curIndex = ListView_GetNextItem(g_pChildWnd->hListWnd, curIndex, LVNI_SELECTED);
if(curIndex != -1 && firstItem) {
TCHAR title[256];
TCHAR text[1024];
if(!LoadString(hInst, IDS_DELETE_BOX_TITLE, title, COUNT_OF(title)))
lstrcpy(title, "Error");
if(!LoadString(hInst, IDS_DELETE_BOX_TEXT_MULTIPLE, text, COUNT_OF(text)))
lstrcpy(text, "Unknown error string!");
if (MessageBox(hWnd, text, title, MB_YESNO | MB_ICONEXCLAMATION) != IDYES)
if (MessageBoxW(hWnd, MAKEINTRESOURCEW(IDS_DELETE_BOX_TEXT_MULTIPLE),
MAKEINTRESOURCEW(IDS_DELETE_BOX_TITLE),
MB_YESNO | MB_ICONEXCLAMATION) != IDYES)
break;
}
if (!DeleteValue(hWnd, hKeyRoot, keyPath, valueName, curIndex==-1 && firstItem))
valueNameW = GetWideString(valueName);
keyPathW = GetWideString(keyPath);
if (!DeleteValue(hWnd, hKeyRoot, keyPathW, valueNameW, curIndex==-1 && firstItem))
{
HeapFree(GetProcessHeap(), 0, valueNameW);
HeapFree(GetProcessHeap(), 0, keyPathW);
break;
}
firstItem = FALSE;
HeapFree(GetProcessHeap(), 0, valueNameW);
HeapFree(GetProcessHeap(), 0, keyPathW);
}
RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath, NULL);
}

View file

@ -30,6 +30,7 @@
#include "main.h"
TCHAR g_pszDefaultValueName[64];
WCHAR g_pszDefaultValueNameW[64];
BOOL ProcessCmdLine(LPSTR lpCmdLine);
@ -171,6 +172,7 @@ int APIENTRY WinMain(HINSTANCE hInstance,
/* Initialize global strings */
LoadString(hInstance, IDS_APP_TITLE, szTitle, COUNT_OF(szTitle));
LoadString(hInstance, IDS_REGISTRY_DEFAULT_VALUE, g_pszDefaultValueName, COUNT_OF(g_pszDefaultValueName));
LoadStringW(hInstance, IDS_REGISTRY_DEFAULT_VALUE, g_pszDefaultValueNameW, COUNT_OF(g_pszDefaultValueNameW));
/* Store instance handle in our global variable */
hInst = hInstance;

View file

@ -91,6 +91,7 @@ extern TCHAR szTitle[];
extern const TCHAR szFrameClass[];
extern const TCHAR szChildClass[];
extern TCHAR g_pszDefaultValueName[];
extern WCHAR g_pszDefaultValueNameW[];
/* about.c */
extern void ShowAboutBox(HWND hWnd);
@ -129,8 +130,8 @@ extern HTREEITEM FindNext(HWND hwndTV, HTREEITEM hItem, LPCTSTR sstring, int mod
extern BOOL CreateKey(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath, LPTSTR newKeyName);
extern BOOL CreateValue(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath, DWORD valueType, LPTSTR valueName);
extern BOOL ModifyValue(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath, LPCTSTR valueName);
extern BOOL DeleteKey(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath);
extern BOOL DeleteValue(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath, LPCTSTR valueName, BOOL showMessageBox);
extern BOOL DeleteKey(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath);
extern BOOL DeleteValue(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, LPCWSTR valueName, BOOL showMessageBox);
extern BOOL RenameValue(HWND hwnd, HKEY hRootKey, LPCTSTR keyPath, LPCTSTR oldName, LPCTSTR newName);
extern BOOL RenameKey(HWND hwnd, HKEY hRootKey, LPCTSTR keyPath, LPCTSTR newName);
extern void error(HWND hwnd, INT resId, ...);

View file

@ -25,3 +25,4 @@ BOOL export_registry_key(CHAR *file_name, CHAR *reg_key_name);
BOOL import_registry_file(FILE *in);
void delete_registry_key(WCHAR *reg_key_name);
WCHAR* GetWideString(const char* strA);
CHAR* GetMultiByteString(const WCHAR* strW);