Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

822 lines
24 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 1993-1994
  4. *
  5. * TITLE: REGFILE.C
  6. *
  7. * VERSION: 4.0
  8. *
  9. * AUTHOR: Tracy Sharpe
  10. *
  11. * DATE: 21 Nov 1993
  12. *
  13. * File import and export user interface routines for the Registry Editor.
  14. *
  15. *******************************************************************************/
  16. #include "pch.h"
  17. #include "regedit.h"
  18. #include "regkey.h"
  19. #include "regfile.h"
  20. #include "regcdhk.h"
  21. #include "regresid.h"
  22. #include "reghelp.h"
  23. #include "regstred.h"
  24. #include "regprint.h"
  25. INT_PTR
  26. CALLBACK
  27. RegProgressDlgProc(
  28. HWND hWnd,
  29. UINT Message,
  30. WPARAM wParam,
  31. LPARAM lParam
  32. );
  33. /*******************************************************************************
  34. *
  35. * RegEdit_ImportRegFile
  36. *
  37. * DESCRIPTION:
  38. *
  39. * PARAMETERS:
  40. * hWnd, handle of RegEdit window.
  41. * fSilentMode, TRUE if no messages should be displayed, else FALSE.
  42. * lpFileName, address of file name buffer.
  43. *
  44. *******************************************************************************/
  45. VOID RegEdit_ImportRegFile(HWND hWnd, BOOL fSilentMode, LPTSTR lpFileName, HTREEITEM hComputerItem)
  46. {
  47. if (!fSilentMode && hWnd != NULL) {
  48. if ((g_hRegProgressWnd = CreateDialogParam(g_hInstance,
  49. MAKEINTRESOURCE(IDD_REGPROGRESS), hWnd, RegProgressDlgProc,
  50. (LPARAM) lpFileName)) != NULL)
  51. EnableWindow(hWnd, FALSE);
  52. }
  53. else
  54. g_hRegProgressWnd = NULL;
  55. //
  56. // Prompt user to confirm importing a .reg file if running in silent mode
  57. // without a window (i.e. invoked .reg from a folder)
  58. //
  59. if (!fSilentMode && !hWnd)
  60. {
  61. if (InternalMessageBox(g_hInstance, hWnd, MAKEINTRESOURCE(IDS_CONFIRMIMPFILE),
  62. MAKEINTRESOURCE(IDS_REGEDIT), MB_ICONQUESTION | MB_YESNO , lpFileName) != IDYES)
  63. {
  64. return;
  65. }
  66. }
  67. ImportRegFile(hWnd, lpFileName, hComputerItem);
  68. if (g_hRegProgressWnd != NULL) {
  69. EnableWindow(hWnd, TRUE);
  70. DestroyWindow(g_hRegProgressWnd);
  71. }
  72. if (!fSilentMode && g_FileErrorStringID != IDS_IMPFILEERRORCANCEL)
  73. {
  74. //
  75. // set defaults
  76. //
  77. UINT uStyle = MB_ICONERROR;
  78. TCHAR szComputerName[MAXKEYNAME + 1];
  79. LPTSTR pszComputerName = szComputerName;
  80. KeyTree_GetKeyName(hComputerItem, pszComputerName, ARRAYSIZE(szComputerName));
  81. //
  82. // For the resource messages that take the pszComputerName parameter,
  83. // map them to a local-computer version if pszComputerName is empty.
  84. // (Alternatively, we could fill in "this computer" or somesuch for
  85. // pszComputerName, but the resulting text is sort of weird, which
  86. // which isn't acceptable since local-computer is the 99% case.)
  87. //
  88. // Also map the uStyle as needed.
  89. //
  90. switch (g_FileErrorStringID)
  91. {
  92. case IDS_IMPFILEERRSUCCESS:
  93. if (!hWnd || *pszComputerName == 0)
  94. {
  95. g_FileErrorStringID += LOCAL_OFFSET;
  96. }
  97. uStyle = MB_ICONINFORMATION | MB_OK;
  98. break;
  99. case IDS_IMPFILEERRREGOPEN:
  100. case IDS_IMPFILEERRNOFILE:
  101. if (*pszComputerName == 0)
  102. {
  103. g_FileErrorStringID += LOCAL_OFFSET;
  104. }
  105. break;
  106. }
  107. //
  108. // Put up the message box
  109. //
  110. InternalMessageBox(g_hInstance, hWnd, MAKEINTRESOURCE(g_FileErrorStringID),
  111. MAKEINTRESOURCE(IDS_REGEDIT), uStyle, lpFileName, pszComputerName);
  112. }
  113. }
  114. /*******************************************************************************
  115. *
  116. * RegEdit_OnDropFiles
  117. *
  118. * DESCRIPTION:
  119. *
  120. * PARAMETERS:
  121. * hWnd, handle of RegEdit window.
  122. *
  123. *******************************************************************************/
  124. VOID
  125. PASCAL
  126. RegEdit_OnDropFiles(
  127. HWND hWnd,
  128. HDROP hDrop
  129. )
  130. {
  131. TCHAR FileName[MAX_PATH];
  132. UINT NumberOfDrops;
  133. UINT CurrentDrop;
  134. BOOL me;
  135. HTREEITEM hSelectedTreeItem = TreeView_GetSelection(g_RegEditData.hKeyTreeWnd);
  136. TreeView_SelectDropTarget(g_RegEditData.hKeyTreeWnd, hSelectedTreeItem);
  137. RegEdit_SetWaitCursor(TRUE);
  138. NumberOfDrops = DragQueryFile(hDrop, (UINT) -1, NULL, 0);
  139. for (CurrentDrop = 0; CurrentDrop < NumberOfDrops; CurrentDrop++)
  140. {
  141. DragQueryFile(hDrop, CurrentDrop, FileName, ARRAYSIZE(FileName));
  142. if (TreeView_GetNextSibling(g_RegEditData.hKeyTreeWnd,
  143. TreeView_GetRoot(g_RegEditData.hKeyTreeWnd)) != NULL)
  144. {
  145. // Remote connections exist
  146. RegEdit_ImportToConnectedComputer(hWnd, FileName);
  147. }
  148. else
  149. {
  150. RegEdit_ImportRegFile(hWnd, FALSE, FileName, RegEdit_GetComputerItem(hSelectedTreeItem));
  151. }
  152. }
  153. DragFinish(hDrop);
  154. TreeView_SelectDropTarget(g_RegEditData.hKeyTreeWnd, NULL);
  155. RegEdit_OnKeyTreeRefresh(hWnd);
  156. RegEdit_SetWaitCursor(FALSE);
  157. }
  158. //------------------------------------------------------------------------------
  159. // RegEdit_SetPrivilege
  160. //
  161. // DESCRIPTION: Enable a priviledge
  162. //
  163. // PARAMETERS: lpszPrivilege - the security constant or its corresponding string
  164. // bEnablePrivilege - TRUE = enable, False = disable
  165. //
  166. //------------------------------------------------------------------------------
  167. BOOL RegEdit_SetPrivilege(LPCTSTR lpszPrivilege, BOOL bEnablePrivilege)
  168. {
  169. TOKEN_PRIVILEGES tp;
  170. LUID luid;
  171. HANDLE hToken;
  172. BOOL fSuccess = FALSE;
  173. HRESULT hr;
  174. if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
  175. {
  176. if (LookupPrivilegeValue(NULL, lpszPrivilege, &luid))
  177. {
  178. tp.PrivilegeCount = 1;
  179. tp.Privileges[0].Luid = luid;
  180. tp.Privileges[0].Attributes = (bEnablePrivilege) ? SE_PRIVILEGE_ENABLED : 0;
  181. // Enable or disable the privilege
  182. if (AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), (PTOKEN_PRIVILEGES) NULL,
  183. (PDWORD) NULL))
  184. {
  185. fSuccess = TRUE;
  186. }
  187. }
  188. CloseHandle(hToken);
  189. }
  190. return fSuccess;
  191. }
  192. //------------------------------------------------------------------------------
  193. // RegEdit_OnCommandLoadHive
  194. //
  195. // DESCRIPTION: Open and Load a Hive
  196. //
  197. // PARAMETERS: hWnd - handle of RegEdit window.
  198. //
  199. //------------------------------------------------------------------------------
  200. VOID RegEdit_OnCommandLoadHive(HWND hWnd)
  201. {
  202. TCHAR achFileName[MAX_PATH];
  203. if (RegEdit_GetFileName(hWnd, IDS_LOADHVREGFILETITLE, IDS_REGLOADHVFILEFILTER,
  204. IDS_REGNODEFEXT, achFileName, ARRAYSIZE(achFileName), TRUE))
  205. {
  206. EDITVALUEPARAM EditValueParam;
  207. RegEdit_SetWaitCursor(TRUE);
  208. EditValueParam.cbValueData = 50 * sizeof(TCHAR);
  209. EditValueParam.pValueData = LocalAlloc(LPTR, EditValueParam.cbValueData);
  210. if (EditValueParam.pValueData)
  211. {
  212. EditValueParam.pValueData[0] = TEXT('\0');
  213. if (DialogBoxParam(g_hInstance, MAKEINTRESOURCE(IDD_INPUTHIVENAME), hWnd,
  214. EditStringValueDlgProc, (LPARAM) &EditValueParam) == IDOK)
  215. {
  216. HRESULT hr;
  217. RegEdit_SetPrivilege(SE_RESTORE_NAME, TRUE);
  218. //
  219. // REVIEW:
  220. // What if EditValueParam.pValueData is greater than 50 characters that have been allocated ?
  221. // Is it NULL terminated ?
  222. //
  223. if ((hr = RegLoadKey(g_RegEditData.hCurrentSelectionKey, (PTSTR)EditValueParam.pValueData,
  224. achFileName)) == ERROR_SUCCESS)
  225. {
  226. RegEdit_OnKeyTreeRefresh(hWnd);
  227. }
  228. else
  229. {
  230. UINT uErrorStringID = IDS_ERRORLOADHV;
  231. switch (hr)
  232. {
  233. case ERROR_PRIVILEGE_NOT_HELD:
  234. uErrorStringID = IDS_ERRORLOADHVPRIV;
  235. break;
  236. case ERROR_SHARING_VIOLATION:
  237. uErrorStringID = IDS_ERRORLOADHVNOSHARE;
  238. break;
  239. case ERROR_ACCESS_DENIED:
  240. uErrorStringID = IDS_ERRORLOADHVNOACC;
  241. break;
  242. }
  243. InternalMessageBox(g_hInstance, hWnd, MAKEINTRESOURCE(uErrorStringID),
  244. MAKEINTRESOURCE(IDS_LOADHVREGFILETITLE), MB_ICONERROR | MB_OK, achFileName);
  245. }
  246. RegEdit_SetPrivilege(SE_RESTORE_NAME, FALSE);
  247. }
  248. LocalFree(EditValueParam.pValueData);
  249. }
  250. RegEdit_SetWaitCursor(FALSE);
  251. }
  252. }
  253. //------------------------------------------------------------------------------
  254. // RegEdit_OnCommandUnloadHive
  255. //
  256. // DESCRIPTION: Open and Load a Hive
  257. //
  258. // PARAMETERS: hWnd - handle of RegEdit window.
  259. //
  260. //------------------------------------------------------------------------------
  261. VOID RegEdit_OnCommandUnloadHive(HWND hWnd)
  262. {
  263. if (InternalMessageBox(g_hInstance, hWnd,
  264. MAKEINTRESOURCE(IDS_CONFIRMDELHIVETEXT), MAKEINTRESOURCE(IDS_CONFIRMDELHIVETITLE),
  265. MB_ICONWARNING | MB_YESNO) == IDYES)
  266. {
  267. HRESULT hr;
  268. TCHAR achKeyName[MAXKEYNAME];
  269. HTREEITEM hSelectedTreeItem = TreeView_GetSelection(g_RegEditData.hKeyTreeWnd);
  270. RegEdit_SetPrivilege(SE_RESTORE_NAME, TRUE);
  271. // must close key to unload it
  272. RegCloseKey(g_RegEditData.hCurrentSelectionKey);
  273. if ((hr = RegUnLoadKey(KeyTree_GetRootKey(hSelectedTreeItem),
  274. KeyTree_GetKeyName(hSelectedTreeItem, achKeyName, ARRAYSIZE(achKeyName)))) ==
  275. ERROR_SUCCESS)
  276. {
  277. g_RegEditData.hCurrentSelectionKey = NULL;
  278. RegEdit_OnKeyTreeRefresh(hWnd);
  279. }
  280. else
  281. {
  282. UINT uErrorStringID = IDS_ERRORUNLOADHV;
  283. switch (hr)
  284. {
  285. case ERROR_PRIVILEGE_NOT_HELD:
  286. uErrorStringID = IDS_ERRORUNLOADHVPRIV;
  287. break;
  288. case ERROR_ACCESS_DENIED:
  289. uErrorStringID = IDS_ERRORUNLOADHVNOACC;
  290. break;
  291. }
  292. InternalMessageBox(g_hInstance, hWnd, MAKEINTRESOURCE(uErrorStringID),
  293. MAKEINTRESOURCE(IDS_UNLOADHIVETITLE), MB_ICONERROR | MB_OK, achKeyName);
  294. // The key couldn't be unloaded so select it again
  295. g_RegEditData.hCurrentSelectionKey = NULL;
  296. RegEdit_KeyTreeSelChanged(hWnd);
  297. }
  298. RegEdit_SetPrivilege(SE_RESTORE_NAME, FALSE);
  299. }
  300. }
  301. /*******************************************************************************
  302. *
  303. * RegEdit_OnCommandImportRegFile
  304. *
  305. * DESCRIPTION:
  306. *
  307. * PARAMETERS:
  308. * hWnd, handle of RegEdit window.
  309. *
  310. *******************************************************************************/
  311. VOID RegEdit_OnCommandImportRegFile(HWND hWnd)
  312. {
  313. TCHAR achFileName[MAX_PATH];
  314. if (RegEdit_GetFileName(hWnd, IDS_IMPORTREGFILETITLE, IDS_REGIMPORTFILEFILTER,
  315. IDS_REGFILEDEFEXT, achFileName, ARRAYSIZE(achFileName), TRUE))
  316. {
  317. // check for networked registries
  318. if (TreeView_GetNextSibling(g_RegEditData.hKeyTreeWnd,
  319. TreeView_GetRoot(g_RegEditData.hKeyTreeWnd)) != NULL)
  320. {
  321. // Remote connections exist
  322. RegEdit_ImportToConnectedComputer(hWnd, achFileName);
  323. }
  324. else
  325. {
  326. RegEdit_SetWaitCursor(TRUE);
  327. RegEdit_ImportRegFile(hWnd, FALSE, achFileName, NULL);
  328. // PERF: Only need to refresh the computer that we imported the
  329. // file into, not the whole thing.
  330. RegEdit_OnKeyTreeRefresh(hWnd);
  331. RegEdit_SetWaitCursor(FALSE);
  332. }
  333. }
  334. }
  335. /*******************************************************************************
  336. *
  337. * RegEdit_ExportRegFile
  338. *
  339. * DESCRIPTION:
  340. *
  341. * PARAMETERS:
  342. * hWnd, handle of RegEdit window.
  343. * fSilentMode, TRUE if no messages should be displayed, else FALSE.
  344. * lpFileName, address of file name buffer.
  345. * lpSelectedPath,
  346. *
  347. *******************************************************************************/
  348. VOID
  349. PASCAL
  350. RegEdit_ExportRegFile(
  351. HWND hWnd,
  352. BOOL fSilentMode,
  353. LPTSTR lpFileName,
  354. LPTSTR lpSelectedPath
  355. )
  356. {
  357. //
  358. // Fix a bug where /a or /e is specified and no file is passed in
  359. //
  360. if (lpFileName == NULL)
  361. {
  362. InternalMessageBox(g_hInstance, hWnd, MAKEINTRESOURCE(IDS_NOFILESPECIFIED),
  363. MAKEINTRESOURCE(IDS_REGEDIT), MB_ICONERROR | MB_OK, lpFileName);
  364. return;
  365. }
  366. switch (g_RegEditData.uExportFormat)
  367. {
  368. case FILE_TYPE_REGEDT32:
  369. ExportRegedt32File(lpFileName, lpSelectedPath);
  370. break;
  371. case FILE_TYPE_REGEDIT4:
  372. ExportWin40RegFile(lpFileName, lpSelectedPath);
  373. break;
  374. case FILE_TYPE_TEXT:
  375. RegEdit_SaveAsSubtree(lpFileName, lpSelectedPath);
  376. break;
  377. default:
  378. ExportWinNT50RegFile(lpFileName, lpSelectedPath);
  379. break;
  380. }
  381. if (g_FileErrorStringID != IDS_EXPFILEERRSUCCESS && g_FileErrorStringID != IDS_IMPFILEERRSUCCESSLOCAL)
  382. {
  383. InternalMessageBox(g_hInstance, hWnd, MAKEINTRESOURCE(g_FileErrorStringID),
  384. MAKEINTRESOURCE(IDS_REGEDIT), MB_ICONERROR | MB_OK, lpFileName);
  385. }
  386. }
  387. //------------------------------------------------------------------------------
  388. // RegEdit_OnCommandExportRegFile
  389. //
  390. // DESCRIPTION:
  391. //
  392. // PARAMETERS: - hWnd, handle of RegEdit window.
  393. //------------------------------------------------------------------------------
  394. VOID RegEdit_OnCommandExportRegFile(HWND hWnd)
  395. {
  396. TCHAR achFileName[MAX_PATH];
  397. LPTSTR lpSelectedPath;
  398. if (RegEdit_GetFileName(hWnd, IDS_EXPORTREGFILETITLE, IDS_REGEXPORTFILEFILTER,
  399. IDS_REGFILEDEFEXT, achFileName, ARRAYSIZE(achFileName), FALSE))
  400. {
  401. RegEdit_SetWaitCursor(TRUE);
  402. lpSelectedPath = g_fRangeAll ? NULL : g_SelectedPath;
  403. RegEdit_ExportRegFile(hWnd, FALSE, achFileName, lpSelectedPath);
  404. RegEdit_SetWaitCursor(FALSE);
  405. }
  406. }
  407. //------------------------------------------------------------------------------
  408. // RegEdit_GetFileName
  409. //
  410. // DESCRIPTION: Gets a file name
  411. //
  412. // PARAMETERS: hWnd - handle of RegEdit window.
  413. // fOpen - TRUE if importing a file, else FALSE if exporting a file.
  414. // lpFileName - address of file name buffer.
  415. // cchFileName - size of file name buffer in TCHARacters.
  416. //
  417. // RETURN: True, if successfull
  418. //------------------------------------------------------------------------------
  419. BOOL RegEdit_GetFileName(HWND hWnd, UINT uTitleStringID, UINT uFilterStringID,
  420. UINT uDefExtStringID, LPTSTR lpFileName, DWORD cchFileName, BOOL fOpen)
  421. {
  422. PTSTR pTitle = NULL;
  423. PTSTR pDefaultExtension = NULL;
  424. PTSTR pFilter = NULL;
  425. PTSTR pFilterChar;
  426. OPENFILENAME OpenFileName;
  427. BOOL fSuccess;
  428. //
  429. // Load various strings that will be displayed and used by the common open
  430. // or save dialog box. Note that if any of these fail, the error is not
  431. // fatal-- the common dialog box may look odd, but will still work.
  432. //
  433. pTitle = LoadDynamicString(uTitleStringID);
  434. if (uDefExtStringID != IDS_REGNODEFEXT)
  435. {
  436. pDefaultExtension = LoadDynamicString(uDefExtStringID);
  437. }
  438. if ((pFilter = LoadDynamicString(uFilterStringID)) != NULL)
  439. {
  440. // The common dialog library requires that the substrings of the
  441. // filter string be separated by nulls, but we cannot load a string
  442. // containing nulls. So we use some dummy character in the resource
  443. // that we now convert to nulls.
  444. for (pFilterChar = pFilter; *pFilterChar != 0; pFilterChar =
  445. CharNext(pFilterChar))
  446. {
  447. if (*pFilterChar == TEXT('#'))
  448. *pFilterChar++ = 0;
  449. }
  450. }
  451. *lpFileName = 0;
  452. memset(&OpenFileName, 0, sizeof(OpenFileName));
  453. OpenFileName.lStructSize = sizeof(OpenFileName);
  454. // DebugAssert(OpenFileName.lStructSize == sizeof(OPENFILENAME));
  455. OpenFileName.hwndOwner = hWnd;
  456. OpenFileName.hInstance = g_hInstance;
  457. OpenFileName.lpstrFilter = pFilter;
  458. OpenFileName.lpstrFile = lpFileName;
  459. OpenFileName.nMaxFile = cchFileName;
  460. OpenFileName.lpstrTitle = pTitle;
  461. if (fOpen)
  462. {
  463. OpenFileName.Flags = OFN_HIDEREADONLY | OFN_EXPLORER |
  464. OFN_FILEMUSTEXIST;
  465. fSuccess = GetOpenFileName(&OpenFileName);
  466. }
  467. else
  468. {
  469. OpenFileName.lpstrDefExt = pDefaultExtension;
  470. OpenFileName.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT |
  471. OFN_EXPLORER | OFN_NOREADONLYRETURN | OFN_PATHMUSTEXIST |
  472. OFN_ENABLEHOOK | OFN_ENABLETEMPLATE;
  473. OpenFileName.lpfnHook = RegCommDlgHookProc;
  474. OpenFileName.lpTemplateName = MAKEINTRESOURCE(IDD_REGEXPORT);
  475. g_RegCommDlgDialogTemplate = IDD_REGEXPORT;
  476. fSuccess = GetSaveFileName(&OpenFileName);
  477. }
  478. //
  479. // Delete all of the dynamic strings that we loaded.
  480. //
  481. if (pTitle != NULL)
  482. DeleteDynamicString(pTitle);
  483. if (pDefaultExtension != NULL)
  484. DeleteDynamicString(pDefaultExtension);
  485. if (pFilter != NULL)
  486. DeleteDynamicString(pFilter);
  487. return fSuccess;
  488. }
  489. /*******************************************************************************
  490. *
  491. * RegProgressDlgProc
  492. *
  493. * DESCRIPTION:
  494. * Callback procedure for the RegAbort dialog box.
  495. *
  496. * PARAMETERS:
  497. * hWnd, handle of RegProgress window.
  498. * Message,
  499. * wParam,
  500. * lParam,
  501. * (returns),
  502. *
  503. *******************************************************************************/
  504. INT_PTR
  505. CALLBACK
  506. RegProgressDlgProc(
  507. HWND hWnd,
  508. UINT Message,
  509. WPARAM wParam,
  510. LPARAM lParam
  511. )
  512. {
  513. switch (Message) {
  514. case WM_INITDIALOG:
  515. //PathSetDlgItemPath(hWnd, IDC_FILENAME, (LPTSTR)lParam);
  516. SetDlgItemText(hWnd, IDC_FILENAME, (LPTSTR) lParam);
  517. break;
  518. default:
  519. return FALSE;
  520. }
  521. return TRUE;
  522. }
  523. /*******************************************************************************
  524. *
  525. * ImportRegFileUICallback
  526. *
  527. * DESCRIPTION:
  528. *
  529. * PARAMETERS:
  530. *
  531. *******************************************************************************/
  532. VOID ImportRegFileUICallback(UINT uPercentage)
  533. {
  534. if (g_hRegProgressWnd != NULL)
  535. {
  536. SendDlgItemMessage(g_hRegProgressWnd, IDC_PROGRESSBAR, PBM_SETPOS,
  537. (WPARAM) uPercentage, 0);
  538. while (MessagePump(g_hRegProgressWnd));
  539. }
  540. }
  541. //------------------------------------------------------------------------------
  542. // RegEdit_ImportToConnectedComputer
  543. //
  544. // DESCRIPTION: Imports a reg. file one or more of the connected computers
  545. //
  546. // PARAMETERS: HWND hWnd
  547. // PTSTR pszFileName - import file
  548. //------------------------------------------------------------------------------
  549. void RegEdit_ImportToConnectedComputer(HWND hWnd, PTSTR pszFileName)
  550. {
  551. DialogBoxParam(g_hInstance, MAKEINTRESOURCE(IDD_REGIMPORTNET), hWnd,
  552. RegConnectedComputerDlgProc, (LPARAM) pszFileName);
  553. }
  554. //------------------------------------------------------------------------------
  555. // RegConnectedComputerDlgProc
  556. //
  557. // DESCRIPTION: Dlg Proc for selecting a connected computer
  558. //
  559. // PARAMETERS:
  560. //------------------------------------------------------------------------------
  561. INT_PTR RegConnectedComputerDlgProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
  562. {
  563. switch (uMessage)
  564. {
  565. case WM_INITDIALOG:
  566. SetWindowLongPtr(hWnd, DWLP_USER, lParam);
  567. return RegImport_OnInitDialog(hWnd);
  568. case WM_COMMAND:
  569. switch (GET_WM_COMMAND_ID(wParam, lParam))
  570. {
  571. case IDOK:
  572. {
  573. PTSTR pszFileName = (PTSTR) GetWindowLongPtr(hWnd, DWLP_USER);
  574. // (pszFileName == NULL) is checked later
  575. RegImport_OnCommandOk(hWnd, pszFileName);
  576. }
  577. // FALL THROUGH
  578. case IDCANCEL:
  579. EndDialog(hWnd, 0);
  580. break;
  581. }
  582. return TRUE;
  583. }
  584. return FALSE;
  585. }
  586. //------------------------------------------------------------------------------
  587. // RegImport_OnInitDialog
  588. //
  589. // DESCRIPTION: Create a list of all the connected computers
  590. //
  591. // PARAMETERS: HWND hWnd
  592. //------------------------------------------------------------------------------
  593. INT_PTR RegImport_OnInitDialog(HWND hWnd)
  594. {
  595. HWND hComputerListWnd;
  596. RECT ClientRect;
  597. LV_COLUMN LVColumn;
  598. LV_ITEM LVItem;
  599. TCHAR achComputerName[MAX_PATH];
  600. HWND hKeyTreeWnd;
  601. TV_ITEM TVItem;
  602. hComputerListWnd = GetDlgItem(hWnd, IDC_COMPUTERLIST);
  603. // Initialize the ListView control.
  604. ListView_SetImageList(hComputerListWnd, g_RegEditData.hImageList,
  605. LVSIL_SMALL);
  606. LVColumn.mask = LVCF_FMT | LVCF_WIDTH;
  607. LVColumn.fmt = LVCFMT_LEFT;
  608. GetClientRect(hComputerListWnd, &ClientRect);
  609. LVColumn.cx = ClientRect.right - GetSystemMetrics(SM_CXVSCROLL) -
  610. 2 * GetSystemMetrics(SM_CXEDGE);
  611. ListView_InsertColumn(hComputerListWnd, 0, &LVColumn);
  612. // Walk through the local machine and each remote connection listed
  613. // in the KeyTree and add it to our RemoteList.
  614. LVItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
  615. LVItem.pszText = achComputerName;
  616. LVItem.iItem = 0;
  617. LVItem.iSubItem = 0;
  618. LVItem.iImage = IMAGEINDEX(IDI_COMPUTER);
  619. hKeyTreeWnd = g_RegEditData.hKeyTreeWnd;
  620. TVItem.mask = TVIF_TEXT;
  621. TVItem.hItem = TreeView_GetRoot(hKeyTreeWnd);
  622. TVItem.pszText = achComputerName;
  623. TVItem.cchTextMax = ARRAYSIZE(achComputerName);
  624. // Set "local computer" in list
  625. LVItem.lParam = (LPARAM) TVItem.hItem;
  626. TreeView_GetItem(hKeyTreeWnd, &TVItem);
  627. ListView_InsertItem(hComputerListWnd, &LVItem);
  628. LVItem.iItem++;
  629. LVItem.iImage = IMAGEINDEX(IDI_REMOTE);
  630. while ((TVItem.hItem = TreeView_GetNextSibling(hKeyTreeWnd,
  631. TVItem.hItem)) != NULL)
  632. {
  633. LVItem.lParam = (LPARAM) TVItem.hItem;
  634. TreeView_GetItem(hKeyTreeWnd, &TVItem);
  635. ListView_InsertItem(hComputerListWnd, &LVItem);
  636. LVItem.iItem++;
  637. }
  638. ListView_SetItemState(hComputerListWnd, 0, LVIS_FOCUSED, LVIS_FOCUSED);
  639. return TRUE;
  640. }
  641. //------------------------------------------------------------------------------
  642. // RegImport_OnCommandOk
  643. //
  644. // DESCRIPTION: Import key to selected computers
  645. //
  646. // PARAMETERS: HWND hWnd,
  647. // PTSTR pszFileName - file to import
  648. //------------------------------------------------------------------------------
  649. void RegImport_OnCommandOk(HWND hWnd, PTSTR pszFileName)
  650. {
  651. LV_ITEM LVItem;
  652. HWND hComputerListWnd;
  653. // Walk through each selected item in the ListView and import the reg file
  654. LVItem.mask = LVIF_PARAM;
  655. LVItem.iItem = -1;
  656. LVItem.iSubItem = 0;
  657. hComputerListWnd = GetDlgItem(hWnd, IDC_COMPUTERLIST);
  658. while ((LVItem.iItem = ListView_GetNextItem(hComputerListWnd, LVItem.iItem,
  659. LVNI_SELECTED)) != -1)
  660. {
  661. ListView_GetItem(hComputerListWnd, &LVItem);
  662. RegEdit_SetWaitCursor(TRUE);
  663. RegEdit_ImportRegFile(hWnd, FALSE, pszFileName, (HTREEITEM) LVItem.lParam);
  664. RegEdit_OnKeyTreeRefresh(hWnd);
  665. RegEdit_SetWaitCursor(FALSE);
  666. }
  667. }