regedit: Convert value creation to unicode.

This commit is contained in:
Alexander Nicolaysen Sørnes 2008-08-28 16:18:44 +02:00 committed by Alexandre Julliard
parent 6c4d39bcaf
commit 9d6b80b121
3 changed files with 45 additions and 42 deletions

View file

@ -449,27 +449,27 @@ done:
return result; return result;
} }
BOOL CreateValue(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath, DWORD valueType, LPTSTR valueName) BOOL CreateValue(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, DWORD valueType, LPWSTR valueName)
{ {
LONG lRet = ERROR_SUCCESS; LONG lRet = ERROR_SUCCESS;
TCHAR newValue[256]; WCHAR newValue[256];
DWORD valueDword = 0; DWORD valueDword = 0;
BOOL result = FALSE; BOOL result = FALSE;
int valueNum; int valueNum;
HKEY hKey; HKEY hKey;
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 (!LoadString(GetModuleHandle(0), IDS_NEWVALUE, newValue, COUNT_OF(newValue))) goto done; if (!LoadStringW(GetModuleHandle(0), IDS_NEWVALUE, newValue, COUNT_OF(newValue))) goto done;
/* try to find out a name for the newly create key (max 100 times) */ /* try to find out a name for the newly create key (max 100 times) */
for (valueNum = 1; valueNum < 100; valueNum++) { for (valueNum = 1; valueNum < 100; valueNum++) {
wsprintf(valueName, newValue, valueNum); wsprintfW(valueName, newValue, valueNum);
lRet = RegQueryValueEx(hKey, valueName, 0, 0, 0, 0); lRet = RegQueryValueExW(hKey, valueName, 0, 0, 0, 0);
if (lRet == ERROR_FILE_NOT_FOUND) break; if (lRet == ERROR_FILE_NOT_FOUND) break;
} }
if (lRet != ERROR_FILE_NOT_FOUND) { if (lRet != ERROR_FILE_NOT_FOUND) {
@ -477,7 +477,7 @@ BOOL CreateValue(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath, DWORD valueType, LPT
goto done; goto done;
} }
lRet = RegSetValueEx(hKey, valueName, 0, valueType, (BYTE*)&valueDword, sizeof(DWORD)); lRet = RegSetValueExW(hKey, valueName, 0, valueType, (BYTE*)&valueDword, sizeof(DWORD));
if (lRet != ERROR_SUCCESS) { if (lRet != ERROR_SUCCESS) {
error_code_messagebox(hwnd, lRet); error_code_messagebox(hwnd, lRet);
goto done; goto done;

View file

@ -636,15 +636,11 @@ static INT_PTR CALLBACK removefavorite_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM w
static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{ {
HKEY hKeyRoot = 0; HKEY hKeyRoot = 0;
LPCTSTR keyPath;
LPCTSTR valueName; LPCTSTR valueName;
TCHAR newKey[MAX_NEW_KEY_LEN];
DWORD valueType; DWORD valueType;
int curIndex; int curIndex;
BOOL firstItem = TRUE; BOOL firstItem = TRUE;
keyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hKeyRoot);
if (LOWORD(wParam) >= ID_FAVORITE_FIRST && LOWORD(wParam) <= ID_FAVORITE_LAST) { if (LOWORD(wParam) >= ID_FAVORITE_FIRST && LOWORD(wParam) <= ID_FAVORITE_LAST) {
HKEY hKey; HKEY hKey;
if (RegOpenKeyExW(HKEY_CURRENT_USER, favoritesKey, if (RegOpenKeyExW(HKEY_CURRENT_USER, favoritesKey,
@ -683,15 +679,15 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
} }
case ID_EDIT_DELETE: case ID_EDIT_DELETE:
if (GetFocus() == g_pChildWnd->hTreeWnd) { if (GetFocus() == g_pChildWnd->hTreeWnd) {
WCHAR* keyPathW = GetWideString(keyPath); WCHAR* keyPath = GetItemPathW(g_pChildWnd->hTreeWnd, 0, &hKeyRoot);
if (keyPath == 0 || *keyPath == 0) { if (keyPath == 0 || *keyPath == 0) {
MessageBeep(MB_ICONHAND); MessageBeep(MB_ICONHAND);
} else if (DeleteKey(hWnd, hKeyRoot, keyPathW)) { } else if (DeleteKey(hWnd, hKeyRoot, keyPath)) {
DeleteNode(g_pChildWnd->hTreeWnd, 0); DeleteNode(g_pChildWnd->hTreeWnd, 0);
} }
HeapFree(GetProcessHeap(), 0, keyPathW); HeapFree(GetProcessHeap(), 0, keyPath);
} else if (GetFocus() == g_pChildWnd->hListWnd) { } else if (GetFocus() == g_pChildWnd->hListWnd) {
WCHAR* keyPathW = GetItemPathW(g_pChildWnd->hTreeWnd, 0, &hKeyRoot); WCHAR* keyPath = GetItemPathW(g_pChildWnd->hTreeWnd, 0, &hKeyRoot);
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* valueNameW;
@ -705,7 +701,7 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
break; break;
} }
valueNameW = GetWideString(valueName); valueNameW = GetWideString(valueName);
if (!DeleteValue(hWnd, hKeyRoot, keyPathW, valueNameW, curIndex==-1 && firstItem)) if (!DeleteValue(hWnd, hKeyRoot, keyPath, valueNameW, curIndex==-1 && firstItem))
{ {
HeapFree(GetProcessHeap(), 0, valueNameW); HeapFree(GetProcessHeap(), 0, valueNameW);
break; break;
@ -713,8 +709,8 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
firstItem = FALSE; firstItem = FALSE;
HeapFree(GetProcessHeap(), 0, valueNameW); HeapFree(GetProcessHeap(), 0, valueNameW);
} }
RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPathW, NULL); RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath, NULL);
HeapFree(GetProcessHeap(), 0, keyPathW); HeapFree(GetProcessHeap(), 0, keyPath);
} }
break; break;
case ID_EDIT_MODIFY: case ID_EDIT_MODIFY:
@ -722,10 +718,12 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
LPCWSTR valueNameW = GetValueName(g_pChildWnd->hListWnd); LPCWSTR valueNameW = GetValueName(g_pChildWnd->hListWnd);
CHAR* valueNameA = GetMultiByteString(valueNameW); CHAR* valueNameA = GetMultiByteString(valueNameW);
WCHAR* keyPathW = GetItemPathW(g_pChildWnd->hTreeWnd, 0, &hKeyRoot); WCHAR* keyPathW = GetItemPathW(g_pChildWnd->hTreeWnd, 0, &hKeyRoot);
if (ModifyValue(hWnd, hKeyRoot, keyPath, valueNameA)) CHAR* keyPathA = GetMultiByteString(keyPathW);
if (ModifyValue(hWnd, hKeyRoot, keyPathA, valueNameA))
RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPathW, valueNameW); RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPathW, valueNameW);
HeapFree(GetProcessHeap(), 0, valueNameA); HeapFree(GetProcessHeap(), 0, valueNameA);
HeapFree(GetProcessHeap(), 0, keyPathW); HeapFree(GetProcessHeap(), 0, keyPathW);
HeapFree(GetProcessHeap(), 0, keyPathA);
break; break;
} }
case ID_EDIT_FIND: case ID_EDIT_FIND:
@ -774,12 +772,12 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
case ID_EDIT_NEW_KEY: case ID_EDIT_NEW_KEY:
{ {
WCHAR newKeyW[MAX_NEW_KEY_LEN]; WCHAR newKeyW[MAX_NEW_KEY_LEN];
WCHAR* keyPathW = GetWideString(keyPath); WCHAR* keyPath = GetItemPathW(g_pChildWnd->hTreeWnd, 0, &hKeyRoot);
if (CreateKey(hWnd, hKeyRoot, keyPathW, newKeyW)) { if (CreateKey(hWnd, hKeyRoot, keyPath, newKeyW)) {
if (InsertNode(g_pChildWnd->hTreeWnd, 0, newKeyW)) if (InsertNode(g_pChildWnd->hTreeWnd, 0, newKeyW))
StartKeyRename(g_pChildWnd->hTreeWnd); StartKeyRename(g_pChildWnd->hTreeWnd);
} }
HeapFree(GetProcessHeap(), 0, keyPathW); HeapFree(GetProcessHeap(), 0, keyPath);
} }
break; break;
case ID_EDIT_NEW_STRINGVALUE: case ID_EDIT_NEW_STRINGVALUE:
@ -795,24 +793,29 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
valueType = REG_DWORD; valueType = REG_DWORD;
/* fall through */ /* fall through */
create_value: create_value:
if (CreateValue(hWnd, hKeyRoot, keyPath, valueType, newKey)) { {
WCHAR* keyPathW = GetItemPathW(g_pChildWnd->hTreeWnd, 0, &hKeyRoot); WCHAR* keyPath = GetItemPathW(g_pChildWnd->hTreeWnd, 0, &hKeyRoot);
WCHAR* newKeyW = GetWideString(newKey); WCHAR newKey[MAX_NEW_KEY_LEN];
RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPathW, newKeyW); if (CreateValue(hWnd, hKeyRoot, keyPath, valueType, newKey)) {
HeapFree(GetProcessHeap(), 0, keyPathW); RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath, newKey);
HeapFree(GetProcessHeap(), 0, newKeyW);
StartValueRename(g_pChildWnd->hListWnd); StartValueRename(g_pChildWnd->hListWnd);
/* FIXME: start rename */ /* FIXME: start rename */
} }
HeapFree(GetProcessHeap(), 0, keyPath);
}
break; break;
case ID_EDIT_RENAME: case ID_EDIT_RENAME:
if (keyPath == 0 || *keyPath == 0) { {
MessageBeep(MB_ICONHAND); WCHAR* keyPath = GetItemPathW(g_pChildWnd->hTreeWnd, 0, &hKeyRoot);
} else if (GetFocus() == g_pChildWnd->hTreeWnd) { if (keyPath == 0 || *keyPath == 0) {
StartKeyRename(g_pChildWnd->hTreeWnd); MessageBeep(MB_ICONHAND);
} else if (GetFocus() == g_pChildWnd->hListWnd) { } else if (GetFocus() == g_pChildWnd->hTreeWnd) {
StartValueRename(g_pChildWnd->hListWnd); StartKeyRename(g_pChildWnd->hTreeWnd);
} } else if (GetFocus() == g_pChildWnd->hListWnd) {
StartValueRename(g_pChildWnd->hListWnd);
}
HeapFree(GetProcessHeap(), 0, keyPath);
}
break; break;
case ID_REGISTRY_PRINTERSETUP: case ID_REGISTRY_PRINTERSETUP:
/*PRINTDLG pd;*/ /*PRINTDLG pd;*/
@ -856,10 +859,10 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
} }
case ID_VIEW_REFRESH: case ID_VIEW_REFRESH:
{ {
WCHAR* keyPathW = GetItemPathW(g_pChildWnd->hTreeWnd, 0, &hKeyRoot); WCHAR* keyPath = GetItemPathW(g_pChildWnd->hTreeWnd, 0, &hKeyRoot);
RefreshTreeView(g_pChildWnd->hTreeWnd); RefreshTreeView(g_pChildWnd->hTreeWnd);
RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPathW, NULL); RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath, NULL);
HeapFree(GetProcessHeap(), 0, keyPathW); HeapFree(GetProcessHeap(), 0, keyPath);
} }
break; break;
/*case ID_OPTIONS_TOOLBAR:*/ /*case ID_OPTIONS_TOOLBAR:*/

View file

@ -141,7 +141,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, LPCTSTR keyPath, DWORD valueType, LPTSTR 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, LPCTSTR keyPath, LPCTSTR 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);