added support for deleting values

svn path=/trunk/; revision=9793
This commit is contained in:
Thomas Bluemel 2004-06-21 08:47:38 +00:00
parent aed08f7da3
commit 208898d3cd
6 changed files with 101 additions and 31 deletions

View file

@ -258,6 +258,11 @@ BEGIN
IDS_UNSUPPORTED_TYPE "Can't edit keys of this type (%ld)" IDS_UNSUPPORTED_TYPE "Can't edit keys of this type (%ld)"
IDS_TOO_BIG_VALUE "Value is too big (%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." IDS_MULTI_SZ_EMPTY_STRING "Data of type REG_MULTI_SZ cannot contain empty strings.\nThe empty strings have been removed from the list."
IDS_QUERY_DELETE_ONE "Are you sure you want to delete this value?"
IDS_QUERY_DELETE_MORE "Are you sure you want to delete these values?"
IDS_QUERY_DELETE_CONFIRM "Confirm Value Delete"
IDS_ERR_DELVAL_CAPTION "Error Deleting Values"
IDS_ERR_DELETEVALUE "Unable to delete all specified values!"
END END
STRINGTABLE DISCARDABLE STRINGTABLE DISCARDABLE
@ -269,6 +274,7 @@ BEGIN
IDS_MY_COMPUTER "My Computer" IDS_MY_COMPUTER "My Computer"
IDS_IMPORT_REG_FILE "Import Registry File" IDS_IMPORT_REG_FILE "Import Registry File"
IDS_EXPORT_REG_FILE "Export Registry File" IDS_EXPORT_REG_FILE "Export Registry File"
IDS_INVALID_DWORD "(invalid DWORD value)"
END END
STRINGTABLE DISCARDABLE STRINGTABLE DISCARDABLE

View file

@ -448,7 +448,7 @@ INT_PTR CALLBACK modify_binary_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, L
} }
BOOL ModifyValue(HWND hwnd, HKEY hKey, LPCTSTR valueName) BOOL ModifyValue(HWND hwnd, HKEY hKey, LPCTSTR valueName, BOOL EditBin)
{ {
DWORD type; DWORD type;
LONG lRet; LONG lRet;
@ -475,7 +475,7 @@ BOOL ModifyValue(HWND hwnd, HKEY hKey, LPCTSTR valueName)
goto done; goto done;
} }
if ((type == REG_SZ) || (type == REG_EXPAND_SZ)) if (EditBin == FALSE && ((type == REG_SZ) || (type == REG_EXPAND_SZ)))
{ {
if (valueDataLen > 0) if (valueDataLen > 0)
{ {
@ -510,7 +510,7 @@ BOOL ModifyValue(HWND hwnd, HKEY hKey, LPCTSTR valueName)
result = TRUE; result = TRUE;
} }
} }
else if (type == REG_MULTI_SZ) else if (EditBin == FALSE && type == REG_MULTI_SZ)
{ {
if (valueDataLen > 0) if (valueDataLen > 0)
{ {
@ -615,7 +615,7 @@ BOOL ModifyValue(HWND hwnd, HKEY hKey, LPCTSTR valueName)
result = TRUE; result = TRUE;
} }
} }
else if (type == REG_DWORD) else if (EditBin == FALSE && type == REG_DWORD)
{ {
lRet = RegQueryValueEx(hKey, valueName, 0, 0, (LPBYTE)&dwordValueData, &valueDataLen); lRet = RegQueryValueEx(hKey, valueName, 0, 0, (LPBYTE)&dwordValueData, &valueDataLen);
if (lRet != ERROR_SUCCESS) if (lRet != ERROR_SUCCESS)
@ -631,20 +631,27 @@ BOOL ModifyValue(HWND hwnd, HKEY hKey, LPCTSTR valueName)
result = TRUE; result = TRUE;
} }
} }
else if (type == REG_NONE || type == REG_BINARY) else if (EditBin == TRUE || type == REG_NONE || type == REG_BINARY)
{ {
if(!(binValueData = HeapAlloc(GetProcessHeap(), 0, valueDataLen))) if(valueDataLen > 0)
{ {
error(hwnd, IDS_TOO_BIG_VALUE, valueDataLen); if(!(binValueData = HeapAlloc(GetProcessHeap(), 0, valueDataLen)))
goto done; {
error(hwnd, IDS_TOO_BIG_VALUE, valueDataLen);
goto done;
}
lRet = RegQueryValueEx(hKey, valueName, 0, 0, (LPBYTE)binValueData, &valueDataLen);
if (lRet != ERROR_SUCCESS)
{
HeapFree(GetProcessHeap(), 0, binValueData);
error(hwnd, IDS_BAD_VALUE, valueName);
goto done;
}
} }
else
lRet = RegQueryValueEx(hKey, valueName, 0, 0, (LPBYTE)binValueData, &valueDataLen);
if (lRet != ERROR_SUCCESS)
{ {
HeapFree(GetProcessHeap(), 0, binValueData); binValueData = NULL;
error(hwnd, IDS_BAD_VALUE, valueName);
goto done;
} }
if (DialogBox(0, MAKEINTRESOURCE(IDD_EDIT_BIN_DATA), hwnd, modify_binary_dlgproc) == IDOK) if (DialogBox(0, MAKEINTRESOURCE(IDD_EDIT_BIN_DATA), hwnd, modify_binary_dlgproc) == IDOK)

View file

@ -527,12 +527,14 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
} }
case ID_EDIT_RENAME: case ID_EDIT_RENAME:
case ID_EDIT_MODIFY: case ID_EDIT_MODIFY:
case ID_EDIT_MODIFY_BIN:
case ID_EDIT_DELETE:
regsam |= KEY_WRITE; regsam |= KEY_WRITE;
break; break;
} }
keyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hKeyRoot); keyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hKeyRoot);
valueName = GetValueName(g_pChildWnd->hListWnd); valueName = GetValueName(g_pChildWnd->hListWnd, -1);
if (keyPath) { if (keyPath) {
lRet = RegOpenKeyEx(hKeyRoot, keyPath, 0, regsam, &hKey); lRet = RegOpenKeyEx(hKeyRoot, keyPath, 0, regsam, &hKey);
if (lRet != ERROR_SUCCESS) hKey = 0; if (lRet != ERROR_SUCCESS) hKey = 0;
@ -540,19 +542,58 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
switch (LOWORD(wParam)) { switch (LOWORD(wParam)) {
case ID_EDIT_MODIFY: case ID_EDIT_MODIFY:
if (valueName && ModifyValue(hWnd, hKey, valueName)) if (valueName && ModifyValue(hWnd, hKey, valueName, FALSE))
RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath);
break;
case ID_EDIT_MODIFY_BIN:
if (valueName && ModifyValue(hWnd, hKey, valueName, TRUE))
RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath); RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath);
break; break;
case ID_EDIT_RENAME: case ID_EDIT_RENAME:
if(ListView_GetSelectedCount(g_pChildWnd->hListWnd) == 1) if(ListView_GetSelectedCount(g_pChildWnd->hListWnd) == 1)
{ {
item = ListView_GetNextItem(g_pChildWnd->hListWnd, -1, LVNI_FOCUSED | LVNI_SELECTED); item = ListView_GetNextItem(g_pChildWnd->hListWnd, -1, LVNI_SELECTED);
if(item > -1) if(item > -1)
{ {
ListView_EditLabel(g_pChildWnd->hListWnd, item); ListView_EditLabel(g_pChildWnd->hListWnd, item);
} }
} }
break; break;
case ID_EDIT_DELETE:
{
UINT nSelected = ListView_GetSelectedCount(g_pChildWnd->hListWnd);
if(nSelected >= 1)
{
TCHAR msg[128], caption[128];
LoadString(hInst, IDS_QUERY_DELETE_CONFIRM, caption, sizeof(caption)/sizeof(TCHAR));
LoadString(hInst, (nSelected == 1 ? IDS_QUERY_DELETE_ONE : IDS_QUERY_DELETE_MORE), msg, sizeof(msg)/sizeof(TCHAR));
if(MessageBox(g_pChildWnd->hWnd, msg, caption, MB_ICONQUESTION | MB_YESNO) == IDYES)
{
int ni, errs;
item = -1;
errs = 0;
while((ni = ListView_GetNextItem(g_pChildWnd->hListWnd, item, LVNI_SELECTED)) > -1)
{
valueName = GetValueName(g_pChildWnd->hListWnd, item);
if(RegDeleteValue(hKey, valueName) != ERROR_SUCCESS)
{
errs++;
}
item = ni;
}
RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath);
if(errs > 0)
{
LoadString(hInst, IDS_ERR_DELVAL_CAPTION, caption, sizeof(caption)/sizeof(TCHAR));
LoadString(hInst, IDS_ERR_DELETEVALUE, msg, sizeof(msg)/sizeof(TCHAR));
MessageBox(g_pChildWnd->hWnd, msg, caption, MB_ICONSTOP);
}
}
}
break;
}
case ID_EDIT_COPYKEYNAME: case ID_EDIT_COPYKEYNAME:
CopyKeyName(hWnd, _T("")); CopyKeyName(hWnd, _T(""));
break; break;

View file

@ -55,7 +55,7 @@ static LPTSTR g_valueName;
static int default_column_widths[MAX_LIST_COLUMNS] = { 200, 175, 400 }; static int default_column_widths[MAX_LIST_COLUMNS] = { 200, 175, 400 };
static int column_alignment[MAX_LIST_COLUMNS] = { LVCFMT_LEFT, LVCFMT_LEFT, LVCFMT_LEFT }; static int column_alignment[MAX_LIST_COLUMNS] = { LVCFMT_LEFT, LVCFMT_LEFT, LVCFMT_LEFT };
LPCTSTR GetValueName(HWND hwndLV) LPCTSTR GetValueName(HWND hwndLV, int iStartAt)
{ {
int item, len, maxLen; int item, len, maxLen;
LPTSTR newStr; LPTSTR newStr;
@ -68,7 +68,7 @@ LPCTSTR GetValueName(HWND hwndLV)
maxLen = HeapSize(GetProcessHeap(), 0, g_valueName); maxLen = HeapSize(GetProcessHeap(), 0, g_valueName);
if (maxLen == (SIZE_T) - 1) return NULL; if (maxLen == (SIZE_T) - 1) return NULL;
item = ListView_GetNextItem(hwndLV, -1, LVNI_FOCUSED | LVNI_SELECTED); item = ListView_GetNextItem(hwndLV, iStartAt, LVNI_SELECTED);
if (item == -1) return NULL; if (item == -1) return NULL;
LVItem.mask = LVIF_PARAM; LVItem.mask = LVIF_PARAM;
LVItem.iItem = item; LVItem.iItem = item;
@ -114,7 +114,7 @@ BOOL IsDefaultValue(HWND hwndLV, int i)
/******************************************************************************* /*******************************************************************************
* Local module support methods * Local module support methods
*/ */
static void AddEntryToList(HWND hwndLV, LPTSTR Name, DWORD dwValType, void* ValBuf, DWORD dwCount, int Position) static void AddEntryToList(HWND hwndLV, LPTSTR Name, DWORD dwValType, void* ValBuf, DWORD dwCount, int Position, BOOL ValExists)
{ {
LINE_INFO* linfo; LINE_INFO* linfo;
LVITEM item; LVITEM item;
@ -162,10 +162,17 @@ static void AddEntryToList(HWND hwndLV, LPTSTR Name, DWORD dwValType, void* ValB
switch (dwValType) { switch (dwValType) {
case REG_SZ: case REG_SZ:
case REG_EXPAND_SZ: case REG_EXPAND_SZ:
if(dwCount) if(dwCount > 0)
{ {
ListView_SetItemText(hwndLV, index, 2, ValBuf); ListView_SetItemText(hwndLV, index, 2, ValBuf);
} }
else if(!ValExists)
{
TCHAR buffer[255];
/* load (value not set) string */
LoadString(hInst, IDS_VALUE_NOT_SET, buffer, sizeof(buffer)/sizeof(TCHAR));
ListView_SetItemText(hwndLV, index, 2, buffer);
}
break; break;
case REG_MULTI_SZ: case REG_MULTI_SZ:
{ {
@ -195,8 +202,15 @@ static void AddEntryToList(HWND hwndLV, LPTSTR Name, DWORD dwValType, void* ValB
} }
break; break;
case REG_DWORD: { case REG_DWORD: {
TCHAR buf[64]; TCHAR buf[200];
wsprintf(buf, _T("0x%08X (%d)"), *(DWORD*)ValBuf, *(DWORD*)ValBuf); if(dwCount == sizeof(DWORD))
{
wsprintf(buf, _T("0x%08X (%d)"), *(DWORD*)ValBuf, *(DWORD*)ValBuf);
}
else
{
LoadString(hInst, IDS_INVALID_DWORD, buf, sizeof(buf)/sizeof(TCHAR));
}
ListView_SetItemText(hwndLV, index, 2, buf); ListView_SetItemText(hwndLV, index, 2, buf);
} }
/* lpsRes = convertHexToDWORDStr(lpbData, dwLen); */ /* lpsRes = convertHexToDWORDStr(lpbData, dwLen); */
@ -337,10 +351,6 @@ static void OnGetDispInfo(NMLVDISPINFO* plvdi)
} }
} }
break; break;
case 2:
LoadString(hInst, IDS_VALUE_NOT_SET, buffer, sizeof(buffer)/sizeof(TCHAR));
plvdi->item.pszText = buffer;
break;
case 3: case 3:
plvdi->item.pszText = _T(""); plvdi->item.pszText = _T("");
break; break;
@ -499,7 +509,7 @@ BOOL RefreshListView(HWND hwndLV, HKEY hKey, LPCTSTR keyPath)
/* dwValSize = max_val_size; */ /* dwValSize = max_val_size; */
while (RegEnumValue(hNewKey, dwIndex, ValName, &dwValNameLen, NULL, &dwValType, ValBuf, &dwValSize) == ERROR_SUCCESS) { while (RegEnumValue(hNewKey, dwIndex, ValName, &dwValNameLen, NULL, &dwValType, ValBuf, &dwValSize) == ERROR_SUCCESS) {
ValBuf[dwValSize] = 0; ValBuf[dwValSize] = 0;
AddEntryToList(hwndLV, ValName, dwValType, ValBuf, dwValSize, -1); AddEntryToList(hwndLV, ValName, dwValType, ValBuf, dwValSize, -1, TRUE);
dwValNameLen = max_val_name_len; dwValNameLen = max_val_name_len;
dwValSize = max_val_size; dwValSize = max_val_size;
dwValType = 0L; dwValType = 0L;
@ -514,7 +524,7 @@ BOOL RefreshListView(HWND hwndLV, HKEY hKey, LPCTSTR keyPath)
} }
if(!AddedDefault) if(!AddedDefault)
{ {
AddEntryToList(hwndLV, _T(""), REG_SZ, NULL, 0, 0); AddEntryToList(hwndLV, _T(""), REG_SZ, NULL, 0, 0, FALSE);
} }
ListView_SortItems(hwndLV, CompareFunc, (WPARAM)hwndLV); ListView_SortItems(hwndLV, CompareFunc, (WPARAM)hwndLV);
RegCloseKey(hNewKey); RegCloseKey(hNewKey);

View file

@ -90,7 +90,7 @@ extern void UpdateStatusBar(void);
/* listview.c */ /* listview.c */
extern HWND CreateListView(HWND hwndParent, int id); extern HWND CreateListView(HWND hwndParent, int id);
extern BOOL RefreshListView(HWND hwndLV, HKEY hKey, LPCTSTR keyPath); extern BOOL RefreshListView(HWND hwndLV, HKEY hKey, LPCTSTR keyPath);
extern LPCTSTR GetValueName(HWND hwndLV); extern LPCTSTR GetValueName(HWND hwndLV, int iStartAt);
extern BOOL ListWndNotifyProc(HWND hWnd, WPARAM wParam, LPARAM lParam, BOOL *Result); extern BOOL ListWndNotifyProc(HWND hWnd, WPARAM wParam, LPARAM lParam, BOOL *Result);
extern BOOL IsDefaultValue(HWND hwndLV, int i); extern BOOL IsDefaultValue(HWND hwndLV, int i);
@ -100,6 +100,6 @@ extern BOOL OnTreeExpanding(HWND hWnd, NMTREEVIEW* pnmtv);
extern LPCTSTR GetItemPath(HWND hwndTV, HTREEITEM hItem, HKEY* phRootKey); extern LPCTSTR GetItemPath(HWND hwndTV, HTREEITEM hItem, HKEY* phRootKey);
/* edit.c */ /* edit.c */
extern BOOL ModifyValue(HWND hwnd, HKEY hKey, LPCTSTR valueName); extern BOOL ModifyValue(HWND hwnd, HKEY hKey, LPCTSTR valueName, BOOL EditBin);
#endif /* __MAIN_H__ */ #endif /* __MAIN_H__ */

View file

@ -118,6 +118,12 @@
#define IDS_MY_COMPUTER 32847 #define IDS_MY_COMPUTER 32847
#define IDS_IMPORT_REG_FILE 32848 #define IDS_IMPORT_REG_FILE 32848
#define IDS_EXPORT_REG_FILE 32849 #define IDS_EXPORT_REG_FILE 32849
#define IDS_INVALID_DWORD 32850
#define IDS_QUERY_DELETE_ONE 32851
#define IDS_QUERY_DELETE_MORE 32852
#define IDS_QUERY_DELETE_CONFIRM 32853
#define IDS_ERR_DELVAL_CAPTION 32854
#define IDS_ERR_DELETEVALUE 32855
#define IDS_FLT_REGFILES 31001 #define IDS_FLT_REGFILES 31001
#define IDS_FLT_REGFILES_FLT 31002 #define IDS_FLT_REGFILES_FLT 31002