Add value rename support to regedit.
This commit is contained in:
parent
f4e7227541
commit
d160d46c7d
|
@ -125,6 +125,36 @@ INT_PTR CALLBACK modify_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
static LPTSTR read_value(HWND hwnd, HKEY hKey, LPCTSTR valueName, DWORD *lpType, LONG *len)
|
||||
{
|
||||
DWORD valueDataLen;
|
||||
LPTSTR buffer = NULL;
|
||||
LONG lRet;
|
||||
|
||||
lRet = RegQueryValueEx(hKey, valueName, 0, lpType, 0, &valueDataLen);
|
||||
if (lRet != ERROR_SUCCESS) {
|
||||
error(hwnd, IDS_BAD_VALUE, valueName);
|
||||
goto done;
|
||||
}
|
||||
if ( *lpType == REG_DWORD ) valueDataLen = sizeof(DWORD);
|
||||
if (!(buffer = HeapAlloc(GetProcessHeap(), 0, valueDataLen))) {
|
||||
error(hwnd, IDS_TOO_BIG_VALUE, valueDataLen);
|
||||
goto done;
|
||||
}
|
||||
lRet = RegQueryValueEx(hKey, valueName, 0, 0, buffer, &valueDataLen);
|
||||
if (lRet != ERROR_SUCCESS) {
|
||||
error(hwnd, IDS_BAD_VALUE, valueName);
|
||||
goto done;
|
||||
}
|
||||
|
||||
if(len) *len = valueDataLen;
|
||||
return buffer;
|
||||
|
||||
done:
|
||||
HeapFree(GetProcessHeap(), 0, buffer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BOOL CreateKey(HKEY hKey)
|
||||
{
|
||||
LONG lRet = ERROR_SUCCESS;
|
||||
|
@ -156,7 +186,6 @@ BOOL CreateKey(HKEY hKey)
|
|||
|
||||
BOOL ModifyValue(HWND hwnd, HKEY hKey, LPCTSTR valueName)
|
||||
{
|
||||
DWORD valueDataLen;
|
||||
DWORD type;
|
||||
LONG lRet;
|
||||
BOOL result = FALSE;
|
||||
|
@ -164,22 +193,7 @@ BOOL ModifyValue(HWND hwnd, HKEY hKey, LPCTSTR valueName)
|
|||
if (!hKey || !valueName) return FALSE;
|
||||
|
||||
editValueName = valueName;
|
||||
|
||||
lRet = RegQueryValueEx(hKey, valueName, 0, &type, 0, &valueDataLen);
|
||||
if (lRet != ERROR_SUCCESS) {
|
||||
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(!(stringValueData = read_value(hwnd, hKey, valueName, &type, 0))) goto done;
|
||||
|
||||
if ( (type == REG_SZ) || (type == REG_EXPAND_SZ) ) {
|
||||
if (DialogBox(0, MAKEINTRESOURCE(IDD_EDIT_STRING), hwnd, modify_dlgproc) == IDOK) {
|
||||
|
@ -248,3 +262,29 @@ BOOL CreateValue(HWND hwnd, HKEY hKey, DWORD valueType)
|
|||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL RenameValue(HWND hwnd, HKEY hRootKey, LPCTSTR keyPath, LPCTSTR oldName, LPCTSTR newName)
|
||||
{
|
||||
LPTSTR value = NULL;
|
||||
DWORD type;
|
||||
LONG len, lRet;
|
||||
BOOL result = FALSE;
|
||||
HKEY hKey;
|
||||
|
||||
lRet = RegOpenKeyEx(hRootKey, keyPath, 0, KEY_ALL_ACCESS, &hKey);
|
||||
if (lRet != ERROR_SUCCESS) goto done;
|
||||
value = read_value(hwnd, hKey, oldName, &type, &len);
|
||||
if(!value) goto done;
|
||||
lRet = RegSetValueEx(hKey, newName, 0, type, (BYTE*)value, len);
|
||||
if (lRet != ERROR_SUCCESS) goto done;
|
||||
lRet = RegDeleteValue(hKey, oldName);
|
||||
if (lRet != ERROR_SUCCESS) {
|
||||
RegDeleteValue(hKey, newName);
|
||||
goto done;
|
||||
}
|
||||
result = TRUE;
|
||||
|
||||
done:
|
||||
HeapFree(GetProcessHeap(), 0, value);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -488,6 +488,9 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||
create_value:
|
||||
if (CreateValue(hWnd, hKey, valueType))
|
||||
RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath);
|
||||
case ID_EDIT_RENAME:
|
||||
StartValueRename(g_pChildWnd->hListWnd, hKeyRoot, keyPath);
|
||||
break;
|
||||
break;
|
||||
case ID_REGISTRY_PRINTERSETUP:
|
||||
/*PRINTDLG pd;*/
|
||||
|
|
|
@ -44,6 +44,9 @@ static WNDPROC g_orgListWndProc;
|
|||
static DWORD g_columnToSort = ~0UL;
|
||||
static BOOL g_invertSort = FALSE;
|
||||
static LPTSTR g_valueName;
|
||||
static LPCTSTR g_currentValue;
|
||||
static LPTSTR g_currentPath;
|
||||
static HKEY g_currentRootKey;
|
||||
|
||||
#define MAX_LIST_COLUMNS (IDS_LIST_COLUMN_LAST - IDS_LIST_COLUMN_FIRST + 1)
|
||||
static int default_column_widths[MAX_LIST_COLUMNS] = { 200, 175, 400 };
|
||||
|
@ -238,7 +241,24 @@ static int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSor
|
|||
}
|
||||
|
||||
static void ListViewPopUpMenu(HWND hWnd, POINT pt)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
BOOL StartValueRename(HWND hwndLV, HKEY hRootKey, LPCTSTR path)
|
||||
{
|
||||
int item;
|
||||
|
||||
item = ListView_GetNextItem(hwndLV, -1, LVNI_FOCUSED);
|
||||
if (item == -1) return FALSE;
|
||||
if (!(g_currentValue = GetValueName(hwndLV))) return FALSE;
|
||||
g_currentRootKey = hRootKey;
|
||||
HeapFree(GetProcessHeap(), 0, g_currentPath);
|
||||
g_currentPath = HeapAlloc(GetProcessHeap(), 0, (lstrlen(path) + 1) * sizeof(TCHAR));
|
||||
if (!g_currentPath) return FALSE;
|
||||
lstrcpy(g_currentPath, path);
|
||||
if (!ListView_EditLabel(hwndLV, item)) return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
|
@ -274,6 +294,8 @@ static LRESULT CALLBACK ListWndProc(HWND hWnd, UINT message, WPARAM wParam, LPAR
|
|||
|
||||
ListView_SortItems(hWnd, CompareFunc, hWnd);
|
||||
break;
|
||||
case LVN_ENDLABELEDIT:
|
||||
return RenameValue(hWnd, g_currentRootKey, g_currentPath, g_currentValue, ((LPNMLVDISPINFO)lParam)->item.pszText);
|
||||
case NM_DBLCLK: {
|
||||
NMITEMACTIVATE* nmitem = (LPNMITEMACTIVATE)lParam;
|
||||
LVHITTESTINFO info;
|
||||
|
@ -346,7 +368,7 @@ HWND CreateListView(HWND hwndParent, int id)
|
|||
/* Get the dimensions of the parent window's client area, and create the list view control. */
|
||||
GetClientRect(hwndParent, &rcClient);
|
||||
hwndLV = CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEW, _T("List View"),
|
||||
WS_VISIBLE | WS_CHILD | LVS_REPORT,
|
||||
WS_VISIBLE | WS_CHILD | LVS_REPORT | LVS_EDITLABELS,
|
||||
0, 0, rcClient.right, rcClient.bottom,
|
||||
hwndParent, (HMENU)id, hInst, NULL);
|
||||
if (!hwndLV) return NULL;
|
||||
|
|
|
@ -85,6 +85,7 @@ extern void UpdateStatusBar(void);
|
|||
/* listview.c */
|
||||
extern HWND CreateListView(HWND hwndParent, int id);
|
||||
extern BOOL RefreshListView(HWND hwndLV, HKEY hKey, LPCTSTR keyPath);
|
||||
extern BOOL StartValueRename(HWND hwndLV, HKEY hKey, LPCTSTR keyPath);
|
||||
extern LPCTSTR GetValueName(HWND hwndLV);
|
||||
|
||||
/* treeview.c */
|
||||
|
@ -97,5 +98,6 @@ extern BOOL CreateKey(HKEY hKey);
|
|||
extern BOOL CreateValue(HWND hwnd, HKEY hKey, DWORD valueType);
|
||||
extern BOOL ModifyValue(HWND hwnd, HKEY hKey, LPCTSTR valueName);
|
||||
extern BOOL DeleteValue(HWND hwnd, HKEY hKey, LPCTSTR valueName);
|
||||
extern BOOL RenameValue(HWND hwnd, HKEY hRootKey, LPCTSTR keyPath, LPCTSTR oldName, LPCTSTR newName);
|
||||
|
||||
#endif /* __MAIN_H__ */
|
||||
|
|
Loading…
Reference in New Issue