regedit: Convert value editing to unicode.
[wine/hacks.git] / programs / regedit / edit.c
blobc44da85c4e480743d94c38a70780dd7fdfc3bf8a
1 /*
2 * Registry editing UI functions.
4 * Copyright (C) 2003 Dimitrie O. Paun
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
23 #include <windows.h>
24 #include <tchar.h>
25 #include <commctrl.h>
26 #include <commdlg.h>
27 #include <cderr.h>
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <shellapi.h>
31 #include <shlwapi.h>
33 #include "main.h"
34 #include "regproc.h"
35 #include "resource.h"
37 static const WCHAR* editValueName;
38 static WCHAR* stringValueData;
39 static BOOL isDecimal;
41 struct edit_params
43 HKEY hKey;
44 LPCWSTR lpszValueName;
45 void *pData;
46 LONG cbData;
49 static INT vmessagebox(HWND hwnd, INT buttons, INT titleId, INT resId, va_list ap)
51 TCHAR title[256];
52 TCHAR errfmt[1024];
53 TCHAR errstr[1024];
55 if (!LoadString(hInst, titleId, title, COUNT_OF(title)))
56 lstrcpy(title, "Error");
58 if (!LoadString(hInst, resId, errfmt, COUNT_OF(errfmt)))
59 lstrcpy(errfmt, "Unknown error string!");
61 _vsntprintf(errstr, COUNT_OF(errstr), errfmt, ap);
63 return MessageBox(hwnd, errstr, title, buttons);
66 static INT messagebox(HWND hwnd, INT buttons, INT titleId, INT resId, ...)
68 va_list ap;
69 INT result;
71 va_start(ap, resId);
72 result = vmessagebox(hwnd, buttons, titleId, resId, ap);
73 va_end(ap);
75 return result;
78 void error(HWND hwnd, INT resId, ...)
80 va_list ap;
82 va_start(ap, resId);
83 vmessagebox(hwnd, MB_OK | MB_ICONERROR, IDS_ERROR, resId, ap);
84 va_end(ap);
87 static void error_code_messagebox(HWND hwnd, DWORD error_code)
89 LPTSTR lpMsgBuf;
90 DWORD status;
91 TCHAR title[256];
92 static TCHAR fallback[] = TEXT("Error displaying error message.\n");
93 if (!LoadString(hInst, IDS_ERROR, title, COUNT_OF(title)))
94 lstrcpy(title, TEXT("Error"));
95 status = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
96 NULL, error_code, 0, (LPTSTR)&lpMsgBuf, 0, NULL);
97 if (!status)
98 lpMsgBuf = fallback;
99 MessageBox(hwnd, lpMsgBuf, title, MB_OK | MB_ICONERROR);
100 if (lpMsgBuf != fallback)
101 LocalFree(lpMsgBuf);
104 static BOOL change_dword_base(HWND hwndDlg, BOOL toHex)
106 TCHAR buf[128];
107 DWORD val;
109 if (!GetDlgItemText(hwndDlg, IDC_VALUE_DATA, buf, COUNT_OF(buf))) return FALSE;
110 if (!_stscanf(buf, toHex ? "%u" : "%x", &val)) return FALSE;
111 wsprintf(buf, toHex ? "%x" : "%u", val);
112 return SetDlgItemText(hwndDlg, IDC_VALUE_DATA, buf);
115 static INT_PTR CALLBACK modify_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
117 WCHAR* valueData;
118 HWND hwndValue;
119 int len;
121 switch(uMsg) {
122 case WM_INITDIALOG:
123 SetDlgItemTextW(hwndDlg, IDC_VALUE_NAME, editValueName);
124 SetDlgItemTextW(hwndDlg, IDC_VALUE_DATA, stringValueData);
125 CheckRadioButton(hwndDlg, IDC_DWORD_HEX, IDC_DWORD_DEC, isDecimal ? IDC_DWORD_DEC : IDC_DWORD_HEX);
126 return TRUE;
127 case WM_COMMAND:
128 switch (LOWORD(wParam)) {
129 case IDC_DWORD_HEX:
130 if (isDecimal && change_dword_base(hwndDlg, TRUE)) isDecimal = FALSE;
131 break;
132 case IDC_DWORD_DEC:
133 if (!isDecimal && change_dword_base(hwndDlg, FALSE)) isDecimal = TRUE;
134 break;
135 case IDOK:
136 if ((hwndValue = GetDlgItem(hwndDlg, IDC_VALUE_DATA))) {
137 len = GetWindowTextLengthW(hwndValue);
138 if ((valueData = HeapReAlloc(GetProcessHeap(), 0, stringValueData, (len + 1) * sizeof(WCHAR)))) {
139 stringValueData = valueData;
140 if (!GetWindowTextW(hwndValue, stringValueData, len + 1))
141 *stringValueData = 0;
144 /* Fall through */
145 case IDCANCEL:
146 EndDialog(hwndDlg, wParam);
147 return TRUE;
150 return FALSE;
153 static INT_PTR CALLBACK bin_modify_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
155 struct edit_params *params;
156 LPBYTE pData;
157 LONG cbData;
158 LONG lRet;
160 switch(uMsg) {
161 case WM_INITDIALOG:
162 params = (struct edit_params *)lParam;
163 SetWindowLongPtr(hwndDlg, DWLP_USER, (ULONG_PTR)params);
164 if (params->lpszValueName)
165 SetDlgItemTextW(hwndDlg, IDC_VALUE_NAME, params->lpszValueName);
166 else
167 SetDlgItemTextW(hwndDlg, IDC_VALUE_NAME, g_pszDefaultValueNameW);
168 SendDlgItemMessage(hwndDlg, IDC_VALUE_DATA, HEM_SETDATA, (WPARAM)params->cbData, (LPARAM)params->pData);
169 return TRUE;
170 case WM_COMMAND:
171 switch (LOWORD(wParam)) {
172 case IDOK:
173 params = (struct edit_params *)GetWindowLongPtr(hwndDlg, DWLP_USER);
174 cbData = SendDlgItemMessage(hwndDlg, IDC_VALUE_DATA, HEM_GETDATA, 0, 0);
175 pData = HeapAlloc(GetProcessHeap(), 0, cbData);
177 if (pData)
179 SendDlgItemMessageW(hwndDlg, IDC_VALUE_DATA, HEM_GETDATA, (WPARAM)cbData, (LPARAM)pData);
180 lRet = RegSetValueExW(params->hKey, params->lpszValueName, 0, REG_BINARY, pData, cbData);
182 else
183 lRet = ERROR_OUTOFMEMORY;
185 if (lRet == ERROR_SUCCESS)
186 EndDialog(hwndDlg, 1);
187 else
189 error_code_messagebox(hwndDlg, lRet);
190 EndDialog(hwndDlg, 0);
192 return TRUE;
193 case IDCANCEL:
194 EndDialog(hwndDlg, 0);
195 return TRUE;
198 return FALSE;
201 static BOOL check_value(HWND hwnd, HKEY hKey, LPCTSTR valueName)
203 LONG lRet = RegQueryValueEx(hKey, valueName ? valueName : _T(""), 0, NULL, 0, NULL);
204 if(lRet != ERROR_SUCCESS) return FALSE;
205 return TRUE;
208 static LPTSTR read_value(HWND hwnd, HKEY hKey, LPCTSTR valueName, DWORD *lpType, LONG *len)
210 DWORD valueDataLen;
211 LPTSTR buffer = NULL;
212 LONG lRet;
214 lRet = RegQueryValueEx(hKey, valueName ? valueName : _T(""), 0, lpType, 0, &valueDataLen);
215 if (lRet != ERROR_SUCCESS) {
216 if (lRet == ERROR_FILE_NOT_FOUND && !valueName) { /* no default value here, make it up */
217 if (len) *len = 1;
218 if (lpType) *lpType = REG_SZ;
219 buffer = HeapAlloc(GetProcessHeap(), 0, 1);
220 *buffer = '\0';
221 return buffer;
223 error(hwnd, IDS_BAD_VALUE, valueName);
224 goto done;
226 if ( *lpType == REG_DWORD ) valueDataLen = sizeof(DWORD);
227 if (!(buffer = HeapAlloc(GetProcessHeap(), 0, valueDataLen+1))) {
228 error(hwnd, IDS_TOO_BIG_VALUE, valueDataLen);
229 goto done;
231 lRet = RegQueryValueEx(hKey, valueName, 0, 0, (LPBYTE)buffer, &valueDataLen);
232 if (lRet != ERROR_SUCCESS) {
233 error(hwnd, IDS_BAD_VALUE, valueName);
234 goto done;
236 buffer[valueDataLen] = 0;
237 if(len) *len = valueDataLen;
238 return buffer;
240 done:
241 HeapFree(GetProcessHeap(), 0, buffer);
242 return NULL;
245 static LPWSTR read_valueW(HWND hwnd, HKEY hKey, LPCWSTR valueName, DWORD *lpType, LONG *len)
247 DWORD valueDataLen;
248 LPWSTR buffer = NULL;
249 LONG lRet;
250 WCHAR empty = 0;
252 lRet = RegQueryValueExW(hKey, valueName ? valueName : &empty, 0, lpType, 0, &valueDataLen);
253 if (lRet != ERROR_SUCCESS) {
254 if (lRet == ERROR_FILE_NOT_FOUND && !valueName) { /* no default value here, make it up */
255 if (len) *len = 1;
256 if (lpType) *lpType = REG_SZ;
257 buffer = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR));
258 *buffer = '\0';
259 return buffer;
261 error(hwnd, IDS_BAD_VALUE, valueName);
262 goto done;
264 if ( *lpType == REG_DWORD ) valueDataLen = sizeof(DWORD);
265 if (!(buffer = HeapAlloc(GetProcessHeap(), 0, valueDataLen+sizeof(WCHAR)))) {
266 error(hwnd, IDS_TOO_BIG_VALUE, valueDataLen);
267 goto done;
269 lRet = RegQueryValueExW(hKey, valueName, 0, 0, (LPBYTE)buffer, &valueDataLen);
270 if (lRet != ERROR_SUCCESS) {
271 error(hwnd, IDS_BAD_VALUE, valueName);
272 goto done;
274 if((valueDataLen % sizeof(WCHAR)) == 0)
275 buffer[valueDataLen / sizeof(WCHAR)] = 0;
276 if(len) *len = valueDataLen;
277 return buffer;
279 done:
280 HeapFree(GetProcessHeap(), 0, buffer);
281 return NULL;
284 BOOL CreateKey(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, LPWSTR keyName)
286 BOOL result = FALSE;
287 LONG lRet = ERROR_SUCCESS;
288 HKEY retKey = NULL;
289 WCHAR newKey[MAX_NEW_KEY_LEN - 4];
290 int keyNum;
291 HKEY hKey;
293 lRet = RegOpenKeyExW(hKeyRoot, keyPath, 0, KEY_CREATE_SUB_KEY, &hKey);
294 if (lRet != ERROR_SUCCESS) {
295 error_code_messagebox(hwnd, lRet);
296 goto done;
299 if (!LoadStringW(GetModuleHandle(0), IDS_NEWKEY, newKey, COUNT_OF(newKey))) goto done;
301 /* try to find out a name for the newly create key (max 100 times) */
302 for (keyNum = 1; keyNum < 100; keyNum++) {
303 wsprintfW(keyName, newKey, keyNum);
304 lRet = RegOpenKeyW(hKey, keyName, &retKey);
305 if (lRet != ERROR_SUCCESS) break;
306 RegCloseKey(retKey);
308 if (lRet == ERROR_SUCCESS) goto done;
310 lRet = RegCreateKeyW(hKey, keyName, &retKey);
311 if (lRet != ERROR_SUCCESS) {
312 error_code_messagebox(hwnd, lRet);
313 goto done;
316 result = TRUE;
318 done:
319 RegCloseKey(retKey);
320 return result;
323 BOOL ModifyValue(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, LPCWSTR valueName)
325 BOOL result = FALSE;
326 DWORD type;
327 LONG lRet;
328 HKEY hKey;
329 LONG len;
331 lRet = RegOpenKeyExW(hKeyRoot, keyPath, 0, KEY_READ | KEY_SET_VALUE, &hKey);
332 if (lRet != ERROR_SUCCESS) {
333 error_code_messagebox(hwnd, lRet);
334 return FALSE;
337 editValueName = valueName ? valueName : g_pszDefaultValueNameW;
338 if(!(stringValueData = read_valueW(hwnd, hKey, valueName, &type, &len))) goto done;
340 if ( (type == REG_SZ) || (type == REG_EXPAND_SZ) ) {
341 if (DialogBoxW(0, MAKEINTRESOURCEW(IDD_EDIT_STRING), hwnd, modify_dlgproc) == IDOK) {
342 lRet = RegSetValueExW(hKey, valueName, 0, type, (LPBYTE)stringValueData, (lstrlenW(stringValueData) + 1) * sizeof(WCHAR));
343 if (lRet == ERROR_SUCCESS) result = TRUE;
344 else error_code_messagebox(hwnd, lRet);
346 } else if ( type == REG_DWORD ) {
347 const WCHAR u[] = {'%','u',0};
348 const WCHAR x[] = {'%','x',0};
349 wsprintfW(stringValueData, isDecimal ? u : x, *((DWORD*)stringValueData));
350 if (DialogBoxW(0, MAKEINTRESOURCEW(IDD_EDIT_DWORD), hwnd, modify_dlgproc) == IDOK) {
351 DWORD val;
352 CHAR* valueA = GetMultiByteString(stringValueData);
353 if (_stscanf(valueA, isDecimal ? "%u" : "%x", &val)) {
354 lRet = RegSetValueExW(hKey, valueName, 0, type, (BYTE*)&val, sizeof(val));
355 if (lRet == ERROR_SUCCESS) result = TRUE;
356 else error_code_messagebox(hwnd, lRet);
358 HeapFree(GetProcessHeap(), 0, valueA);
360 } else if ( type == REG_BINARY ) {
361 struct edit_params params;
362 params.hKey = hKey;
363 params.lpszValueName = valueName;
364 params.pData = stringValueData;
365 params.cbData = len;
366 result = DialogBoxParam(NULL, MAKEINTRESOURCE(IDD_EDIT_BINARY), hwnd,
367 bin_modify_dlgproc, (LPARAM)&params);
368 } else if ( type == REG_MULTI_SZ ) {
369 WCHAR char1 = '\r', char2 = '\n';
370 WCHAR *tmpValueData = NULL;
371 INT i, j, count;
373 for ( i = 0, count = 0; i < len - 1; i++)
374 if ( !stringValueData[i] && stringValueData[i + 1] )
375 count++;
376 tmpValueData = HeapAlloc( GetProcessHeap(), 0, ( len + count ) * sizeof(WCHAR));
377 if ( !tmpValueData ) goto done;
379 for ( i = 0, j = 0; i < len - 1; i++)
381 if ( !stringValueData[i] && stringValueData[i + 1])
383 tmpValueData[j++] = char1;
384 tmpValueData[j++] = char2;
386 else
387 tmpValueData[j++] = stringValueData[i];
389 tmpValueData[j] = stringValueData[i];
390 HeapFree( GetProcessHeap(), 0, stringValueData);
391 stringValueData = tmpValueData;
392 tmpValueData = NULL;
394 if (DialogBoxW(0, MAKEINTRESOURCEW(IDD_EDIT_MULTI_STRING), hwnd, modify_dlgproc) == IDOK)
396 len = lstrlenW( stringValueData );
397 tmpValueData = HeapAlloc( GetProcessHeap(), 0, (len + 2) * sizeof(WCHAR));
398 if ( !tmpValueData ) goto done;
400 for ( i = 0, j = 0; i < len - 1; i++)
402 if ( stringValueData[i] == char1 && stringValueData[i + 1] == char2)
404 if ( tmpValueData[j - 1] != 0)
405 tmpValueData[j++] = 0;
406 i++;
408 else
409 tmpValueData[j++] = stringValueData[i];
411 tmpValueData[j++] = stringValueData[i];
412 tmpValueData[j++] = 0;
413 tmpValueData[j++] = 0;
414 HeapFree( GetProcessHeap(), 0, stringValueData);
415 stringValueData = tmpValueData;
417 lRet = RegSetValueExW(hKey, valueName, 0, type, (LPBYTE)stringValueData, j * sizeof(TCHAR));
418 if (lRet == ERROR_SUCCESS) result = TRUE;
419 else error_code_messagebox(hwnd, lRet);
421 } else {
422 error(hwnd, IDS_UNSUPPORTED_TYPE, type);
425 done:
426 HeapFree(GetProcessHeap(), 0, stringValueData);
427 stringValueData = NULL;
428 RegCloseKey(hKey);
429 return result;
432 BOOL DeleteKey(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath)
434 BOOL result = FALSE;
435 LONG lRet;
436 HKEY hKey;
437 CHAR* keyPathA = GetMultiByteString(keyPath);
439 lRet = RegOpenKeyExW(hKeyRoot, keyPath, 0, KEY_READ|KEY_SET_VALUE, &hKey);
440 if (lRet != ERROR_SUCCESS) {
441 error_code_messagebox(hwnd, lRet);
442 return FALSE;
445 if (messagebox(hwnd, MB_YESNO | MB_ICONEXCLAMATION, IDS_DELETE_BOX_TITLE, IDS_DELETE_BOX_TEXT, keyPathA) != IDYES)
446 goto done;
448 lRet = SHDeleteKeyW(hKeyRoot, keyPath);
449 if (lRet != ERROR_SUCCESS) {
450 error(hwnd, IDS_BAD_KEY, keyPath);
451 goto done;
453 result = TRUE;
455 done:
456 RegCloseKey(hKey);
457 HeapFree(GetProcessHeap(), 0, keyPathA);
458 return result;
461 BOOL DeleteValue(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, LPCWSTR valueName, BOOL showMessageBox)
463 BOOL result = FALSE;
464 LONG lRet;
465 HKEY hKey;
466 LPCWSTR visibleValueName = valueName ? valueName : g_pszDefaultValueNameW;
467 WCHAR empty = 0;
469 lRet = RegOpenKeyExW(hKeyRoot, keyPath, 0, KEY_READ | KEY_SET_VALUE, &hKey);
470 if (lRet != ERROR_SUCCESS) return FALSE;
472 if (showMessageBox)
474 LPSTR visibleValueNameA = GetMultiByteString(visibleValueName);
475 if (messagebox(hwnd, MB_YESNO | MB_ICONEXCLAMATION, IDS_DELETE_BOX_TITLE, IDS_DELETE_BOX_TEXT, visibleValueNameA) != IDYES)
477 HeapFree(GetProcessHeap(), 0, visibleValueNameA);
478 goto done;
480 HeapFree(GetProcessHeap(), 0, visibleValueNameA);
483 lRet = RegDeleteValueW(hKey, valueName ? valueName : &empty);
484 if (lRet != ERROR_SUCCESS && valueName) {
485 error(hwnd, IDS_BAD_VALUE, valueName);
487 if (lRet != ERROR_SUCCESS) goto done;
488 result = TRUE;
490 done:
491 RegCloseKey(hKey);
492 return result;
495 BOOL CreateValue(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, DWORD valueType, LPWSTR valueName)
497 LONG lRet = ERROR_SUCCESS;
498 WCHAR newValue[256];
499 DWORD valueDword = 0;
500 BOOL result = FALSE;
501 int valueNum;
502 HKEY hKey;
504 lRet = RegOpenKeyExW(hKeyRoot, keyPath, 0, KEY_READ | KEY_SET_VALUE, &hKey);
505 if (lRet != ERROR_SUCCESS) {
506 error_code_messagebox(hwnd, lRet);
507 return FALSE;
510 if (!LoadStringW(GetModuleHandle(0), IDS_NEWVALUE, newValue, COUNT_OF(newValue))) goto done;
512 /* try to find out a name for the newly create key (max 100 times) */
513 for (valueNum = 1; valueNum < 100; valueNum++) {
514 wsprintfW(valueName, newValue, valueNum);
515 lRet = RegQueryValueExW(hKey, valueName, 0, 0, 0, 0);
516 if (lRet == ERROR_FILE_NOT_FOUND) break;
518 if (lRet != ERROR_FILE_NOT_FOUND) {
519 error_code_messagebox(hwnd, lRet);
520 goto done;
523 lRet = RegSetValueExW(hKey, valueName, 0, valueType, (BYTE*)&valueDword, sizeof(DWORD));
524 if (lRet != ERROR_SUCCESS) {
525 error_code_messagebox(hwnd, lRet);
526 goto done;
528 result = TRUE;
530 done:
531 RegCloseKey(hKey);
532 return result;
535 BOOL RenameValue(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath, LPCTSTR oldName, LPCTSTR newName)
537 LPTSTR value = NULL;
538 DWORD type;
539 LONG len, lRet;
540 BOOL result = FALSE;
541 HKEY hKey;
543 if (!oldName) return FALSE;
544 if (!newName) return FALSE;
546 lRet = RegOpenKeyEx(hKeyRoot, keyPath, 0, KEY_READ | KEY_SET_VALUE, &hKey);
547 if (lRet != ERROR_SUCCESS) {
548 error_code_messagebox(hwnd, lRet);
549 return FALSE;
551 /* check if value already exists */
552 if (check_value(hwnd, hKey, newName)) goto done;
553 value = read_value(hwnd, hKey, oldName, &type, &len);
554 if(!value) goto done;
555 lRet = RegSetValueEx(hKey, newName, 0, type, (BYTE*)value, len);
556 if (lRet != ERROR_SUCCESS) {
557 error_code_messagebox(hwnd, lRet);
558 goto done;
560 lRet = RegDeleteValue(hKey, oldName);
561 if (lRet != ERROR_SUCCESS) {
562 RegDeleteValue(hKey, newName);
563 error_code_messagebox(hwnd, lRet);
564 goto done;
566 result = TRUE;
568 done:
569 HeapFree(GetProcessHeap(), 0, value);
570 RegCloseKey(hKey);
571 return result;
575 BOOL RenameKey(HWND hwnd, HKEY hRootKey, LPCTSTR keyPath, LPCTSTR newName)
577 LPTSTR parentPath = 0;
578 LPCTSTR srcSubKey = 0;
579 HKEY parentKey = 0;
580 HKEY destKey = 0;
581 BOOL result = FALSE;
582 LONG lRet;
583 DWORD disposition;
585 if (!keyPath || !newName) return FALSE;
587 if (!strrchr(keyPath, '\\')) {
588 parentKey = hRootKey;
589 srcSubKey = keyPath;
590 } else {
591 LPTSTR srcSubKey_copy;
593 parentPath = strdup(keyPath);
594 srcSubKey_copy = strrchr(parentPath, '\\');
595 *srcSubKey_copy = 0;
596 srcSubKey = srcSubKey_copy + 1;
597 lRet = RegOpenKeyEx(hRootKey, parentPath, 0, KEY_READ | KEY_CREATE_SUB_KEY, &parentKey);
598 if (lRet != ERROR_SUCCESS) {
599 error_code_messagebox(hwnd, lRet);
600 goto done;
604 /* The following fails if the old name is the same as the new name. */
605 if (!strcmp(srcSubKey, newName)) goto done;
607 lRet = RegCreateKeyEx(parentKey, newName, 0, NULL, REG_OPTION_NON_VOLATILE,
608 KEY_WRITE, NULL /* FIXME */, &destKey, &disposition);
609 if (disposition == REG_OPENED_EXISTING_KEY)
610 lRet = ERROR_FILE_EXISTS; /* FIXME: we might want a better error message than this */
611 if (lRet != ERROR_SUCCESS) {
612 error_code_messagebox(hwnd, lRet);
613 goto done;
616 /* FIXME: SHCopyKey does not copy the security attributes */
617 lRet = SHCopyKey(parentKey, srcSubKey, destKey, 0);
618 if (lRet != ERROR_SUCCESS) {
619 RegCloseKey(destKey);
620 RegDeleteKey(parentKey, newName);
621 error_code_messagebox(hwnd, lRet);
622 goto done;
625 lRet = SHDeleteKey(hRootKey, keyPath);
626 if (lRet != ERROR_SUCCESS) {
627 error_code_messagebox(hwnd, lRet);
628 goto done;
631 result = TRUE;
633 done:
634 RegCloseKey(destKey);
635 if (parentKey) {
636 RegCloseKey(parentKey);
637 free(parentPath);
639 return result;