Regedit: Implemented exporting specific branches

svn path=/trunk/; revision=18198
This commit is contained in:
Nathan Woods 2005-10-02 01:21:43 +00:00
parent 8ec93653e6
commit 46a48736ad
3 changed files with 81 additions and 21 deletions

View file

@ -294,31 +294,51 @@ static BOOL ImportRegistryFile(HWND hWnd)
static UINT_PTR CALLBACK ExportRegistryFile_OFNHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
HWND hControl;
HWND hwndExportAll;
HWND hwndExportBranch;
HWND hwndExportBranchText;
UINT_PTR iResult = 0;
OPENFILENAME *pOfn;
LPTSTR pszSelectedKey;
OFNOTIFY *pOfnNotify;
switch(uiMsg) {
case WM_INITDIALOG:
hControl = GetDlgItem(hdlg, IDC_EXPORT_ALL);
if (hControl)
{
EnableWindow(hControl, FALSE);
SendMessage(hControl, BM_SETCHECK, BST_CHECKED, 0);
}
pOfn = (OPENFILENAME *) lParam;
pszSelectedKey = (LPTSTR) pOfn->lCustData;
hControl = GetDlgItem(hdlg, IDC_EXPORT_BRANCH);
if (hControl)
{
EnableWindow(hControl, FALSE);
SendMessage(hControl, BM_SETCHECK, BST_UNCHECKED, 0);
}
hwndExportAll = GetDlgItem(hdlg, IDC_EXPORT_ALL);
if (hwndExportAll)
SendMessage(hwndExportAll, BM_SETCHECK, pszSelectedKey[0] ? BST_UNCHECKED : BST_CHECKED, 0);
hControl = GetDlgItem(hdlg, IDC_EXPORT_BRANCH_TEXT);
if (hControl)
{
EnableWindow(hControl, FALSE);
hwndExportBranch = GetDlgItem(hdlg, IDC_EXPORT_BRANCH);
if (hwndExportBranch)
SendMessage(hwndExportBranch, BM_SETCHECK, pszSelectedKey[0] ? BST_CHECKED : BST_UNCHECKED, 0);
hwndExportBranchText = GetDlgItem(hdlg, IDC_EXPORT_BRANCH_TEXT);
if (hwndExportBranchText)
SetWindowText(hwndExportBranchText, pszSelectedKey);
break;
case WM_NOTIFY:
if (((NMHDR *) lParam)->code == CDN_FILEOK)
{
pOfnNotify = (OFNOTIFY *) lParam;
pszSelectedKey = (LPTSTR) pOfnNotify->lpOFN->lCustData;
hwndExportBranch = GetDlgItem(hdlg, IDC_EXPORT_BRANCH);
hwndExportBranchText = GetDlgItem(hdlg, IDC_EXPORT_BRANCH_TEXT);
if (hwndExportBranch && hwndExportBranchText
&& (SendMessage(hwndExportBranch, BM_GETCHECK, 0, 0) == BST_CHECKED))
{
GetWindowText(hwndExportBranchText, pszSelectedKey, _MAX_PATH);
}
else
{
pszSelectedKey[0] = '\0';
}
}
break;
break;
}
return iResult;
}
@ -328,12 +348,18 @@ static BOOL ExportRegistryFile(HWND hWnd)
OPENFILENAME ofn;
TCHAR ExportKeyPath[_MAX_PATH];
TCHAR Caption[128];
HKEY hKeyRoot;
LPCTSTR pszKeyPath;
/* Figure out which key path we are exporting */
pszKeyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hKeyRoot);
RegKeyGetName(ExportKeyPath, sizeof(ExportKeyPath) / sizeof(ExportKeyPath[0]),
hKeyRoot, pszKeyPath);
ExportKeyPath[0] = _T('\0');
InitOpenFileName(hWnd, &ofn);
LoadString(hInst, IDS_EXPORT_REG_FILE, Caption, sizeof(Caption)/sizeof(TCHAR));
ofn.lpstrTitle = Caption;
/* ofn.lCustData = ;*/
ofn.lCustData = (LPARAM) ExportKeyPath;
ofn.Flags = OFN_ENABLETEMPLATE | OFN_EXPLORER | OFN_ENABLEHOOK;
ofn.lpfnHook = ExportRegistryFile_OFNHookProc;
ofn.lpTemplateName = MAKEINTRESOURCE(IDD_EXPORTRANGE);

View file

@ -1384,7 +1384,6 @@ BOOL export_registry_key(CHAR *file_name, CHAR *reg_key_name)
if (file) {
fclose(file);
}
HeapFree(GetProcessHeap(), 0, reg_key_name);
HeapFree(GetProcessHeap(), 0, val_buf);
return TRUE;
}
@ -1665,3 +1664,33 @@ done:
return lResult;
}
/******************************************************************************
* Key naming and parsing
*/
BOOL RegKeyGetName(LPTSTR pszDest, size_t iDestLength, HKEY hRootKey, LPCTSTR lpSubKey)
{
LPCTSTR pszRootKey;
if (hRootKey == HKEY_CLASSES_ROOT)
pszRootKey = TEXT("HKEY_CLASSES_ROOT");
else if (hRootKey == HKEY_CURRENT_USER)
pszRootKey = TEXT("HKEY_CURRENT_USER");
else if (hRootKey == HKEY_LOCAL_MACHINE)
pszRootKey = TEXT("HKEY_LOCAL_MACHINE");
else if (hRootKey == HKEY_USERS)
pszRootKey = TEXT("HKEY_USERS");
else if (hRootKey == HKEY_CURRENT_CONFIG)
pszRootKey = TEXT("HKEY_CURRENT_CONFIG");
else if (hRootKey == HKEY_DYN_DATA)
pszRootKey = TEXT("HKEY_DYN_DATA");
else
return FALSE;
if (lpSubKey[0])
_sntprintf(pszDest, iDestLength, TEXT("%s\\%s"), pszRootKey, lpSubKey);
else
_sntprintf(pszDest, iDestLength, TEXT("%s"), pszRootKey);
return TRUE;
}

View file

@ -91,4 +91,9 @@ LONG RegMoveKey(HKEY hDestKey, LPCTSTR lpDestSubKey, HKEY hSrcKey, LPCTSTR lpSrc
LONG RegRenameKey(HKEY hKey, LPCTSTR lpSubKey, LPCTSTR lpNewName);
LONG RegRenameValue(HKEY hKey, LPCTSTR lpSubKey, LPCTSTR lpDestValue, LPCTSTR lpSrcValue);
/*
* Miscellaneous
*/
BOOL RegKeyGetName(LPTSTR pszDest, size_t iDestLength, HKEY hRootKey, LPCTSTR lpSubKey);
/* EOF */