From f4c3e0f464cb5cd7f664c5ea3a78db5557a43980 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Nicolaysen=20S=C3=B8rnes?= Date: Wed, 9 Jul 2008 18:18:14 +0200 Subject: [PATCH] regedit: Use unicode for all key deletion. --- programs/regedit/regedit.c | 6 ++++- programs/regedit/regproc.c | 46 ++++++++++++++------------------------ programs/regedit/regproc.h | 4 ++-- 3 files changed, 24 insertions(+), 32 deletions(-) diff --git a/programs/regedit/regedit.c b/programs/regedit/regedit.c index ea8aee95d18..fca0cacaa9e 100644 --- a/programs/regedit/regedit.c +++ b/programs/regedit/regedit.c @@ -186,8 +186,12 @@ static BOOL PerformRegAction(REGEDIT_ACTION action, LPSTR s) getAppName()); fprintf(stderr,usage); exit(1); + } else + { + WCHAR* reg_key_nameW = GetWideString(reg_key_name, lstrlenA(reg_key_name)+1); + delete_registry_key(reg_key_nameW); + HeapFree(GetProcessHeap(), 0, reg_key_nameW); } - delete_registry_key(reg_key_name); break; } case ACTION_EXPORT: { diff --git a/programs/regedit/regproc.c b/programs/regedit/regproc.c index a169889e303..7101e3a575a 100644 --- a/programs/regedit/regproc.c +++ b/programs/regedit/regproc.c @@ -74,6 +74,20 @@ if (!(p)) \ exit(NOT_ENOUGH_MEMORY); \ } +/****************************************************************************** + * Allocates memory and convers input from multibyte to wide chars + * Returned string must be freed by the caller + */ +WCHAR* GetWideString(char* strA, int len) +{ + WCHAR* strW = NULL; + + strW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); + CHECK_ENOUGH_MEMORY(strW); + MultiByteToWideChar(CP_ACP, 0, strA, len, strW, len); + return strW; +} + /****************************************************************************** * Allocates memory and convers input from wide chars to multibyte * Returned string must be freed by the caller @@ -529,12 +543,8 @@ static void processRegEntry(LPSTR stdInput) /* delete the key if we encounter '-' at the start of reg key */ if ( stdInput[0] == '-') { - WCHAR* stdInputW = NULL; - int size = keyEnd - stdInput - 1; - stdInputW = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size * sizeof(WCHAR)); - CHECK_ENOUGH_MEMORY(stdInputW); - MultiByteToWideChar(CP_ACP, 0, stdInput + 1, size, stdInputW, size); - delete_registry_keyW(stdInputW); + WCHAR* stdInputW = GetWideString(stdInput + 1, keyEnd - stdInput); + delete_registry_key(stdInputW); HeapFree(GetProcessHeap(), 0, stdInputW); } else if ( openKey(stdInput) != ERROR_SUCCESS ) { @@ -1062,29 +1072,7 @@ BOOL import_registry_file(LPTSTR filename) * reg_key_name - full name of registry branch to delete. Ignored if is NULL, * empty, points to register key class, does not exist. */ -void delete_registry_key(CHAR *reg_key_name) -{ - CHAR *key_name; - HKEY key_class; - - if (!reg_key_name || !reg_key_name[0]) - return; - - if (!parseKeyName(reg_key_name, &key_class, &key_name)) { - fprintf(stderr,"%s: Incorrect registry class specification in '%s'\n", - getAppName(), reg_key_name); - exit(1); - } - if (!*key_name) { - fprintf(stderr,"%s: Can't delete registry class '%s'\n", - getAppName(), reg_key_name); - exit(1); - } - - RegDeleteTreeA(key_class, key_name); -} - -void delete_registry_keyW(WCHAR *reg_key_name) +void delete_registry_key(WCHAR *reg_key_name) { WCHAR *key_name = NULL; HKEY key_class; diff --git a/programs/regedit/regproc.h b/programs/regedit/regproc.h index 59e1b0cf2d0..9faf8b14670 100644 --- a/programs/regedit/regproc.h +++ b/programs/regedit/regproc.h @@ -23,6 +23,6 @@ const CHAR *getAppName(void); BOOL export_registry_key(CHAR *file_name, CHAR *reg_key_name); BOOL import_registry_file(LPTSTR filename); -void delete_registry_key(CHAR *reg_key_name); -void delete_registry_keyW(WCHAR *reg_key_name); +void delete_registry_key(WCHAR *reg_key_name); +WCHAR* GetWideString(char* strA, int len); void processRegLines(FILE *in);