dwIndex = 0;
do
{
- cbValueName = sizeof(szValueName) / sizeof(szValueName[0]);
+ cbValueName = COUNT_OF(szValueName);
cbValueData = sizeof(abValueData);
lResult = RegEnumValue(hKey, dwIndex, szValueName, &cbValueName, NULL, &dwType, abValueData, &cbValueData);
if ((lResult == ERROR_SUCCESS) && (dwType == REG_SZ))
return TRUE;
}
-#define MAX_CUSTOM_FILTER_SIZE 50
-TCHAR CustomFilterBuffer[MAX_CUSTOM_FILTER_SIZE];
TCHAR FileNameBuffer[_MAX_PATH];
TCHAR FileTitleBuffer[_MAX_PATH];
BuildFilterStrings(Filter, FilterPairs, sizeof(FilterPairs) / sizeof(FILTERPAIR));
pofn->lpstrFilter = Filter;
- pofn->lpstrCustomFilter = CustomFilterBuffer;
- pofn->nMaxCustFilter = MAX_CUSTOM_FILTER_SIZE;
- pofn->nFilterIndex = 0;
pofn->lpstrFile = FileNameBuffer;
pofn->nMaxFile = _MAX_PATH;
pofn->lpstrFileTitle = FileTitleBuffer;
pofn->nMaxFileTitle = _MAX_PATH;
- /* pofn->lpstrInitialDir = _T("");*/
- /* pofn->lpstrTitle = _T("Import Registry File");*/
- /* pofn->Flags = OFN_ENABLETEMPLATE + OFN_EXPLORER + OFN_ENABLESIZING;*/
pofn->Flags = OFN_HIDEREADONLY;
- /* pofn->nFileOffset = ;*/
- /* pofn->nFileExtension = ;*/
- /* pofn->lpstrDefExt = _T("");*/
- /* pofn->lCustData = ;*/
- /* pofn->lpfnHook = ImportRegistryFile_OFNHookProc;*/
- /* pofn->lpTemplateName = _T("ID_DLG_IMPORT_REGFILE");*/
- /* pofn->lpTemplateName = MAKEINTRESOURCE(IDD_DIALOG1);*/
- /* pofn->FlagsEx = ;*/
+ pofn->lpstrDefExt = TEXT("reg");
+ return TRUE;
+}
+
+static INT_PTR CALLBACK LoadHive_KeyNameInHookProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ static LPTSTR sKey = NULL;
+ static INT sLength = 0;
+ switch(uMsg)
+ {
+ case WM_INITDIALOG:
+ sKey = (LPTSTR)lParam;
+ sLength = 128; /* FIXME: Ugly hack! */
+ case WM_COMMAND:
+ switch(LOWORD(wParam))
+ {
+ case IDOK:
+ if(GetDlgItemText(hWndDlg, IDC_EDIT_KEY, sKey, sLength))
+ return EndDialog(hWndDlg, -1);
+ else
+ return EndDialog(hWndDlg, 0);
+ case IDCANCEL:
+ return EndDialog(hWndDlg, 0);
+ }
+ break;
+ }
+ return FALSE;
+}
+
+static BOOL LoadHive(HWND hWnd)
+{
+ OPENFILENAME ofn;
+ TCHAR Caption[128];
+ LPCTSTR pszKeyPath;
+ TCHAR xPath[128];
+ HKEY hRootKey;
+ TCHAR Filter[1024];
+ FILTERPAIR filter;
+ /* get the item key to load the hive in */
+ pszKeyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hRootKey);
+ /* initialize the "open file" dialog */
+ InitOpenFileName(hWnd, &ofn);
+ /* build the "All Files" filter up */
+ filter.DisplayID = IDS_FLT_ALLFILES;
+ filter.FilterID = IDS_FLT_ALLFILES_FLT;
+ BuildFilterStrings(Filter, &filter, sizeof(filter));
+ ofn.lpstrFilter = Filter;
+ /* load and set the caption and flags for dialog */
+ LoadString(hInst, IDS_LOAD_HIVE, Caption, COUNT_OF(Caption));
+ ofn.lpstrTitle = Caption;
+ ofn.Flags |= OFN_ENABLESIZING;
+ /* ofn.lCustData = ;*/
+ /* now load the hive */
+ if (GetOpenFileName(&ofn))
+ {
+ if(DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_LOADHIVE), hWnd, &LoadHive_KeyNameInHookProc, (LPARAM)xPath))
+ {
+ LONG regLoadResult = RegLoadKey(hRootKey, xPath, ofn.lpstrFile);
+ if(regLoadResult == ERROR_SUCCESS)
+ {
+ /* refresh tree and list views */
+ RefreshTreeView(g_pChildWnd->hTreeWnd);
+ pszKeyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hRootKey);
+ RefreshListView(g_pChildWnd->hListWnd, hRootKey, pszKeyPath);
+ }
+ else
+ {
+ ErrorMessageBox(hWnd, Caption, regLoadResult);
+ return FALSE;
+ }
+ }
+ } else {
+ CheckCommDlgError(hWnd);
+ }
+ return TRUE;
+}
+
+static BOOL UnloadHive(HWND hWnd)
+{
+ TCHAR Caption[128];
+ LPCTSTR pszKeyPath;
+ HKEY hRootKey;
+ LONG regUnloadResult;
+
+ /* get the item key to unload */
+ pszKeyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hRootKey);
+ /* load and set the caption and flags for dialog */
+ LoadString(hInst, IDS_UNLOAD_HIVE, Caption, COUNT_OF(Caption));
+ /* now unload the hive */
+ regUnloadResult = RegUnLoadKey(hRootKey, pszKeyPath);
+ if(regUnloadResult == ERROR_SUCCESS)
+ {
+ /* refresh tree and list views */
+ RefreshTreeView(g_pChildWnd->hTreeWnd);
+ pszKeyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hRootKey);
+ RefreshListView(g_pChildWnd->hListWnd, hRootKey, pszKeyPath);
+ }
+ else
+ {
+ ErrorMessageBox(hWnd, Caption, regUnloadResult);
+ return FALSE;
+ }
return TRUE;
}
{
OPENFILENAME ofn;
TCHAR Caption[128];
+ LPCTSTR pszKeyPath;
+ HKEY hRootKey;
InitOpenFileName(hWnd, &ofn);
- LoadString(hInst, IDS_IMPORT_REG_FILE, Caption, sizeof(Caption)/sizeof(TCHAR));
+ LoadString(hInst, IDS_IMPORT_REG_FILE, Caption, COUNT_OF(Caption));
ofn.lpstrTitle = Caption;
+ ofn.Flags |= OFN_ENABLESIZING;
/* ofn.lCustData = ;*/
if (GetOpenFileName(&ofn)) {
- /* FIXME - convert to ascii */
- if (!import_registry_file(ofn.lpstrFile)) {
- /*printf("Can't open file \"%s\"\n", ofn.lpstrFile);*/
- return FALSE;
- }
-#if 0
- get_file_name(&s, filename, MAX_PATH);
- if (!filename[0]) {
- printf("No file name is specified\n%s", usage);
+ FILE *fp = _wfopen(ofn.lpstrFile, L"r");
+ if (fp == NULL || !import_registry_file(fp)) {
+ LPSTR p = GetMultiByteString(ofn.lpstrFile);
+ fprintf(stderr, "Can't open file \"%s\"\n", p);
+ HeapFree(GetProcessHeap(), 0, p);
+ if (fp != NULL)
+ fclose(fp);
return FALSE;
- /*exit(1);*/
}
- while (filename[0]) {
- if (!import_registry_file(filename)) {
- perror("");
- printf("Can't open file \"%s\"\n", filename);
- return FALSE;
- /*exit(1);*/
- }
- get_file_name(&s, filename, MAX_PATH);
- }
-#endif
-
+ fclose(fp);
} else {
CheckCommDlgError(hWnd);
}
+
+ RefreshTreeView(g_pChildWnd->hTreeWnd);
+ pszKeyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hRootKey);
+ RefreshListView(g_pChildWnd->hListWnd, hRootKey, pszKeyPath);
+
return TRUE;
}
-
static UINT_PTR CALLBACK ExportRegistryFile_OFNHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
HWND hwndExportAll;
hwndExportAll = GetDlgItem(hdlg, IDC_EXPORT_ALL);
if (hwndExportAll)
- SendMessage(hwndExportAll, BM_SETCHECK, pszSelectedKey[0] ? BST_UNCHECKED : BST_CHECKED, 0);
+ SendMessage(hwndExportAll, BM_SETCHECK, pszSelectedKey ? BST_UNCHECKED : BST_CHECKED, 0);
hwndExportBranch = GetDlgItem(hdlg, IDC_EXPORT_BRANCH);
if (hwndExportBranch)
- SendMessage(hwndExportBranch, BM_SETCHECK, pszSelectedKey[0] ? BST_CHECKED : BST_UNCHECKED, 0);
+ SendMessage(hwndExportBranch, BM_SETCHECK, pszSelectedKey ? BST_CHECKED : BST_UNCHECKED, 0);
hwndExportBranchText = GetDlgItem(hdlg, IDC_EXPORT_BRANCH_TEXT);
if (hwndExportBranchText)
/* Figure out which key path we are exporting */
pszKeyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hKeyRoot);
- RegKeyGetName(ExportKeyPath, sizeof(ExportKeyPath) / sizeof(ExportKeyPath[0]),
- hKeyRoot, pszKeyPath);
+ GetKeyName(ExportKeyPath, COUNT_OF(ExportKeyPath), hKeyRoot, pszKeyPath);
InitOpenFileName(hWnd, &ofn);
LoadString(hInst, IDS_EXPORT_REG_FILE, Caption, sizeof(Caption)/sizeof(TCHAR));
ofn.lpstrTitle = Caption;
- ofn.lCustData = (LPARAM) ExportKeyPath;
- ofn.Flags = OFN_ENABLETEMPLATE | OFN_EXPLORER | OFN_ENABLEHOOK;
+
+ /* Only set the path if a key (not the root node) is selected */
+ if (hKeyRoot != 0)
+ {
+ ofn.lCustData = (LPARAM) ExportKeyPath;
+ }
+ ofn.Flags = OFN_ENABLETEMPLATE | OFN_EXPLORER | OFN_ENABLEHOOK | OFN_OVERWRITEPROMPT;
ofn.lpfnHook = ExportRegistryFile_OFNHookProc;
ofn.lpTemplateName = MAKEINTRESOURCE(IDD_EXPORTRANGE);
if (GetSaveFileName(&ofn)) {
BOOL result;
- LPSTR pszExportKeyPath;
-#ifdef UNICODE
- CHAR buffer[_MAX_PATH];
+ DWORD format;
- WideCharToMultiByte(CP_ACP, 0, ExportKeyPath, -1, buffer, sizeof(buffer), NULL, NULL);
- pszExportKeyPath = buffer;
-#else
- pszExportKeyPath = ExportKeyPath;
-#endif
-
- result = export_registry_key(ofn.lpstrFile, pszExportKeyPath);
+ if (ofn.nFilterIndex == 1)
+ format = REG_FORMAT_5;
+ else
+ format = REG_FORMAT_4;
+ result = export_registry_key(ofn.lpstrFile, ExportKeyPath, format);
if (!result) {
- /*printf("Can't open file \"%s\"\n", ofn.lpstrFile);*/
+ LPSTR p = GetMultiByteString(ofn.lpstrFile);
+ fprintf(stderr, "Can't open file \"%s\"\n", p);
+ HeapFree(GetProcessHeap(), 0, p);
return FALSE;
}
-#if 0
- TCHAR filename[MAX_PATH];
- filename[0] = '\0';
- get_file_name(&s, filename, MAX_PATH);
- if (!filename[0]) {
- printf("No file name is specified\n%s", usage);
- return FALSE;
- /*exit(1);*/
- }
- if (s[0]) {
- TCHAR reg_key_name[KEY_MAX_LEN];
- get_file_name(&s, reg_key_name, KEY_MAX_LEN);
- export_registry_key((CHAR)filename, reg_key_name);
- } else {
- export_registry_key(filename, NULL);
- }
-#endif
-
} else {
CheckCommDlgError(hWnd);
}
if (!EmptyClipboard())
goto done;
- if (!RegKeyGetName(szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]), hRootKey, keyName))
+ if (!GetKeyName(szBuffer, COUNT_OF(szBuffer), hRootKey, keyName))
goto done;
- hGlobal = GlobalAlloc(GMEM_MOVEABLE, (_tcslen(szBuffer) + 1) * sizeof(TCHAR));
+ hGlobal = GlobalAlloc(GMEM_MOVEABLE, (lstrlen(szBuffer) + 1) * sizeof(TCHAR));
if (!hGlobal)
goto done;
HKEY hKey;
LVFINDINFO lvfi;
- if (RegOpenKey(hRootKey, pszKeyPath, &hKey) != ERROR_SUCCESS)
+ if (RegOpenKeyEx(hRootKey, pszKeyPath, 0, KEY_QUERY_VALUE | KEY_SET_VALUE,
+ &hKey) != ERROR_SUCCESS)
return FALSE;
- LoadString(hInst, IDS_NEW_VALUE, szNewValueFormat, sizeof(szNewValueFormat)
- / sizeof(szNewValueFormat[0]));
+ LoadString(hInst, IDS_NEW_VALUE, szNewValueFormat, COUNT_OF(szNewValueFormat));
do
{
- _sntprintf(szNewValue, sizeof(szNewValue) / sizeof(szNewValue[0]),
- szNewValueFormat, iIndex++);
-
+ wsprintf(szNewValue, szNewValueFormat, iIndex++);
cbData = sizeof(data);
lResult = RegQueryValueEx(hKey, szNewValue, NULL, &dwExistingType, data, &cbData);
- }
- while(lResult == ERROR_SUCCESS);
+ } while(lResult == ERROR_SUCCESS);
switch(dwType) {
case REG_DWORD:
}
memset(data, 0, cbData);
lResult = RegSetValueEx(hKey, szNewValue, 0, dwType, data, cbData);
+ RegCloseKey(hKey);
if (lResult != ERROR_SUCCESS)
+ {
return FALSE;
+ }
RefreshListView(g_pChildWnd->hListWnd, hRootKey, pszKeyPath);
UNREFERENCED_PARAMETER(message);
switch (LOWORD(wParam)) {
+ case ID_REGISTRY_LOADHIVE:
+ LoadHive(hWnd);
+ return TRUE;
+ case ID_REGISTRY_UNLOADHIVE:
+ UnloadHive(hWnd);
+ return TRUE;
case ID_REGISTRY_IMPORTREGISTRYFILE:
ImportRegistryFile(hWnd);
return TRUE;
}
}
}
- if (GetFocus() == g_pChildWnd->hTreeWnd)
+ else if (GetFocus() == g_pChildWnd->hTreeWnd)
{
/* Get focused entry of treeview (if any) */
HTREEITEM hItem = TreeView_GetSelection(g_pChildWnd->hTreeWnd);
}
}
}
- } else
- if (GetFocus() == g_pChildWnd->hTreeWnd)
+ }
+ else if (GetFocus() == g_pChildWnd->hTreeWnd)
{
if (keyPath == 0 || *keyPath == 0)
{
RefreshTreeView(g_pChildWnd->hTreeWnd);
}
}
- break;
+ break;
+ }
case ID_EDIT_NEW_STRINGVALUE:
CreateNewValue(hKeyRoot, keyPath, REG_SZ);
break;
case ID_EDIT_NEW_DWORDVALUE:
CreateNewValue(hKeyRoot, keyPath, REG_DWORD);
break;
- case ID_EDIT_NEW_MULTISTRINGVALUE:
+ case ID_EDIT_NEW_MULTISTRINGVALUE:
CreateNewValue(hKeyRoot, keyPath, REG_MULTI_SZ);
break;
- case ID_EDIT_NEW_EXPANDABLESTRINGVALUE:
+ case ID_EDIT_NEW_EXPANDABLESTRINGVALUE:
CreateNewValue(hKeyRoot, keyPath, REG_EXPAND_SZ);
break;
-
- }
case ID_EDIT_FIND:
FindDialog(hWnd);
break;