2003-12-03 21:25:24 +01:00
|
|
|
/*
|
|
|
|
* Registry editing UI functions.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2003 Dimitrie O. Paun
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2003-12-03 21:25:24 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <commctrl.h>
|
|
|
|
#include <commdlg.h>
|
|
|
|
#include <cderr.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <shellapi.h>
|
2004-03-12 20:44:47 +01:00
|
|
|
#include <shlwapi.h>
|
2003-12-03 21:25:24 +01:00
|
|
|
|
2018-02-07 00:20:07 +01:00
|
|
|
#include "wine/heap.h"
|
2008-08-30 23:50:24 +02:00
|
|
|
#include "wine/unicode.h"
|
2003-12-03 21:25:24 +01:00
|
|
|
#include "main.h"
|
|
|
|
|
2008-08-29 21:37:43 +02:00
|
|
|
static const WCHAR* editValueName;
|
|
|
|
static WCHAR* stringValueData;
|
2004-01-05 22:14:19 +01:00
|
|
|
static BOOL isDecimal;
|
2003-12-03 21:25:24 +01:00
|
|
|
|
2005-04-14 13:30:31 +02:00
|
|
|
struct edit_params
|
|
|
|
{
|
2018-07-16 14:20:49 +02:00
|
|
|
HKEY hkey;
|
|
|
|
const WCHAR *value_name;
|
2018-07-16 14:20:50 +02:00
|
|
|
DWORD type;
|
2018-07-16 14:20:49 +02:00
|
|
|
void *data;
|
|
|
|
DWORD size;
|
2005-04-14 13:30:31 +02:00
|
|
|
};
|
|
|
|
|
2017-02-01 13:56:27 +01:00
|
|
|
static int vmessagebox(HWND hwnd, int buttons, int titleId, int resId, __ms_va_list va_args)
|
2003-12-03 21:25:24 +01:00
|
|
|
{
|
2009-01-06 21:09:43 +01:00
|
|
|
WCHAR title[256];
|
2017-02-01 13:56:27 +01:00
|
|
|
WCHAR fmt[1024];
|
|
|
|
WCHAR *str;
|
|
|
|
int ret;
|
2003-12-03 21:25:24 +01:00
|
|
|
|
2018-05-21 15:34:49 +02:00
|
|
|
LoadStringW(hInst, titleId, title, ARRAY_SIZE(title));
|
|
|
|
LoadStringW(hInst, resId, fmt, ARRAY_SIZE(fmt));
|
2003-12-03 21:25:24 +01:00
|
|
|
|
2017-02-01 13:56:27 +01:00
|
|
|
FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ALLOCATE_BUFFER,
|
|
|
|
fmt, 0, 0, (WCHAR *)&str, 0, &va_args);
|
|
|
|
ret = MessageBoxW(hwnd, str, title, buttons);
|
|
|
|
LocalFree(str);
|
2004-01-05 22:14:19 +01:00
|
|
|
|
2017-02-01 13:56:27 +01:00
|
|
|
return ret;
|
2004-01-05 22:14:19 +01:00
|
|
|
}
|
|
|
|
|
2017-11-02 10:21:53 +01:00
|
|
|
int WINAPIV messagebox(HWND hwnd, int buttons, int titleId, int resId, ...)
|
2004-01-05 22:14:19 +01:00
|
|
|
{
|
2017-02-01 13:56:27 +01:00
|
|
|
__ms_va_list ap;
|
2004-01-05 22:14:19 +01:00
|
|
|
INT result;
|
|
|
|
|
2017-02-01 13:56:27 +01:00
|
|
|
__ms_va_start(ap, resId);
|
2004-01-05 22:14:19 +01:00
|
|
|
result = vmessagebox(hwnd, buttons, titleId, resId, ap);
|
2017-02-01 13:56:27 +01:00
|
|
|
__ms_va_end(ap);
|
2003-12-03 21:25:24 +01:00
|
|
|
|
2004-01-05 22:14:19 +01:00
|
|
|
return result;
|
2003-12-03 21:25:24 +01:00
|
|
|
}
|
|
|
|
|
2017-11-02 10:21:53 +01:00
|
|
|
static void WINAPIV error_code_messagebox(HWND hwnd, unsigned int msg_id, ...)
|
2004-01-05 22:14:19 +01:00
|
|
|
{
|
2017-02-01 13:56:27 +01:00
|
|
|
__ms_va_list ap;
|
2004-01-05 22:14:19 +01:00
|
|
|
|
2017-02-01 13:56:51 +01:00
|
|
|
__ms_va_start(ap, msg_id);
|
|
|
|
vmessagebox(hwnd, MB_OK|MB_ICONERROR, IDS_ERROR, msg_id, ap);
|
2017-02-01 13:56:27 +01:00
|
|
|
__ms_va_end(ap);
|
2004-01-05 22:14:19 +01:00
|
|
|
}
|
|
|
|
|
2005-06-04 12:01:25 +02:00
|
|
|
static BOOL change_dword_base(HWND hwndDlg, BOOL toHex)
|
2004-01-05 22:14:19 +01:00
|
|
|
{
|
2011-04-16 10:07:13 +02:00
|
|
|
static const WCHAR percent_u[] = {'%','u',0};
|
|
|
|
static const WCHAR percent_x[] = {'%','x',0};
|
|
|
|
|
|
|
|
WCHAR buf[128];
|
2004-01-05 22:14:19 +01:00
|
|
|
DWORD val;
|
|
|
|
|
2018-05-21 15:34:49 +02:00
|
|
|
if (!GetDlgItemTextW(hwndDlg, IDC_VALUE_DATA, buf, ARRAY_SIZE(buf))) return FALSE;
|
2011-04-16 10:07:13 +02:00
|
|
|
if (!swscanf(buf, toHex ? percent_u : percent_x, &val)) return FALSE;
|
|
|
|
wsprintfW(buf, toHex ? percent_x : percent_u, val);
|
|
|
|
return SetDlgItemTextW(hwndDlg, IDC_VALUE_DATA, buf);
|
2004-01-05 22:14:19 +01:00
|
|
|
}
|
|
|
|
|
2005-06-04 12:01:25 +02:00
|
|
|
static INT_PTR CALLBACK modify_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
2003-12-03 21:25:24 +01:00
|
|
|
{
|
|
|
|
HWND hwndValue;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
switch(uMsg) {
|
2003-12-08 23:48:07 +01:00
|
|
|
case WM_INITDIALOG:
|
2008-08-29 21:37:43 +02:00
|
|
|
SetDlgItemTextW(hwndDlg, IDC_VALUE_NAME, editValueName);
|
|
|
|
SetDlgItemTextW(hwndDlg, IDC_VALUE_DATA, stringValueData);
|
2018-07-16 14:20:48 +02:00
|
|
|
CheckRadioButton(hwndDlg, IDC_DWORD_HEX, IDC_DWORD_DEC, IDC_DWORD_HEX);
|
|
|
|
isDecimal = FALSE;
|
2003-12-08 23:48:07 +01:00
|
|
|
return TRUE;
|
|
|
|
case WM_COMMAND:
|
|
|
|
switch (LOWORD(wParam)) {
|
2004-01-05 22:14:19 +01:00
|
|
|
case IDC_DWORD_HEX:
|
|
|
|
if (isDecimal && change_dword_base(hwndDlg, TRUE)) isDecimal = FALSE;
|
|
|
|
break;
|
|
|
|
case IDC_DWORD_DEC:
|
|
|
|
if (!isDecimal && change_dword_base(hwndDlg, FALSE)) isDecimal = TRUE;
|
|
|
|
break;
|
2003-12-08 23:48:07 +01:00
|
|
|
case IDOK:
|
|
|
|
if ((hwndValue = GetDlgItem(hwndDlg, IDC_VALUE_DATA))) {
|
2008-08-29 21:37:43 +02:00
|
|
|
len = GetWindowTextLengthW(hwndValue);
|
2017-07-27 14:25:26 +02:00
|
|
|
stringValueData = heap_xrealloc(stringValueData, (len + 1) * sizeof(WCHAR));
|
|
|
|
if (!GetWindowTextW(hwndValue, stringValueData, len + 1))
|
|
|
|
*stringValueData = 0;
|
2003-12-08 23:48:07 +01:00
|
|
|
}
|
|
|
|
/* Fall through */
|
|
|
|
case IDCANCEL:
|
|
|
|
EndDialog(hwndDlg, wParam);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2003-12-03 21:25:24 +01:00
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2005-04-14 13:30:31 +02:00
|
|
|
static INT_PTR CALLBACK bin_modify_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
struct edit_params *params;
|
2018-07-16 14:20:49 +02:00
|
|
|
BYTE *data;
|
|
|
|
LONG size;
|
2005-04-14 13:30:31 +02:00
|
|
|
LONG lRet;
|
|
|
|
|
|
|
|
switch(uMsg) {
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
params = (struct edit_params *)lParam;
|
2011-04-16 10:07:13 +02:00
|
|
|
SetWindowLongPtrW(hwndDlg, DWLP_USER, (ULONG_PTR)params);
|
2018-07-16 14:20:49 +02:00
|
|
|
if (params->value_name)
|
|
|
|
SetDlgItemTextW(hwndDlg, IDC_VALUE_NAME, params->value_name);
|
2005-04-14 13:30:31 +02:00
|
|
|
else
|
2008-08-31 16:49:43 +02:00
|
|
|
SetDlgItemTextW(hwndDlg, IDC_VALUE_NAME, g_pszDefaultValueName);
|
2018-07-16 14:20:49 +02:00
|
|
|
SendDlgItemMessageW(hwndDlg, IDC_VALUE_DATA, HEM_SETDATA, (WPARAM)params->size, (LPARAM)params->data);
|
2018-03-11 18:28:31 +01:00
|
|
|
SendDlgItemMessageW(hwndDlg, IDC_VALUE_DATA, WM_SETFONT, (WPARAM) GetStockObject(ANSI_FIXED_FONT), TRUE);
|
2005-04-14 13:30:31 +02:00
|
|
|
return TRUE;
|
|
|
|
case WM_COMMAND:
|
|
|
|
switch (LOWORD(wParam)) {
|
|
|
|
case IDOK:
|
2011-04-16 10:07:13 +02:00
|
|
|
params = (struct edit_params *)GetWindowLongPtrW(hwndDlg, DWLP_USER);
|
2018-07-16 14:20:49 +02:00
|
|
|
size = SendDlgItemMessageW(hwndDlg, IDC_VALUE_DATA, HEM_GETDATA, 0, 0);
|
|
|
|
data = heap_xalloc(size);
|
2005-04-14 13:30:31 +02:00
|
|
|
|
2018-07-16 14:20:49 +02:00
|
|
|
SendDlgItemMessageW(hwndDlg, IDC_VALUE_DATA, HEM_GETDATA, (WPARAM)size, (LPARAM)data);
|
2018-07-16 14:20:50 +02:00
|
|
|
lRet = RegSetValueExW(params->hkey, params->value_name, 0, params->type, data, size);
|
2018-07-16 14:20:49 +02:00
|
|
|
heap_free(data);
|
2005-04-14 13:30:31 +02:00
|
|
|
|
|
|
|
if (lRet == ERROR_SUCCESS)
|
|
|
|
EndDialog(hwndDlg, 1);
|
|
|
|
else
|
|
|
|
{
|
2017-02-01 13:56:40 +01:00
|
|
|
error_code_messagebox(hwndDlg, IDS_SET_VALUE_FAILED);
|
2005-04-14 13:30:31 +02:00
|
|
|
EndDialog(hwndDlg, 0);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
case IDCANCEL:
|
|
|
|
EndDialog(hwndDlg, 0);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-05-21 15:34:57 +02:00
|
|
|
static BOOL value_exists(HWND hwnd, HKEY hKey, const WCHAR *value_name)
|
2004-05-04 04:55:28 +02:00
|
|
|
{
|
2018-05-21 15:34:57 +02:00
|
|
|
return !RegQueryValueExW(hKey, value_name, NULL, NULL, NULL, NULL);
|
2004-05-04 04:55:28 +02:00
|
|
|
}
|
|
|
|
|
2008-08-29 22:20:26 +02:00
|
|
|
static LPWSTR read_value(HWND hwnd, HKEY hKey, LPCWSTR valueName, DWORD *lpType, LONG *len)
|
2008-08-29 21:37:43 +02:00
|
|
|
{
|
|
|
|
DWORD valueDataLen;
|
|
|
|
LPWSTR buffer = NULL;
|
|
|
|
LONG lRet;
|
|
|
|
|
2018-05-28 15:48:07 +02:00
|
|
|
lRet = RegQueryValueExW(hKey, valueName, NULL, lpType, NULL, &valueDataLen);
|
2018-05-21 15:34:58 +02:00
|
|
|
if (lRet) {
|
2008-08-29 21:37:43 +02:00
|
|
|
if (lRet == ERROR_FILE_NOT_FOUND && !valueName) { /* no default value here, make it up */
|
|
|
|
if (len) *len = 1;
|
|
|
|
if (lpType) *lpType = REG_SZ;
|
2017-07-27 14:25:26 +02:00
|
|
|
buffer = heap_xalloc(sizeof(WCHAR));
|
2008-08-29 21:37:43 +02:00
|
|
|
*buffer = '\0';
|
|
|
|
return buffer;
|
|
|
|
}
|
2017-02-01 13:56:51 +01:00
|
|
|
error_code_messagebox(hwnd, IDS_BAD_VALUE, valueName);
|
2008-08-29 21:37:43 +02:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
if ( *lpType == REG_DWORD ) valueDataLen = sizeof(DWORD);
|
2017-07-27 14:25:26 +02:00
|
|
|
buffer = heap_xalloc(valueDataLen + sizeof(WCHAR));
|
2008-08-29 21:37:43 +02:00
|
|
|
lRet = RegQueryValueExW(hKey, valueName, 0, 0, (LPBYTE)buffer, &valueDataLen);
|
2018-05-21 15:34:58 +02:00
|
|
|
if (lRet) {
|
2017-02-01 13:56:51 +01:00
|
|
|
error_code_messagebox(hwnd, IDS_BAD_VALUE, valueName);
|
2008-08-29 21:37:43 +02:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
if((valueDataLen % sizeof(WCHAR)) == 0)
|
|
|
|
buffer[valueDataLen / sizeof(WCHAR)] = 0;
|
|
|
|
if(len) *len = valueDataLen;
|
|
|
|
return buffer;
|
|
|
|
|
|
|
|
done:
|
2017-07-27 14:25:26 +02:00
|
|
|
heap_free(buffer);
|
2008-08-29 21:37:43 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-08-21 23:49:34 +02:00
|
|
|
BOOL CreateKey(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, LPWSTR keyName)
|
2004-01-03 01:33:56 +01:00
|
|
|
{
|
2004-01-16 03:21:23 +01:00
|
|
|
BOOL result = FALSE;
|
2004-01-06 21:38:56 +01:00
|
|
|
LONG lRet = ERROR_SUCCESS;
|
2006-10-23 21:30:58 +02:00
|
|
|
HKEY retKey = NULL;
|
2008-08-21 23:49:34 +02:00
|
|
|
WCHAR newKey[MAX_NEW_KEY_LEN - 4];
|
2004-01-06 21:38:56 +01:00
|
|
|
int keyNum;
|
2004-01-16 03:21:23 +01:00
|
|
|
HKEY hKey;
|
2004-01-03 01:33:56 +01:00
|
|
|
|
2008-08-21 23:49:34 +02:00
|
|
|
lRet = RegOpenKeyExW(hKeyRoot, keyPath, 0, KEY_CREATE_SUB_KEY, &hKey);
|
2018-05-21 15:34:58 +02:00
|
|
|
if (lRet) {
|
2017-02-01 13:56:40 +01:00
|
|
|
error_code_messagebox(hwnd, IDS_CREATE_KEY_FAILED);
|
2005-03-21 11:29:09 +01:00
|
|
|
goto done;
|
|
|
|
}
|
2004-01-03 01:33:56 +01:00
|
|
|
|
2018-05-21 15:34:49 +02:00
|
|
|
if (!LoadStringW(GetModuleHandleW(0), IDS_NEWKEY, newKey, ARRAY_SIZE(newKey))) goto done;
|
2004-01-03 01:33:56 +01:00
|
|
|
|
2017-02-01 13:57:32 +01:00
|
|
|
/* try to find a name for the key being created (maximum = 100 attempts) */
|
2004-01-06 21:38:56 +01:00
|
|
|
for (keyNum = 1; keyNum < 100; keyNum++) {
|
2008-08-21 23:49:34 +02:00
|
|
|
wsprintfW(keyName, newKey, keyNum);
|
|
|
|
lRet = RegOpenKeyW(hKey, keyName, &retKey);
|
2018-05-21 15:34:58 +02:00
|
|
|
if (lRet) break;
|
2004-01-06 21:38:56 +01:00
|
|
|
RegCloseKey(retKey);
|
2004-01-03 01:33:56 +01:00
|
|
|
}
|
2004-01-16 03:21:23 +01:00
|
|
|
if (lRet == ERROR_SUCCESS) goto done;
|
2004-01-03 01:33:56 +01:00
|
|
|
|
2008-08-21 23:49:34 +02:00
|
|
|
lRet = RegCreateKeyW(hKey, keyName, &retKey);
|
2018-05-21 15:34:58 +02:00
|
|
|
if (lRet) {
|
2017-02-01 13:56:40 +01:00
|
|
|
error_code_messagebox(hwnd, IDS_CREATE_KEY_FAILED);
|
2005-03-21 11:29:09 +01:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2004-01-16 03:21:23 +01:00
|
|
|
result = TRUE;
|
2004-01-06 21:38:56 +01:00
|
|
|
|
2004-01-16 03:21:23 +01:00
|
|
|
done:
|
2004-01-06 21:38:56 +01:00
|
|
|
RegCloseKey(retKey);
|
2004-01-16 03:21:23 +01:00
|
|
|
return result;
|
2004-01-03 01:33:56 +01:00
|
|
|
}
|
|
|
|
|
2008-08-29 21:37:43 +02:00
|
|
|
BOOL ModifyValue(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, LPCWSTR valueName)
|
2003-12-03 21:25:24 +01:00
|
|
|
{
|
2004-01-16 03:21:23 +01:00
|
|
|
BOOL result = FALSE;
|
2003-12-03 21:25:24 +01:00
|
|
|
DWORD type;
|
|
|
|
LONG lRet;
|
2004-01-16 03:21:23 +01:00
|
|
|
HKEY hKey;
|
2005-04-14 13:30:31 +02:00
|
|
|
LONG len;
|
2003-12-03 21:25:24 +01:00
|
|
|
|
2008-08-29 21:37:43 +02:00
|
|
|
lRet = RegOpenKeyExW(hKeyRoot, keyPath, 0, KEY_READ | KEY_SET_VALUE, &hKey);
|
2018-05-21 15:34:58 +02:00
|
|
|
if (lRet) {
|
2017-02-01 13:56:40 +01:00
|
|
|
error_code_messagebox(hwnd, IDS_SET_VALUE_FAILED);
|
2005-03-21 11:29:09 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2003-12-03 21:25:24 +01:00
|
|
|
|
2008-08-31 16:49:43 +02:00
|
|
|
editValueName = valueName ? valueName : g_pszDefaultValueName;
|
2008-08-29 22:20:26 +02:00
|
|
|
if(!(stringValueData = read_value(hwnd, hKey, valueName, &type, &len))) goto done;
|
2003-12-03 21:25:24 +01:00
|
|
|
|
|
|
|
if ( (type == REG_SZ) || (type == REG_EXPAND_SZ) ) {
|
2008-08-29 21:37:43 +02:00
|
|
|
if (DialogBoxW(0, MAKEINTRESOURCEW(IDD_EDIT_STRING), hwnd, modify_dlgproc) == IDOK) {
|
|
|
|
lRet = RegSetValueExW(hKey, valueName, 0, type, (LPBYTE)stringValueData, (lstrlenW(stringValueData) + 1) * sizeof(WCHAR));
|
2003-12-08 23:48:07 +01:00
|
|
|
if (lRet == ERROR_SUCCESS) result = TRUE;
|
2017-02-01 13:56:40 +01:00
|
|
|
else error_code_messagebox(hwnd, IDS_SET_VALUE_FAILED);
|
2003-12-08 23:48:07 +01:00
|
|
|
}
|
2003-12-03 21:25:24 +01:00
|
|
|
} else if ( type == REG_DWORD ) {
|
2018-07-16 14:20:48 +02:00
|
|
|
static const WCHAR x[] = {'%','x',0};
|
|
|
|
wsprintfW(stringValueData, x, *((DWORD*)stringValueData));
|
2008-08-29 21:37:43 +02:00
|
|
|
if (DialogBoxW(0, MAKEINTRESOURCEW(IDD_EDIT_DWORD), hwnd, modify_dlgproc) == IDOK) {
|
2005-03-21 11:29:09 +01:00
|
|
|
DWORD val;
|
2008-08-29 21:37:43 +02:00
|
|
|
CHAR* valueA = GetMultiByteString(stringValueData);
|
2012-01-23 12:02:39 +01:00
|
|
|
if (sscanf(valueA, isDecimal ? "%u" : "%x", &val)) {
|
2008-08-29 21:37:43 +02:00
|
|
|
lRet = RegSetValueExW(hKey, valueName, 0, type, (BYTE*)&val, sizeof(val));
|
2005-03-21 11:29:09 +01:00
|
|
|
if (lRet == ERROR_SUCCESS) result = TRUE;
|
2017-02-01 13:56:40 +01:00
|
|
|
else error_code_messagebox(hwnd, IDS_SET_VALUE_FAILED);
|
2005-03-21 11:29:09 +01:00
|
|
|
}
|
2017-07-27 14:25:26 +02:00
|
|
|
heap_free(valueA);
|
2004-01-05 22:14:19 +01:00
|
|
|
}
|
2007-03-30 17:14:03 +02:00
|
|
|
} else if ( type == REG_MULTI_SZ ) {
|
2008-08-29 21:37:43 +02:00
|
|
|
WCHAR char1 = '\r', char2 = '\n';
|
|
|
|
WCHAR *tmpValueData = NULL;
|
2007-03-30 17:14:03 +02:00
|
|
|
INT i, j, count;
|
|
|
|
|
|
|
|
for ( i = 0, count = 0; i < len - 1; i++)
|
|
|
|
if ( !stringValueData[i] && stringValueData[i + 1] )
|
|
|
|
count++;
|
2017-07-27 14:25:26 +02:00
|
|
|
tmpValueData = heap_xalloc((len + count) * sizeof(WCHAR));
|
2007-03-30 17:14:03 +02:00
|
|
|
|
|
|
|
for ( i = 0, j = 0; i < len - 1; i++)
|
|
|
|
{
|
|
|
|
if ( !stringValueData[i] && stringValueData[i + 1])
|
|
|
|
{
|
|
|
|
tmpValueData[j++] = char1;
|
|
|
|
tmpValueData[j++] = char2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
tmpValueData[j++] = stringValueData[i];
|
|
|
|
}
|
|
|
|
tmpValueData[j] = stringValueData[i];
|
2017-07-27 14:25:26 +02:00
|
|
|
heap_free(stringValueData);
|
2007-03-30 17:14:03 +02:00
|
|
|
stringValueData = tmpValueData;
|
|
|
|
tmpValueData = NULL;
|
|
|
|
|
2008-08-29 21:37:43 +02:00
|
|
|
if (DialogBoxW(0, MAKEINTRESOURCEW(IDD_EDIT_MULTI_STRING), hwnd, modify_dlgproc) == IDOK)
|
2007-03-30 17:14:03 +02:00
|
|
|
{
|
2008-08-29 21:37:43 +02:00
|
|
|
len = lstrlenW( stringValueData );
|
2017-07-27 14:25:26 +02:00
|
|
|
tmpValueData = heap_xalloc((len + 2) * sizeof(WCHAR));
|
2007-03-30 17:14:03 +02:00
|
|
|
|
|
|
|
for ( i = 0, j = 0; i < len - 1; i++)
|
|
|
|
{
|
|
|
|
if ( stringValueData[i] == char1 && stringValueData[i + 1] == char2)
|
|
|
|
{
|
|
|
|
if ( tmpValueData[j - 1] != 0)
|
|
|
|
tmpValueData[j++] = 0;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
tmpValueData[j++] = stringValueData[i];
|
|
|
|
}
|
|
|
|
tmpValueData[j++] = stringValueData[i];
|
|
|
|
tmpValueData[j++] = 0;
|
|
|
|
tmpValueData[j++] = 0;
|
2017-07-27 14:25:26 +02:00
|
|
|
heap_free(stringValueData);
|
2007-03-30 17:14:03 +02:00
|
|
|
stringValueData = tmpValueData;
|
|
|
|
|
2008-09-02 18:41:42 +02:00
|
|
|
lRet = RegSetValueExW(hKey, valueName, 0, type, (LPBYTE)stringValueData, j * sizeof(WCHAR));
|
2007-03-30 17:14:03 +02:00
|
|
|
if (lRet == ERROR_SUCCESS) result = TRUE;
|
2017-02-01 13:56:40 +01:00
|
|
|
else error_code_messagebox(hwnd, IDS_SET_VALUE_FAILED);
|
2007-03-30 17:14:03 +02:00
|
|
|
}
|
2017-08-07 14:29:01 +02:00
|
|
|
}
|
|
|
|
else /* hex data types */
|
|
|
|
{
|
|
|
|
struct edit_params params;
|
|
|
|
|
2018-07-16 14:20:49 +02:00
|
|
|
params.hkey = hKey;
|
|
|
|
params.value_name = valueName;
|
2018-07-16 14:20:50 +02:00
|
|
|
params.type = type;
|
2018-07-16 14:20:49 +02:00
|
|
|
params.data = stringValueData;
|
|
|
|
params.size = len;
|
2017-08-07 14:29:01 +02:00
|
|
|
result = DialogBoxParamW(NULL, MAKEINTRESOURCEW(IDD_EDIT_BINARY), hwnd,
|
|
|
|
bin_modify_dlgproc, (LPARAM)¶ms);
|
2003-12-03 21:25:24 +01:00
|
|
|
}
|
|
|
|
|
2017-05-29 10:20:44 +02:00
|
|
|
/* Update the listview item with the new data string */
|
|
|
|
if (result)
|
|
|
|
{
|
|
|
|
int index = SendMessageW(g_pChildWnd->hListWnd, LVM_GETNEXTITEM, -1,
|
|
|
|
MAKELPARAM(LVNI_FOCUSED | LVNI_SELECTED, 0));
|
2017-07-27 14:25:26 +02:00
|
|
|
heap_free(stringValueData);
|
2017-05-29 10:20:44 +02:00
|
|
|
stringValueData = read_value(hwnd, hKey, valueName, &type, &len);
|
|
|
|
format_value_data(g_pChildWnd->hListWnd, index, type, stringValueData, len);
|
|
|
|
}
|
|
|
|
|
2003-12-03 21:25:24 +01:00
|
|
|
done:
|
2017-07-27 14:25:26 +02:00
|
|
|
heap_free(stringValueData);
|
2003-12-03 21:25:24 +01:00
|
|
|
stringValueData = NULL;
|
2004-01-16 03:21:23 +01:00
|
|
|
RegCloseKey(hKey);
|
2003-12-03 21:25:24 +01:00
|
|
|
return result;
|
|
|
|
}
|
2004-01-05 22:14:19 +01:00
|
|
|
|
2008-08-09 02:25:34 +02:00
|
|
|
BOOL DeleteKey(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath)
|
2004-03-12 20:44:47 +01:00
|
|
|
{
|
|
|
|
BOOL result = FALSE;
|
|
|
|
LONG lRet;
|
|
|
|
HKEY hKey;
|
2008-08-09 02:25:34 +02:00
|
|
|
|
|
|
|
lRet = RegOpenKeyExW(hKeyRoot, keyPath, 0, KEY_READ|KEY_SET_VALUE, &hKey);
|
2018-05-21 15:34:58 +02:00
|
|
|
if (lRet) {
|
2017-02-01 13:56:40 +01:00
|
|
|
error_code_messagebox(hwnd, IDS_DELETE_KEY_FAILED);
|
2005-03-21 11:29:09 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2004-03-12 20:44:47 +01:00
|
|
|
|
2017-07-12 13:09:23 +02:00
|
|
|
if (messagebox(hwnd, MB_YESNO | MB_ICONEXCLAMATION, IDS_DELETE_KEY_TITLE,
|
|
|
|
IDS_DELETE_KEY_TEXT) != IDYES)
|
2004-03-12 20:44:47 +01:00
|
|
|
goto done;
|
|
|
|
|
2008-08-09 02:25:34 +02:00
|
|
|
lRet = SHDeleteKeyW(hKeyRoot, keyPath);
|
2018-05-21 15:34:58 +02:00
|
|
|
if (lRet) {
|
2017-02-01 13:56:51 +01:00
|
|
|
error_code_messagebox(hwnd, IDS_BAD_KEY, keyPath);
|
2004-03-12 20:44:47 +01:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
result = TRUE;
|
|
|
|
|
|
|
|
done:
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-05-28 15:48:06 +02:00
|
|
|
BOOL DeleteValue(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, LPCWSTR valueName)
|
2004-01-05 22:14:19 +01:00
|
|
|
{
|
2004-01-16 03:21:23 +01:00
|
|
|
BOOL result = FALSE;
|
2004-01-05 22:14:19 +01:00
|
|
|
LONG lRet;
|
2004-01-16 03:21:23 +01:00
|
|
|
HKEY hKey;
|
2004-01-05 22:14:19 +01:00
|
|
|
|
2008-08-09 02:25:34 +02:00
|
|
|
lRet = RegOpenKeyExW(hKeyRoot, keyPath, 0, KEY_READ | KEY_SET_VALUE, &hKey);
|
2018-05-21 15:34:58 +02:00
|
|
|
if (lRet) return FALSE;
|
2004-01-05 22:14:19 +01:00
|
|
|
|
2018-05-28 15:48:07 +02:00
|
|
|
lRet = RegDeleteValueW(hKey, valueName);
|
2018-05-21 15:34:58 +02:00
|
|
|
if (lRet && valueName) {
|
2017-02-01 13:56:51 +01:00
|
|
|
error_code_messagebox(hwnd, IDS_BAD_VALUE, valueName);
|
2004-01-05 22:14:19 +01:00
|
|
|
}
|
2018-05-21 15:34:58 +02:00
|
|
|
if (lRet) goto done;
|
2004-01-16 03:21:23 +01:00
|
|
|
result = TRUE;
|
|
|
|
|
|
|
|
done:
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
return result;
|
2004-01-05 22:14:19 +01:00
|
|
|
}
|
2004-01-06 21:38:56 +01:00
|
|
|
|
2008-08-28 16:18:44 +02:00
|
|
|
BOOL CreateValue(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, DWORD valueType, LPWSTR valueName)
|
2004-01-06 21:38:56 +01:00
|
|
|
{
|
|
|
|
LONG lRet = ERROR_SUCCESS;
|
2008-08-28 16:18:44 +02:00
|
|
|
WCHAR newValue[256];
|
2004-01-06 21:38:56 +01:00
|
|
|
DWORD valueDword = 0;
|
2004-01-16 03:21:23 +01:00
|
|
|
BOOL result = FALSE;
|
2017-05-29 10:20:34 +02:00
|
|
|
int valueNum, index;
|
2004-01-16 03:21:23 +01:00
|
|
|
HKEY hKey;
|
2017-05-29 10:20:34 +02:00
|
|
|
LVITEMW item;
|
2004-01-06 21:38:56 +01:00
|
|
|
|
2008-08-28 16:18:44 +02:00
|
|
|
lRet = RegOpenKeyExW(hKeyRoot, keyPath, 0, KEY_READ | KEY_SET_VALUE, &hKey);
|
2018-05-21 15:34:58 +02:00
|
|
|
if (lRet) {
|
2017-02-01 13:56:40 +01:00
|
|
|
error_code_messagebox(hwnd, IDS_CREATE_VALUE_FAILED);
|
2005-03-21 11:29:09 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2004-01-06 21:38:56 +01:00
|
|
|
|
2018-05-21 15:34:49 +02:00
|
|
|
if (!LoadStringW(GetModuleHandleW(0), IDS_NEWVALUE, newValue, ARRAY_SIZE(newValue))) goto done;
|
2004-01-06 21:38:56 +01:00
|
|
|
|
2017-02-01 13:57:32 +01:00
|
|
|
/* try to find a name for the value being created (maximum = 100 attempts) */
|
2004-01-06 21:38:56 +01:00
|
|
|
for (valueNum = 1; valueNum < 100; valueNum++) {
|
2008-08-28 16:18:44 +02:00
|
|
|
wsprintfW(valueName, newValue, valueNum);
|
|
|
|
lRet = RegQueryValueExW(hKey, valueName, 0, 0, 0, 0);
|
2005-03-21 11:29:09 +01:00
|
|
|
if (lRet == ERROR_FILE_NOT_FOUND) break;
|
|
|
|
}
|
|
|
|
if (lRet != ERROR_FILE_NOT_FOUND) {
|
2017-02-01 13:56:40 +01:00
|
|
|
error_code_messagebox(hwnd, IDS_CREATE_VALUE_FAILED);
|
2005-03-21 11:29:09 +01:00
|
|
|
goto done;
|
2004-01-06 21:38:56 +01:00
|
|
|
}
|
|
|
|
|
2008-08-28 16:18:44 +02:00
|
|
|
lRet = RegSetValueExW(hKey, valueName, 0, valueType, (BYTE*)&valueDword, sizeof(DWORD));
|
2018-05-21 15:34:58 +02:00
|
|
|
if (lRet) {
|
2017-02-01 13:56:40 +01:00
|
|
|
error_code_messagebox(hwnd, IDS_CREATE_VALUE_FAILED);
|
2005-03-21 11:29:09 +01:00
|
|
|
goto done;
|
|
|
|
}
|
2017-05-29 10:20:34 +02:00
|
|
|
|
|
|
|
/* Add the new item to the listview */
|
2017-06-16 15:06:59 +02:00
|
|
|
index = AddEntryToList(g_pChildWnd->hListWnd, valueName, valueType,
|
|
|
|
(BYTE *)&valueDword, sizeof(DWORD), -1);
|
2017-05-29 10:20:34 +02:00
|
|
|
item.state = LVIS_FOCUSED | LVIS_SELECTED;
|
|
|
|
item.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
|
|
|
|
SendMessageW(g_pChildWnd->hListWnd, LVM_SETITEMSTATE, index, (LPARAM)&item);
|
|
|
|
|
2004-01-16 03:21:23 +01:00
|
|
|
result = TRUE;
|
2004-01-06 21:38:56 +01:00
|
|
|
|
2004-01-16 03:21:23 +01:00
|
|
|
done:
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
return result;
|
2004-01-06 21:38:56 +01:00
|
|
|
}
|
2004-01-14 00:18:12 +01:00
|
|
|
|
2008-08-29 22:20:26 +02:00
|
|
|
BOOL RenameValue(HWND hwnd, HKEY hKeyRoot, LPCWSTR keyPath, LPCWSTR oldName, LPCWSTR newName)
|
2004-01-14 00:18:12 +01:00
|
|
|
{
|
2008-08-29 22:20:26 +02:00
|
|
|
LPWSTR value = NULL;
|
2004-01-14 00:18:12 +01:00
|
|
|
DWORD type;
|
|
|
|
LONG len, lRet;
|
|
|
|
BOOL result = FALSE;
|
|
|
|
HKEY hKey;
|
|
|
|
|
2004-05-04 04:55:28 +02:00
|
|
|
if (!oldName) return FALSE;
|
2004-01-17 00:02:44 +01:00
|
|
|
if (!newName) return FALSE;
|
|
|
|
|
2008-08-29 22:20:26 +02:00
|
|
|
lRet = RegOpenKeyExW(hKeyRoot, keyPath, 0, KEY_READ | KEY_SET_VALUE, &hKey);
|
2018-05-21 15:34:58 +02:00
|
|
|
if (lRet) {
|
2017-02-01 13:56:40 +01:00
|
|
|
error_code_messagebox(hwnd, IDS_RENAME_VALUE_FAILED);
|
2005-03-21 11:29:09 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2018-05-21 15:34:57 +02:00
|
|
|
|
|
|
|
if (value_exists(hwnd, hKey, newName)) {
|
2017-02-01 13:57:20 +01:00
|
|
|
error_code_messagebox(hwnd, IDS_VALUE_EXISTS, oldName);
|
|
|
|
goto done;
|
|
|
|
}
|
2004-01-14 00:18:12 +01:00
|
|
|
value = read_value(hwnd, hKey, oldName, &type, &len);
|
|
|
|
if(!value) goto done;
|
2008-08-29 22:20:26 +02:00
|
|
|
lRet = RegSetValueExW(hKey, newName, 0, type, (BYTE*)value, len);
|
2018-05-21 15:34:58 +02:00
|
|
|
if (lRet) {
|
2017-02-01 13:56:40 +01:00
|
|
|
error_code_messagebox(hwnd, IDS_RENAME_VALUE_FAILED);
|
2005-03-21 11:29:09 +01:00
|
|
|
goto done;
|
|
|
|
}
|
2008-08-29 22:20:26 +02:00
|
|
|
lRet = RegDeleteValueW(hKey, oldName);
|
2018-05-21 15:34:58 +02:00
|
|
|
if (lRet) {
|
2008-08-29 22:20:26 +02:00
|
|
|
RegDeleteValueW(hKey, newName);
|
2017-02-01 13:56:40 +01:00
|
|
|
error_code_messagebox(hwnd, IDS_RENAME_VALUE_FAILED);
|
2004-01-14 00:18:12 +01:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
result = TRUE;
|
|
|
|
|
|
|
|
done:
|
2017-07-27 14:25:26 +02:00
|
|
|
heap_free(value);
|
2004-01-16 03:21:23 +01:00
|
|
|
RegCloseKey(hKey);
|
2004-01-14 00:18:12 +01:00
|
|
|
return result;
|
|
|
|
}
|
2004-03-15 21:19:38 +01:00
|
|
|
|
|
|
|
|
2008-08-30 23:50:24 +02:00
|
|
|
BOOL RenameKey(HWND hwnd, HKEY hRootKey, LPCWSTR keyPath, LPCWSTR newName)
|
2004-03-15 21:19:38 +01:00
|
|
|
{
|
2008-08-30 23:50:24 +02:00
|
|
|
LPWSTR parentPath = 0;
|
|
|
|
LPCWSTR srcSubKey = 0;
|
2004-03-15 21:19:38 +01:00
|
|
|
HKEY parentKey = 0;
|
|
|
|
HKEY destKey = 0;
|
|
|
|
BOOL result = FALSE;
|
|
|
|
LONG lRet;
|
2005-03-21 11:29:09 +01:00
|
|
|
DWORD disposition;
|
2004-03-15 21:19:38 +01:00
|
|
|
|
|
|
|
if (!keyPath || !newName) return FALSE;
|
|
|
|
|
2008-08-30 23:50:24 +02:00
|
|
|
if (!strrchrW(keyPath, '\\')) {
|
2004-03-15 21:19:38 +01:00
|
|
|
parentKey = hRootKey;
|
|
|
|
srcSubKey = keyPath;
|
|
|
|
} else {
|
2008-08-30 23:50:24 +02:00
|
|
|
LPWSTR srcSubKey_copy;
|
2006-10-05 23:01:55 +02:00
|
|
|
|
2017-07-27 14:25:26 +02:00
|
|
|
parentPath = heap_xalloc((lstrlenW(keyPath) + 1) * sizeof(WCHAR));
|
2008-08-30 23:50:24 +02:00
|
|
|
lstrcpyW(parentPath, keyPath);
|
|
|
|
srcSubKey_copy = strrchrW(parentPath, '\\');
|
2006-10-05 23:01:55 +02:00
|
|
|
*srcSubKey_copy = 0;
|
|
|
|
srcSubKey = srcSubKey_copy + 1;
|
2008-08-30 23:50:24 +02:00
|
|
|
lRet = RegOpenKeyExW(hRootKey, parentPath, 0, KEY_READ | KEY_CREATE_SUB_KEY, &parentKey);
|
2018-05-21 15:34:58 +02:00
|
|
|
if (lRet) {
|
2017-02-01 13:56:40 +01:00
|
|
|
error_code_messagebox(hwnd, IDS_RENAME_KEY_FAILED);
|
2005-03-21 11:29:09 +01:00
|
|
|
goto done;
|
|
|
|
}
|
2004-03-15 21:19:38 +01:00
|
|
|
}
|
|
|
|
|
2005-01-10 17:03:22 +01:00
|
|
|
/* The following fails if the old name is the same as the new name. */
|
2008-08-30 23:50:24 +02:00
|
|
|
if (!lstrcmpW(srcSubKey, newName)) goto done;
|
2005-01-10 17:03:22 +01:00
|
|
|
|
2008-08-30 23:50:24 +02:00
|
|
|
lRet = RegCreateKeyExW(parentKey, newName, 0, NULL, REG_OPTION_NON_VOLATILE,
|
2005-03-21 11:29:09 +01:00
|
|
|
KEY_WRITE, NULL /* FIXME */, &destKey, &disposition);
|
|
|
|
if (disposition == REG_OPENED_EXISTING_KEY)
|
2017-02-01 13:56:40 +01:00
|
|
|
lRet = ERROR_FILE_EXISTS;
|
2018-05-21 15:34:58 +02:00
|
|
|
if (lRet) {
|
2017-02-01 13:57:20 +01:00
|
|
|
error_code_messagebox(hwnd, IDS_KEY_EXISTS, srcSubKey);
|
2005-03-21 11:29:09 +01:00
|
|
|
goto done;
|
|
|
|
}
|
2004-03-15 21:19:38 +01:00
|
|
|
|
|
|
|
/* FIXME: SHCopyKey does not copy the security attributes */
|
2008-08-30 23:50:24 +02:00
|
|
|
lRet = SHCopyKeyW(parentKey, srcSubKey, destKey, 0);
|
2018-05-21 15:34:58 +02:00
|
|
|
if (lRet) {
|
2005-03-21 11:29:09 +01:00
|
|
|
RegCloseKey(destKey);
|
2008-08-30 23:50:24 +02:00
|
|
|
RegDeleteKeyW(parentKey, newName);
|
2017-02-01 13:56:40 +01:00
|
|
|
error_code_messagebox(hwnd, IDS_RENAME_KEY_FAILED);
|
2005-03-21 11:29:09 +01:00
|
|
|
goto done;
|
|
|
|
}
|
2004-03-15 21:19:38 +01:00
|
|
|
|
2008-08-30 23:50:24 +02:00
|
|
|
lRet = SHDeleteKeyW(hRootKey, keyPath);
|
2018-05-21 15:34:58 +02:00
|
|
|
if (lRet) {
|
2017-02-01 13:56:40 +01:00
|
|
|
error_code_messagebox(hwnd, IDS_RENAME_KEY_FAILED);
|
2005-03-21 11:29:09 +01:00
|
|
|
goto done;
|
|
|
|
}
|
2004-03-15 21:19:38 +01:00
|
|
|
|
|
|
|
result = TRUE;
|
|
|
|
|
|
|
|
done:
|
|
|
|
RegCloseKey(destKey);
|
|
|
|
if (parentKey) {
|
|
|
|
RegCloseKey(parentKey);
|
2017-07-27 14:25:26 +02:00
|
|
|
heap_free(parentPath);
|
2004-03-15 21:19:38 +01:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|