diff --git a/reactos/subsys/system/regedit/En.rc b/reactos/subsys/system/regedit/En.rc index 8617b4a0a83..fb4874e4d82 100644 --- a/reactos/subsys/system/regedit/En.rc +++ b/reactos/subsys/system/regedit/En.rc @@ -142,6 +142,20 @@ BEGIN PUSHBUTTON "Cancel",IDCANCEL,196,64,50,14 END +IDD_EDIT_MULTI_STRING DIALOG 32, 24, 252, 174 +STYLE DS_SETFONT | DS_MODALFRAME | DS_NOIDLEMSG | DS_3DLOOK | DS_CONTEXTHELP | + WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU +CAPTION "Edit Multi-String" +FONT 8, "MS Shell Dlg" +BEGIN + LTEXT "Value &name:",IDC_STATIC,6,6,134,8 + EDITTEXT IDC_VALUE_NAME,6,17,240,12,ES_AUTOHSCROLL | ES_READONLY + LTEXT "&Value data:",IDC_STATIC,6,35,161,8 + EDITTEXT IDC_VALUE_DATA,6,46,240,102,ES_AUTOHSCROLL | ES_MULTILINE | ES_WANTRETURN | ES_AUTOVSCROLL | WS_VSCROLL + DEFPUSHBUTTON "OK",IDOK,142,154,50,14 + PUSHBUTTON "Cancel",IDCANCEL,196,154,50,14 +END + IDD_EDIT_DWORD DIALOG 32, 24, 252, 104 STYLE DS_SETFONT | DS_MODALFRAME | DS_NOIDLEMSG | DS_3DLOOK | DS_CONTEXTHELP | @@ -225,9 +239,11 @@ END STRINGTABLE DISCARDABLE BEGIN IDS_ERROR "Error" + IDS_WARNING "Warning" IDS_BAD_VALUE "Can't query value '%s'" IDS_UNSUPPORTED_TYPE "Can't edit keys of this type (%ld)" IDS_TOO_BIG_VALUE "Value is too big (%ld)" + IDS_MULTI_SZ_EMPTY_STRING "Data of type REG_MULTI_SZ cannot contain empty strings.\nThe empty strings have been removed from the list." END /*****************************************************************/ diff --git a/reactos/subsys/system/regedit/edit.c b/reactos/subsys/system/regedit/edit.c index 7523f59773c..abddc30a5fc 100644 --- a/reactos/subsys/system/regedit/edit.c +++ b/reactos/subsys/system/regedit/edit.c @@ -71,6 +71,29 @@ void error(HWND hwnd, INT resId, ...) MessageBox(hwnd, errstr, title, MB_OK | MB_ICONERROR); } +void warning(HWND hwnd, INT resId, ...) +{ + va_list ap; + TCHAR title[256]; + TCHAR errfmt[1024]; + TCHAR errstr[1024]; + HINSTANCE hInstance; + + hInstance = GetModuleHandle(0); + + if (!LoadString(hInstance, IDS_WARNING, title, COUNT_OF(title))) + lstrcpy(title, "Error"); + + if (!LoadString(hInstance, resId, errfmt, COUNT_OF(errfmt))) + lstrcpy(errfmt, "Unknown error string!"); + + va_start(ap, resId); + _vsntprintf(errstr, COUNT_OF(errstr), errfmt, ap); + va_end(ap); + + MessageBox(hwnd, errstr, title, MB_OK | MB_ICONSTOP); +} + INT_PTR CALLBACK modify_string_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { TCHAR* valueData; @@ -134,6 +157,69 @@ INT_PTR CALLBACK modify_string_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, L } +INT_PTR CALLBACK modify_multi_string_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + TCHAR* valueData; + HWND hwndValue; + int len; + + switch(uMsg) { + case WM_INITDIALOG: + if(editValueName && strcmp(editValueName, _T(""))) + { + SetDlgItemText(hwndDlg, IDC_VALUE_NAME, editValueName); + } + else + { + SetDlgItemText(hwndDlg, IDC_VALUE_NAME, _T("(Default)")); + } + SetDlgItemText(hwndDlg, IDC_VALUE_DATA, stringValueData); + SetFocus(GetDlgItem(hwndDlg, IDC_VALUE_DATA)); + return FALSE; + case WM_COMMAND: + switch (LOWORD(wParam)) + { + case IDOK: + if ((hwndValue = GetDlgItem(hwndDlg, IDC_VALUE_DATA))) + { + if ((len = GetWindowTextLength(hwndValue))) + { + if (stringValueData) + { + if ((valueData = HeapReAlloc(GetProcessHeap(), 0, stringValueData, (len + 1) * sizeof(TCHAR)))) + { + stringValueData = valueData; + if (!GetWindowText(hwndValue, stringValueData, len + 1)) + *stringValueData = 0; + } + } + else + { + if ((valueData = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(TCHAR)))) + { + stringValueData = valueData; + if (!GetWindowText(hwndValue, stringValueData, len + 1)) + *stringValueData = 0; + } + } + } + else + { + if (stringValueData) + *stringValueData = 0; + } + } + EndDialog(hwndDlg, IDOK); + break; + case IDCANCEL: + EndDialog(hwndDlg, IDCANCEL); + return TRUE; + } + } + return FALSE; +} + + LRESULT CALLBACK DwordEditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { WNDPROC oldwndproc; @@ -362,6 +448,112 @@ BOOL ModifyValue(HWND hwnd, HKEY hKey, LPCTSTR valueName) result = TRUE; } } + else if (type == REG_MULTI_SZ) + { + if (valueDataLen > 0) + { + DWORD NewLen, llen, listlen, nl_len; + LPTSTR src, lines = NULL; + + if (!(stringValueData = HeapAlloc(GetProcessHeap(), 0, valueDataLen))) + { + error(hwnd, IDS_TOO_BIG_VALUE, valueDataLen); + goto done; + } + lRet = RegQueryValueEx(hKey, valueName, 0, 0, stringValueData, &valueDataLen); + if (lRet != ERROR_SUCCESS) + { + error(hwnd, IDS_BAD_VALUE, valueName); + goto done; + } + + /* convert \0 to \r\n */ + NewLen = valueDataLen; + src = stringValueData; + nl_len = _tcslen(_T("\r\n")) * sizeof(TCHAR); + listlen = sizeof(TCHAR); + lines = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, listlen + sizeof(TCHAR)); + while(*src != _T('\0')) + { + llen = _tcslen(src); + if(llen == 0) + break; + listlen += (llen * sizeof(TCHAR)) + nl_len; + lines = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, lines, listlen); + _tcscat(lines, src); + _tcscat(lines, _T("\r\n")); + src += llen + 1; + } + HeapFree(GetProcessHeap(), 0, stringValueData); + stringValueData = lines; + } + else + { + stringValueData = NULL; + } + + if (DialogBox(0, MAKEINTRESOURCE(IDD_EDIT_MULTI_STRING), hwnd, modify_multi_string_dlgproc) == IDOK) + { + if (stringValueData) + { + /* convert \r\n to \0 */ + BOOL EmptyLines = FALSE; + LPTSTR src, lines, nl; + DWORD linechars, buflen, c_nl, dest; + + src = stringValueData; + buflen = sizeof(TCHAR); + lines = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, buflen + sizeof(TCHAR)); + c_nl = _tcslen(_T("\r\n")); + dest = 0; + while(*src != _T('\0')) + { + if((nl = _tcsstr(src, _T("\r\n")))) + { + linechars = (nl - src) / sizeof(TCHAR); + if(nl == src) + { + EmptyLines = TRUE; + src = nl + c_nl; + continue; + } + } + else + { + linechars = _tcslen(src); + } + if(linechars > 0) + { + buflen += ((linechars + 1) * sizeof(TCHAR)); + lines = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, lines, buflen); + memcpy((lines + dest), src, linechars * sizeof(TCHAR)); + dest += linechars; + lines[dest++] = _T('\0'); + } + else + { + EmptyLines = TRUE; + } + src += linechars + (nl != NULL ? c_nl : 0); + } + lines[++dest] = _T('\0'); + + if(EmptyLines) + { + warning(hwnd, IDS_MULTI_SZ_EMPTY_STRING); + } + + lRet = RegSetValueEx(hKey, valueName, 0, type, lines, buflen); + HeapFree(GetProcessHeap(), 0, lines); + } + else + { + lRet = RegSetValueEx(hKey, valueName, 0, type, NULL, 0); + } + if (lRet == ERROR_SUCCESS) + result = TRUE; + } + } else if (type == REG_DWORD) { lRet = RegQueryValueEx(hKey, valueName, 0, 0, (LPBYTE)&dwordValueData, &valueDataLen); diff --git a/reactos/subsys/system/regedit/listview.c b/reactos/subsys/system/regedit/listview.c index 0e6efb2becc..a9525a1c6de 100644 --- a/reactos/subsys/system/regedit/listview.c +++ b/reactos/subsys/system/regedit/listview.c @@ -159,8 +159,6 @@ static void AddEntryToList(HWND hwndLV, LPTSTR Name, DWORD dwValType, void* ValB index = ListView_InsertItem(hwndLV, &item); if (index != -1) { - /* LPTSTR pszText = NULL; */ - LPTSTR pszText = _T("value"); switch (dwValType) { case REG_SZ: case REG_EXPAND_SZ: @@ -182,14 +180,18 @@ static void AddEntryToList(HWND hwndLV, LPTSTR Name, DWORD dwValType, void* ValB /* concatenate all srings */ while(*src != _T('\0')) { - _tcscat(str, _T(" ")); _tcscat(str, src); + _tcscat(str, _T(" ")); src += _tcslen(src) + 1; } ListView_SetItemText(hwndLV, index, 2, str); HeapFree(GetProcessHeap(), 0, str); } + else + ListView_SetItemText(hwndLV, index, 2, _T("")); } + else + ListView_SetItemText(hwndLV, index, 2, _T("")); } break; case REG_DWORD: { @@ -212,8 +214,7 @@ static void AddEntryToList(HWND hwndLV, LPTSTR Name, DWORD dwValType, void* ValB } break; default: - /* lpsRes = convertHexToHexCSV(lpbData, dwLen); */ - ListView_SetItemText(hwndLV, index, 2, pszText); + ListView_SetItemText(hwndLV, index, 2, _T("(value)")); break; } } diff --git a/reactos/subsys/system/regedit/resource.h b/reactos/subsys/system/regedit/resource.h index cccd1129d79..83cae73a35c 100644 --- a/reactos/subsys/system/regedit/resource.h +++ b/reactos/subsys/system/regedit/resource.h @@ -109,6 +109,8 @@ #define IDS_UNSUPPORTED_TYPE 32838 #define IDS_TOO_BIG_VALUE 32839 #define ID_EDIT_MODIFY_BIN 32840 +#define IDS_WARNING 32841 +#define IDS_MULTI_SZ_EMPTY_STRING 32842 #define IDD_EDIT_STRING 2000 #define IDC_VALUE_NAME 2001 @@ -118,4 +120,6 @@ #define IDC_FORMAT_HEX 2004 #define IDC_FORMAT_DEC 2005 +#define IDD_EDIT_MULTI_STRING 2006 + #define IDC_STATIC -1