Commit 4352892f authored by Dimitrie O. Paun's avatar Dimitrie O. Paun Committed by Alexandre Julliard

Add value delete, and dword edit support.

parent 41b72184
......@@ -132,6 +132,21 @@ BEGIN
DEFPUSHBUTTON "Cancel",IDCANCEL,175,60,30,11,WS_GROUP
END
IDD_EDIT_DWORD DIALOG DISCARDABLE 22, 17, 210, 100
STYLE DS_MODALFRAME | WS_CAPTION | WS_SYSMENU
CAPTION "Edit String"
FONT 8, "System"
BEGIN
LTEXT "Value name:",IDC_STATIC,5,5,119,8
EDITTEXT IDC_VALUE_NAME,5,15,200,12, WS_BORDER | WS_TABSTOP | WS_DISABLED
LTEXT "Value data:",IDC_STATIC,5,30,90,8
EDITTEXT IDC_VALUE_DATA,5,40,90,12, WS_BORDER | WS_TABSTOP
GROUPBOX "Base", IDC_DWORD_BASE, 120, 30, 85, 37, BS_GROUPBOX
AUTORADIOBUTTON "Hexadecimal", IDC_DWORD_HEX, 130, 40, 60, 10, WS_TABSTOP
AUTORADIOBUTTON "Decimal", IDC_DWORD_DEC, 130, 52, 60, 10, WS_TABSTOP
DEFPUSHBUTTON "OK",IDOK,140,80,30,11,WS_GROUP
DEFPUSHBUTTON "Cancel",IDCANCEL,175,80,30,11,WS_GROUP
END
/*
* String Table
......@@ -201,6 +216,8 @@ BEGIN
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_DELETE_BOX_TITLE "Confirm Value Delete"
IDS_DELETE_BOX_TEXT "Are you sure you want to delete value '%s'?"
IDS_NEWKEY "New Key"
END
......
......@@ -35,31 +35,58 @@
static const TCHAR* editValueName;
static TCHAR* stringValueData;
static BOOL isDecimal;
void error(HWND hwnd, INT resId, ...)
INT vmessagebox(HWND hwnd, INT buttons, INT titleId, INT resId, va_list ap)
{
va_list ap;
TCHAR title[256];
TCHAR errfmt[1024];
TCHAR errstr[1024];
HINSTANCE hInstance;
hInstance = GetModuleHandle(0);
if (!LoadString(hInstance, IDS_ERROR, title, COUNT_OF(title)))
if (!LoadString(hInst, titleId, title, COUNT_OF(title)))
lstrcpy(title, "Error");
if (!LoadString(hInstance, resId, errfmt, COUNT_OF(errfmt)))
if (!LoadString(hInst, resId, errfmt, COUNT_OF(errfmt)))
lstrcpy(errfmt, "Unknown error string!");
va_start(ap, resId);
_vsntprintf(errstr, COUNT_OF(errstr), errfmt, ap);
return MessageBox(hwnd, errstr, title, buttons);
}
INT messagebox(HWND hwnd, INT buttons, INT titleId, INT resId, ...)
{
va_list ap;
INT result;
va_start(ap, resId);
result = vmessagebox(hwnd, buttons, titleId, resId, ap);
va_end(ap);
MessageBox(hwnd, errstr, title, MB_OK | MB_ICONERROR);
return result;
}
INT_PTR CALLBACK modify_string_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
void error(HWND hwnd, INT resId, ...)
{
va_list ap;
va_start(ap, resId);
vmessagebox(hwnd, MB_OK | MB_ICONERROR, IDS_ERROR, resId, ap);
va_end(ap);
}
BOOL change_dword_base(HWND hwndDlg, BOOL toHex)
{
TCHAR buf[128];
DWORD val;
if (!GetDlgItemText(hwndDlg, IDC_VALUE_DATA, buf, COUNT_OF(buf))) return FALSE;
if (!_stscanf(buf, toHex ? "%ld" : "%lx", &val)) return FALSE;
wsprintf(buf, toHex ? "%lx" : "%ld", val);
return SetDlgItemText(hwndDlg, IDC_VALUE_DATA, buf);
}
INT_PTR CALLBACK modify_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
TCHAR* valueData;
HWND hwndValue;
......@@ -69,9 +96,16 @@ INT_PTR CALLBACK modify_string_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, L
case WM_INITDIALOG:
SetDlgItemText(hwndDlg, IDC_VALUE_NAME, editValueName);
SetDlgItemText(hwndDlg, IDC_VALUE_DATA, stringValueData);
CheckRadioButton(hwndDlg, IDC_DWORD_HEX, IDC_DWORD_DEC, isDecimal ? IDC_DWORD_DEC : IDC_DWORD_HEX);
return TRUE;
case WM_COMMAND:
switch (LOWORD(wParam)) {
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;
case IDOK:
if ((hwndValue = GetDlgItem(hwndDlg, IDC_VALUE_DATA))) {
if ((len = GetWindowTextLength(hwndValue))) {
......@@ -108,7 +142,7 @@ BOOL CreateKey(HKEY hKey)
if (newKey[0] == 0) {
hInstance = GetModuleHandle(0);
if (!LoadString(hInstance, IDS_NEWKEY, newKey, COUNT_OF(newKey)))
lstrcpy(newKey, "new key");
lstrcpy(newKey, "New Key");
}
lstrcpy(keyName, newKey);
......@@ -116,8 +150,8 @@ BOOL CreateKey(HKEY hKey)
We try it max 100 times. */
lRet = RegOpenKey(hKey, keyName, &retKey);
while (lRet == ERROR_SUCCESS && keyNum < 100) {
sprintf(keyName, "%s %u", newKey, ++keyNum);
lRet = RegOpenKey(hKey, keyName, &retKey);
wsprintf(keyName, "%s %u", newKey, ++keyNum);
lRet = RegOpenKey(hKey, keyName, &retKey);
}
if (lRet == ERROR_SUCCESS) return FALSE;
......@@ -141,23 +175,31 @@ BOOL ModifyValue(HWND hwnd, HKEY hKey, LPCTSTR valueName)
error(hwnd, IDS_BAD_VALUE, valueName);
goto done;
}
if ( type == REG_DWORD ) valueDataLen = 128;
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;
}
if ( (type == REG_SZ) || (type == REG_EXPAND_SZ) ) {
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;
}
if (DialogBox(0, MAKEINTRESOURCE(IDD_EDIT_STRING), hwnd, modify_string_dlgproc) == IDOK) {
if (DialogBox(0, MAKEINTRESOURCE(IDD_EDIT_STRING), hwnd, modify_dlgproc) == IDOK) {
lRet = RegSetValueEx(hKey, valueName, 0, type, stringValueData, lstrlen(stringValueData) + 1);
if (lRet == ERROR_SUCCESS) result = TRUE;
}
} else if ( type == REG_DWORD ) {
MessageBox(hwnd, "Can't edit dwords for now", "Error", MB_OK | MB_ICONERROR);
wsprintf(stringValueData, isDecimal ? "%ld" : "%lx", *((DWORD*)stringValueData));
if (DialogBox(0, MAKEINTRESOURCE(IDD_EDIT_DWORD), hwnd, modify_dlgproc) == IDOK) {
DWORD val;
if (_stscanf(stringValueData, isDecimal ? "%ld" : "%lx", &val)) {
lRet = RegSetValueEx(hKey, valueName, 0, type, (BYTE*)&val, sizeof(val));
if (lRet == ERROR_SUCCESS) result = TRUE;
}
}
} else {
error(hwnd, IDS_UNSUPPORTED_TYPE, type);
}
......@@ -168,3 +210,19 @@ done:
return result;
}
BOOL DeleteValue(HWND hwnd, HKEY hKey, LPCTSTR valueName)
{
LONG lRet;
if (!hKey || !valueName) return FALSE;
if (messagebox(hwnd, MB_YESNO | MB_ICONEXCLAMATION, IDS_DELETE_BOX_TITLE, IDS_DELETE_BOX_TEXT, valueName) != IDYES)
return FALSE;
lRet = RegDeleteValue(hKey, valueName);
if (lRet != ERROR_SUCCESS) {
error(hwnd, IDS_BAD_VALUE, valueName);
}
return lRet == ERROR_SUCCESS;
}
......@@ -441,12 +441,11 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
BOOL result = TRUE;
LONG lRet;
keyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hKeyRoot);
valueName = GetValueName(g_pChildWnd->hListWnd);
if (keyPath) {
lRet = RegOpenKeyEx(hKeyRoot, keyPath, 0, KEY_READ, &hKey);
if ((keyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hKeyRoot))) {
lRet = RegOpenKeyEx(hKeyRoot, keyPath, 0, KEY_ALL_ACCESS, &hKey);
if (lRet != ERROR_SUCCESS) hKey = 0;
}
valueName = GetValueName(g_pChildWnd->hListWnd);
switch (LOWORD(wParam)) {
case ID_REGISTRY_IMPORTREGISTRYFILE:
......@@ -462,6 +461,10 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
case ID_REGISTRY_PRINT:
PrintRegistryHive(hWnd, _T(""));
break;
case ID_EDIT_DELETE:
if (DeleteValue(hWnd, hKey, valueName))
RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath);
break;
case ID_EDIT_MODIFY:
if (ModifyValue(hWnd, hKey, valueName))
RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath);
......
......@@ -93,7 +93,8 @@ extern BOOL OnTreeExpanding(HWND hWnd, NMTREEVIEW* pnmtv);
extern LPCTSTR GetItemPath(HWND hwndTV, HTREEITEM hItem, HKEY* phRootKey);
/* edit.c */
BOOL CreateKey(HKEY hKey);
BOOL ModifyValue(HWND hwnd, HKEY hKey, LPCTSTR valueName);
extern BOOL CreateKey(HKEY hKey);
extern BOOL ModifyValue(HWND hwnd, HKEY hKey, LPCTSTR valueName);
extern BOOL DeleteValue(HWND hwnd, HKEY hKey, LPCTSTR valueName);
#endif /* __MAIN_H__ */
......@@ -106,7 +106,13 @@
#define IDS_BAD_VALUE 32837
#define IDS_UNSUPPORTED_TYPE 32838
#define IDS_TOO_BIG_VALUE 32839
#define IDS_NEWKEY 32840
#define IDS_DELETE_BOX_TITLE 32840
#define IDS_DELETE_BOX_TEXT 32841
#define IDD_EDIT_DWORD 32850
#define IDC_DWORD_BASE 32852
#define IDC_DWORD_HEX 32853
#define IDC_DWORD_DEC 32854
#define IDS_NEWKEY 32860
#define IDD_EDIT_STRING 2000
#define IDC_VALUE_NAME 2001
......
......@@ -99,7 +99,6 @@ LPCTSTR GetItemPath(HWND hwndTV, HTREEITEM hItem, HKEY* phRootKey)
if (!hItem) hItem = TreeView_GetSelection(hwndTV);
if (!hItem) return NULL;
if (!get_item_path(hwndTV, hItem, phRootKey, &pathBuffer, &pathLen, &maxLen)) return NULL;
printf("hRoot=%p, keyPath='%s'\n", *phRootKey, pathBuffer);
return pathBuffer;
}
......@@ -235,7 +234,6 @@ BOOL OnTreeExpanding(HWND hwndTV, NMTREEVIEW* pnmtv)
RegCloseKey(hKey);
}
if (errCode != ERROR_SUCCESS) dwSubCount = 0;
printf("dwSubCount=%ld, Name=%s\n", dwSubCount, Name);
AddEntryToTree(hwndTV, pnmtv->itemNew.hItem, Name, NULL, dwSubCount);
}
RegCloseKey(hNewKey);
......
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