Commit 1e56f949 authored by Alexander Nicolaysen Sørnes's avatar Alexander Nicolaysen Sørnes Committed by Alexandre Julliard

regedit: Convert value editing to unicode.

parent 377f14c7
...@@ -34,14 +34,14 @@ ...@@ -34,14 +34,14 @@
#include "regproc.h" #include "regproc.h"
#include "resource.h" #include "resource.h"
static const TCHAR* editValueName; static const WCHAR* editValueName;
static TCHAR* stringValueData; static WCHAR* stringValueData;
static BOOL isDecimal; static BOOL isDecimal;
struct edit_params struct edit_params
{ {
HKEY hKey; HKEY hKey;
LPCTSTR lpszValueName; LPCWSTR lpszValueName;
void *pData; void *pData;
LONG cbData; LONG cbData;
}; };
...@@ -114,14 +114,14 @@ static BOOL change_dword_base(HWND hwndDlg, BOOL toHex) ...@@ -114,14 +114,14 @@ static BOOL change_dword_base(HWND hwndDlg, BOOL toHex)
static INT_PTR CALLBACK modify_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) static INT_PTR CALLBACK modify_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
TCHAR* valueData; WCHAR* valueData;
HWND hwndValue; HWND hwndValue;
int len; int len;
switch(uMsg) { switch(uMsg) {
case WM_INITDIALOG: case WM_INITDIALOG:
SetDlgItemText(hwndDlg, IDC_VALUE_NAME, editValueName); SetDlgItemTextW(hwndDlg, IDC_VALUE_NAME, editValueName);
SetDlgItemText(hwndDlg, IDC_VALUE_DATA, stringValueData); SetDlgItemTextW(hwndDlg, IDC_VALUE_DATA, stringValueData);
CheckRadioButton(hwndDlg, IDC_DWORD_HEX, IDC_DWORD_DEC, isDecimal ? IDC_DWORD_DEC : IDC_DWORD_HEX); CheckRadioButton(hwndDlg, IDC_DWORD_HEX, IDC_DWORD_DEC, isDecimal ? IDC_DWORD_DEC : IDC_DWORD_HEX);
return TRUE; return TRUE;
case WM_COMMAND: case WM_COMMAND:
...@@ -134,10 +134,10 @@ static INT_PTR CALLBACK modify_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, L ...@@ -134,10 +134,10 @@ static INT_PTR CALLBACK modify_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, L
break; break;
case IDOK: case IDOK:
if ((hwndValue = GetDlgItem(hwndDlg, IDC_VALUE_DATA))) { if ((hwndValue = GetDlgItem(hwndDlg, IDC_VALUE_DATA))) {
len = GetWindowTextLength(hwndValue); len = GetWindowTextLengthW(hwndValue);
if ((valueData = HeapReAlloc(GetProcessHeap(), 0, stringValueData, (len + 1) * sizeof(TCHAR)))) { if ((valueData = HeapReAlloc(GetProcessHeap(), 0, stringValueData, (len + 1) * sizeof(WCHAR)))) {
stringValueData = valueData; stringValueData = valueData;
if (!GetWindowText(hwndValue, stringValueData, len + 1)) if (!GetWindowTextW(hwndValue, stringValueData, len + 1))
*stringValueData = 0; *stringValueData = 0;
} }
} }
...@@ -162,9 +162,9 @@ static INT_PTR CALLBACK bin_modify_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wPara ...@@ -162,9 +162,9 @@ static INT_PTR CALLBACK bin_modify_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wPara
params = (struct edit_params *)lParam; params = (struct edit_params *)lParam;
SetWindowLongPtr(hwndDlg, DWLP_USER, (ULONG_PTR)params); SetWindowLongPtr(hwndDlg, DWLP_USER, (ULONG_PTR)params);
if (params->lpszValueName) if (params->lpszValueName)
SetDlgItemText(hwndDlg, IDC_VALUE_NAME, params->lpszValueName); SetDlgItemTextW(hwndDlg, IDC_VALUE_NAME, params->lpszValueName);
else else
SetDlgItemText(hwndDlg, IDC_VALUE_NAME, g_pszDefaultValueName); SetDlgItemTextW(hwndDlg, IDC_VALUE_NAME, g_pszDefaultValueNameW);
SendDlgItemMessage(hwndDlg, IDC_VALUE_DATA, HEM_SETDATA, (WPARAM)params->cbData, (LPARAM)params->pData); SendDlgItemMessage(hwndDlg, IDC_VALUE_DATA, HEM_SETDATA, (WPARAM)params->cbData, (LPARAM)params->pData);
return TRUE; return TRUE;
case WM_COMMAND: case WM_COMMAND:
...@@ -176,8 +176,8 @@ static INT_PTR CALLBACK bin_modify_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wPara ...@@ -176,8 +176,8 @@ static INT_PTR CALLBACK bin_modify_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wPara
if (pData) if (pData)
{ {
SendDlgItemMessage(hwndDlg, IDC_VALUE_DATA, HEM_GETDATA, (WPARAM)cbData, (LPARAM)pData); SendDlgItemMessageW(hwndDlg, IDC_VALUE_DATA, HEM_GETDATA, (WPARAM)cbData, (LPARAM)pData);
lRet = RegSetValueEx(params->hKey, params->lpszValueName, 0, REG_BINARY, pData, cbData); lRet = RegSetValueExW(params->hKey, params->lpszValueName, 0, REG_BINARY, pData, cbData);
} }
else else
lRet = ERROR_OUTOFMEMORY; lRet = ERROR_OUTOFMEMORY;
...@@ -242,6 +242,45 @@ done: ...@@ -242,6 +242,45 @@ done:
return NULL; return NULL;
} }
static LPWSTR read_valueW(HWND hwnd, HKEY hKey, LPCWSTR valueName, DWORD *lpType, LONG *len)
{
DWORD valueDataLen;
LPWSTR buffer = NULL;
LONG lRet;
WCHAR empty = 0;
lRet = RegQueryValueExW(hKey, valueName ? valueName : &empty, 0, lpType, 0, &valueDataLen);
if (lRet != ERROR_SUCCESS) {
if (lRet == ERROR_FILE_NOT_FOUND && !valueName) { /* no default value here, make it up */
if (len) *len = 1;
if (lpType) *lpType = REG_SZ;
buffer = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR));
*buffer = '\0';
return buffer;
}
error(hwnd, IDS_BAD_VALUE, valueName);
goto done;
}
if ( *lpType == REG_DWORD ) valueDataLen = sizeof(DWORD);
if (!(buffer = HeapAlloc(GetProcessHeap(), 0, valueDataLen+sizeof(WCHAR)))) {
error(hwnd, IDS_TOO_BIG_VALUE, valueDataLen);
goto done;
}
lRet = RegQueryValueExW(hKey, valueName, 0, 0, (LPBYTE)buffer, &valueDataLen);
if (lRet != ERROR_SUCCESS) {
error(hwnd, IDS_BAD_VALUE, valueName);
goto done;
}
if((valueDataLen % sizeof(WCHAR)) == 0)
buffer[valueDataLen / sizeof(WCHAR)] = 0;
if(len) *len = valueDataLen;
return buffer;
done:
HeapFree(GetProcessHeap(), 0, buffer);
return NULL;
}
BOOL CreateKey(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, LPWSTR keyName) BOOL CreateKey(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, LPWSTR keyName)
{ {
BOOL result = FALSE; BOOL result = FALSE;
...@@ -281,7 +320,7 @@ done: ...@@ -281,7 +320,7 @@ done:
return result; return result;
} }
BOOL ModifyValue(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath, LPCTSTR valueName) BOOL ModifyValue(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, LPCWSTR valueName)
{ {
BOOL result = FALSE; BOOL result = FALSE;
DWORD type; DWORD type;
...@@ -289,30 +328,34 @@ BOOL ModifyValue(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath, LPCTSTR valueName) ...@@ -289,30 +328,34 @@ BOOL ModifyValue(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath, LPCTSTR valueName)
HKEY hKey; HKEY hKey;
LONG len; LONG len;
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;
} }
editValueName = valueName ? valueName : g_pszDefaultValueName; editValueName = valueName ? valueName : g_pszDefaultValueNameW;
if(!(stringValueData = read_value(hwnd, hKey, valueName, &type, &len))) goto done; if(!(stringValueData = read_valueW(hwnd, hKey, valueName, &type, &len))) goto done;
if ( (type == REG_SZ) || (type == REG_EXPAND_SZ) ) { if ( (type == REG_SZ) || (type == REG_EXPAND_SZ) ) {
if (DialogBox(0, MAKEINTRESOURCE(IDD_EDIT_STRING), hwnd, modify_dlgproc) == IDOK) { if (DialogBoxW(0, MAKEINTRESOURCEW(IDD_EDIT_STRING), hwnd, modify_dlgproc) == IDOK) {
lRet = RegSetValueEx(hKey, valueName, 0, type, (LPBYTE)stringValueData, lstrlen(stringValueData) + 1); lRet = RegSetValueExW(hKey, valueName, 0, type, (LPBYTE)stringValueData, (lstrlenW(stringValueData) + 1) * sizeof(WCHAR));
if (lRet == ERROR_SUCCESS) result = TRUE; if (lRet == ERROR_SUCCESS) result = TRUE;
else error_code_messagebox(hwnd, lRet); else error_code_messagebox(hwnd, lRet);
} }
} else if ( type == REG_DWORD ) { } else if ( type == REG_DWORD ) {
wsprintf(stringValueData, isDecimal ? "%u" : "%x", *((DWORD*)stringValueData)); const WCHAR u[] = {'%','u',0};
if (DialogBox(0, MAKEINTRESOURCE(IDD_EDIT_DWORD), hwnd, modify_dlgproc) == IDOK) { const WCHAR x[] = {'%','x',0};
wsprintfW(stringValueData, isDecimal ? u : x, *((DWORD*)stringValueData));
if (DialogBoxW(0, MAKEINTRESOURCEW(IDD_EDIT_DWORD), hwnd, modify_dlgproc) == IDOK) {
DWORD val; DWORD val;
if (_stscanf(stringValueData, isDecimal ? "%u" : "%x", &val)) { CHAR* valueA = GetMultiByteString(stringValueData);
lRet = RegSetValueEx(hKey, valueName, 0, type, (BYTE*)&val, sizeof(val)); if (_stscanf(valueA, isDecimal ? "%u" : "%x", &val)) {
lRet = RegSetValueExW(hKey, valueName, 0, type, (BYTE*)&val, sizeof(val));
if (lRet == ERROR_SUCCESS) result = TRUE; if (lRet == ERROR_SUCCESS) result = TRUE;
else error_code_messagebox(hwnd, lRet); else error_code_messagebox(hwnd, lRet);
} }
HeapFree(GetProcessHeap(), 0, valueA);
} }
} else if ( type == REG_BINARY ) { } else if ( type == REG_BINARY ) {
struct edit_params params; struct edit_params params;
...@@ -323,14 +366,14 @@ BOOL ModifyValue(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath, LPCTSTR valueName) ...@@ -323,14 +366,14 @@ BOOL ModifyValue(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath, LPCTSTR valueName)
result = DialogBoxParam(NULL, MAKEINTRESOURCE(IDD_EDIT_BINARY), hwnd, result = DialogBoxParam(NULL, MAKEINTRESOURCE(IDD_EDIT_BINARY), hwnd,
bin_modify_dlgproc, (LPARAM)&params); bin_modify_dlgproc, (LPARAM)&params);
} else if ( type == REG_MULTI_SZ ) { } else if ( type == REG_MULTI_SZ ) {
TCHAR char1 = (TCHAR)'\r', char2 = (TCHAR)'\n'; WCHAR char1 = '\r', char2 = '\n';
TCHAR *tmpValueData = NULL; WCHAR *tmpValueData = NULL;
INT i, j, count; INT i, j, count;
for ( i = 0, count = 0; i < len - 1; i++) for ( i = 0, count = 0; i < len - 1; i++)
if ( !stringValueData[i] && stringValueData[i + 1] ) if ( !stringValueData[i] && stringValueData[i + 1] )
count++; count++;
tmpValueData = HeapAlloc( GetProcessHeap(), 0, ( len + count ) * sizeof(TCHAR)); tmpValueData = HeapAlloc( GetProcessHeap(), 0, ( len + count ) * sizeof(WCHAR));
if ( !tmpValueData ) goto done; if ( !tmpValueData ) goto done;
for ( i = 0, j = 0; i < len - 1; i++) for ( i = 0, j = 0; i < len - 1; i++)
...@@ -348,10 +391,10 @@ BOOL ModifyValue(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath, LPCTSTR valueName) ...@@ -348,10 +391,10 @@ BOOL ModifyValue(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath, LPCTSTR valueName)
stringValueData = tmpValueData; stringValueData = tmpValueData;
tmpValueData = NULL; tmpValueData = NULL;
if (DialogBox(0, MAKEINTRESOURCE(IDD_EDIT_MULTI_STRING), hwnd, modify_dlgproc) == IDOK) if (DialogBoxW(0, MAKEINTRESOURCEW(IDD_EDIT_MULTI_STRING), hwnd, modify_dlgproc) == IDOK)
{ {
len = lstrlen( stringValueData ); len = lstrlenW( stringValueData );
tmpValueData = HeapAlloc( GetProcessHeap(), 0, (len + 2) * sizeof(TCHAR)); tmpValueData = HeapAlloc( GetProcessHeap(), 0, (len + 2) * sizeof(WCHAR));
if ( !tmpValueData ) goto done; if ( !tmpValueData ) goto done;
for ( i = 0, j = 0; i < len - 1; i++) for ( i = 0, j = 0; i < len - 1; i++)
...@@ -371,7 +414,7 @@ BOOL ModifyValue(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath, LPCTSTR valueName) ...@@ -371,7 +414,7 @@ BOOL ModifyValue(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath, LPCTSTR valueName)
HeapFree( GetProcessHeap(), 0, stringValueData); HeapFree( GetProcessHeap(), 0, stringValueData);
stringValueData = tmpValueData; stringValueData = tmpValueData;
lRet = RegSetValueEx(hKey, valueName, 0, type, (LPBYTE)stringValueData, j * sizeof(TCHAR)); lRet = RegSetValueExW(hKey, valueName, 0, type, (LPBYTE)stringValueData, j * sizeof(TCHAR));
if (lRet == ERROR_SUCCESS) result = TRUE; if (lRet == ERROR_SUCCESS) result = TRUE;
else error_code_messagebox(hwnd, lRet); else error_code_messagebox(hwnd, lRet);
} }
......
...@@ -715,15 +715,11 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) ...@@ -715,15 +715,11 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
break; break;
case ID_EDIT_MODIFY: case ID_EDIT_MODIFY:
{ {
LPCWSTR valueNameW = GetValueName(g_pChildWnd->hListWnd); LPCWSTR valueName = GetValueName(g_pChildWnd->hListWnd);
CHAR* valueNameA = GetMultiByteString(valueNameW); WCHAR* keyPath = GetItemPathW(g_pChildWnd->hTreeWnd, 0, &hKeyRoot);
WCHAR* keyPathW = GetItemPathW(g_pChildWnd->hTreeWnd, 0, &hKeyRoot); if (ModifyValue(hWnd, hKeyRoot, keyPath, valueName))
CHAR* keyPathA = GetMultiByteString(keyPathW); RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath, valueName);
if (ModifyValue(hWnd, hKeyRoot, keyPathA, valueNameA)) HeapFree(GetProcessHeap(), 0, keyPath);
RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPathW, valueNameW);
HeapFree(GetProcessHeap(), 0, valueNameA);
HeapFree(GetProcessHeap(), 0, keyPathW);
HeapFree(GetProcessHeap(), 0, keyPathA);
break; break;
} }
case ID_EDIT_FIND: case ID_EDIT_FIND:
......
...@@ -142,7 +142,7 @@ extern HTREEITEM FindNext(HWND hwndTV, HTREEITEM hItem, LPCWSTR sstring, int mod ...@@ -142,7 +142,7 @@ extern HTREEITEM FindNext(HWND hwndTV, HTREEITEM hItem, LPCWSTR sstring, int mod
/* edit.c */ /* edit.c */
extern BOOL CreateKey(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, LPWSTR newKeyName); extern BOOL CreateKey(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, LPWSTR newKeyName);
extern BOOL CreateValue(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, DWORD valueType, LPWSTR valueName); extern BOOL CreateValue(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, DWORD valueType, LPWSTR valueName);
extern BOOL ModifyValue(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath, LPCTSTR valueName); extern BOOL ModifyValue(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, LPCWSTR valueName);
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, LPCTSTR keyPath, LPCTSTR oldName, LPCTSTR newName); extern BOOL RenameValue(HWND hwnd, HKEY hRootKey, LPCTSTR keyPath, LPCTSTR oldName, LPCTSTR newName);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment