regedit: Convert deletion to unicode.
This commit is contained in:
parent
e0df1b9e57
commit
04929756e7
|
@ -386,22 +386,23 @@ done:
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL DeleteKey(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath)
|
BOOL DeleteKey(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath)
|
||||||
{
|
{
|
||||||
BOOL result = FALSE;
|
BOOL result = FALSE;
|
||||||
LONG lRet;
|
LONG lRet;
|
||||||
HKEY hKey;
|
HKEY hKey;
|
||||||
|
CHAR* keyPathA = GetMultiByteString(keyPath);
|
||||||
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) {
|
if (lRet != ERROR_SUCCESS) {
|
||||||
error_code_messagebox(hwnd, lRet);
|
error_code_messagebox(hwnd, lRet);
|
||||||
return FALSE;
|
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;
|
goto done;
|
||||||
|
|
||||||
lRet = SHDeleteKey(hKeyRoot, keyPath);
|
lRet = SHDeleteKeyW(hKeyRoot, keyPath);
|
||||||
if (lRet != ERROR_SUCCESS) {
|
if (lRet != ERROR_SUCCESS) {
|
||||||
error(hwnd, IDS_BAD_KEY, keyPath);
|
error(hwnd, IDS_BAD_KEY, keyPath);
|
||||||
goto done;
|
goto done;
|
||||||
|
@ -410,24 +411,33 @@ BOOL DeleteKey(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath)
|
||||||
|
|
||||||
done:
|
done:
|
||||||
RegCloseKey(hKey);
|
RegCloseKey(hKey);
|
||||||
|
HeapFree(GetProcessHeap(), 0, keyPathA);
|
||||||
return result;
|
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;
|
BOOL result = FALSE;
|
||||||
LONG lRet;
|
LONG lRet;
|
||||||
HKEY hKey;
|
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 (lRet != ERROR_SUCCESS) return FALSE;
|
||||||
|
|
||||||
if (showMessageBox)
|
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;
|
goto done;
|
||||||
|
}
|
||||||
|
HeapFree(GetProcessHeap(), 0, visibleValueNameA);
|
||||||
|
}
|
||||||
|
|
||||||
lRet = RegDeleteValue(hKey, valueName ? valueName : "");
|
lRet = RegDeleteValueW(hKey, valueName ? valueName : &empty);
|
||||||
if (lRet != ERROR_SUCCESS && valueName) {
|
if (lRet != ERROR_SUCCESS && valueName) {
|
||||||
error(hwnd, IDS_BAD_VALUE, valueName);
|
error(hwnd, IDS_BAD_VALUE, valueName);
|
||||||
}
|
}
|
||||||
|
|
|
@ -675,29 +675,38 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
break;
|
break;
|
||||||
case ID_EDIT_DELETE:
|
case ID_EDIT_DELETE:
|
||||||
if (GetFocus() == g_pChildWnd->hTreeWnd) {
|
if (GetFocus() == g_pChildWnd->hTreeWnd) {
|
||||||
|
WCHAR* keyPathW = GetWideString(keyPath);
|
||||||
if (keyPath == 0 || *keyPath == 0) {
|
if (keyPath == 0 || *keyPath == 0) {
|
||||||
MessageBeep(MB_ICONHAND);
|
MessageBeep(MB_ICONHAND);
|
||||||
} else if (DeleteKey(hWnd, hKeyRoot, keyPath)) {
|
} else if (DeleteKey(hWnd, hKeyRoot, keyPathW)) {
|
||||||
DeleteNode(g_pChildWnd->hTreeWnd, 0);
|
DeleteNode(g_pChildWnd->hTreeWnd, 0);
|
||||||
}
|
}
|
||||||
|
HeapFree(GetProcessHeap(), 0, keyPathW);
|
||||||
} else if (GetFocus() == g_pChildWnd->hListWnd) {
|
} else if (GetFocus() == g_pChildWnd->hListWnd) {
|
||||||
curIndex = ListView_GetNextItem(g_pChildWnd->hListWnd, -1, LVNI_SELECTED);
|
curIndex = ListView_GetNextItem(g_pChildWnd->hListWnd, -1, LVNI_SELECTED);
|
||||||
while(curIndex != -1) {
|
while(curIndex != -1) {
|
||||||
|
WCHAR* valueNameW;
|
||||||
|
WCHAR* keyPathW;
|
||||||
|
|
||||||
valueName = GetItemText(g_pChildWnd->hListWnd, curIndex);
|
valueName = GetItemText(g_pChildWnd->hListWnd, curIndex);
|
||||||
curIndex = ListView_GetNextItem(g_pChildWnd->hListWnd, curIndex, LVNI_SELECTED);
|
curIndex = ListView_GetNextItem(g_pChildWnd->hListWnd, curIndex, LVNI_SELECTED);
|
||||||
if(curIndex != -1 && firstItem) {
|
if(curIndex != -1 && firstItem) {
|
||||||
TCHAR title[256];
|
if (MessageBoxW(hWnd, MAKEINTRESOURCEW(IDS_DELETE_BOX_TEXT_MULTIPLE),
|
||||||
TCHAR text[1024];
|
MAKEINTRESOURCEW(IDS_DELETE_BOX_TITLE),
|
||||||
if(!LoadString(hInst, IDS_DELETE_BOX_TITLE, title, COUNT_OF(title)))
|
MB_YESNO | MB_ICONEXCLAMATION) != IDYES)
|
||||||
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)
|
|
||||||
break;
|
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;
|
break;
|
||||||
|
}
|
||||||
firstItem = FALSE;
|
firstItem = FALSE;
|
||||||
|
HeapFree(GetProcessHeap(), 0, valueNameW);
|
||||||
|
HeapFree(GetProcessHeap(), 0, keyPathW);
|
||||||
}
|
}
|
||||||
RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath, NULL);
|
RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath, NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
TCHAR g_pszDefaultValueName[64];
|
TCHAR g_pszDefaultValueName[64];
|
||||||
|
WCHAR g_pszDefaultValueNameW[64];
|
||||||
|
|
||||||
BOOL ProcessCmdLine(LPSTR lpCmdLine);
|
BOOL ProcessCmdLine(LPSTR lpCmdLine);
|
||||||
|
|
||||||
|
@ -171,6 +172,7 @@ int APIENTRY WinMain(HINSTANCE hInstance,
|
||||||
/* Initialize global strings */
|
/* Initialize global strings */
|
||||||
LoadString(hInstance, IDS_APP_TITLE, szTitle, COUNT_OF(szTitle));
|
LoadString(hInstance, IDS_APP_TITLE, szTitle, COUNT_OF(szTitle));
|
||||||
LoadString(hInstance, IDS_REGISTRY_DEFAULT_VALUE, g_pszDefaultValueName, COUNT_OF(g_pszDefaultValueName));
|
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 */
|
/* Store instance handle in our global variable */
|
||||||
hInst = hInstance;
|
hInst = hInstance;
|
||||||
|
|
|
@ -91,6 +91,7 @@ extern TCHAR szTitle[];
|
||||||
extern const TCHAR szFrameClass[];
|
extern const TCHAR szFrameClass[];
|
||||||
extern const TCHAR szChildClass[];
|
extern const TCHAR szChildClass[];
|
||||||
extern TCHAR g_pszDefaultValueName[];
|
extern TCHAR g_pszDefaultValueName[];
|
||||||
|
extern WCHAR g_pszDefaultValueNameW[];
|
||||||
|
|
||||||
/* about.c */
|
/* about.c */
|
||||||
extern void ShowAboutBox(HWND hWnd);
|
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 CreateKey(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath, LPTSTR newKeyName);
|
||||||
extern BOOL CreateValue(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath, DWORD valueType, LPTSTR valueName);
|
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 ModifyValue(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath, LPCTSTR valueName);
|
||||||
extern BOOL DeleteKey(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath);
|
extern BOOL DeleteKey(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath);
|
||||||
extern BOOL DeleteValue(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath, LPCTSTR valueName, BOOL showMessageBox);
|
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 RenameValue(HWND hwnd, HKEY hRootKey, LPCTSTR keyPath, LPCTSTR oldName, LPCTSTR newName);
|
||||||
extern BOOL RenameKey(HWND hwnd, HKEY hRootKey, LPCTSTR keyPath, LPCTSTR newName);
|
extern BOOL RenameKey(HWND hwnd, HKEY hRootKey, LPCTSTR keyPath, LPCTSTR newName);
|
||||||
extern void error(HWND hwnd, INT resId, ...);
|
extern void error(HWND hwnd, INT resId, ...);
|
||||||
|
|
|
@ -25,3 +25,4 @@ BOOL export_registry_key(CHAR *file_name, CHAR *reg_key_name);
|
||||||
BOOL import_registry_file(FILE *in);
|
BOOL import_registry_file(FILE *in);
|
||||||
void delete_registry_key(WCHAR *reg_key_name);
|
void delete_registry_key(WCHAR *reg_key_name);
|
||||||
WCHAR* GetWideString(const char* strA);
|
WCHAR* GetWideString(const char* strA);
|
||||||
|
CHAR* GetMultiByteString(const WCHAR* strW);
|
||||||
|
|
Loading…
Reference in New Issue