Source code of Windows XP (NT5)
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.

1036 lines
25 KiB

  1. // ChooseFileNamePage.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "CertWiz.h"
  5. #include "ChooseFileName.h"
  6. #include "Certificat.h"
  7. #include "Shlwapi.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CChooseFileNamePage property page
  15. IMPLEMENT_DYNCREATE(CChooseFileNamePage, CIISWizardPage)
  16. static BOOL
  17. AnswerIsYes(UINT id, CString& file)
  18. {
  19. CString strMessage;
  20. AfxFormatString1(strMessage, id, file);
  21. return (IDYES == AfxMessageBox(strMessage, MB_ICONEXCLAMATION | MB_YESNO));
  22. }
  23. CChooseFileNamePage::CChooseFileNamePage(UINT id,
  24. UINT defaultID,
  25. UINT extID,
  26. UINT filterID,
  27. CString * pOutFileName,
  28. CString csAdditionalInfo)
  29. : CIISWizardPage(id, IDS_CERTWIZ, TRUE),
  30. m_id(id),
  31. m_defaultID(defaultID),
  32. m_DoReplaceFile(FALSE),
  33. m_pOutFileName(pOutFileName),
  34. m_AdditionalInfo(csAdditionalInfo)
  35. {
  36. //{{AFX_DATA_INIT(CChooseFileNamePage)
  37. m_FileName = _T("");
  38. //}}AFX_DATA_INIT
  39. if (extID != 0)
  40. ext.LoadString(extID);
  41. if (filterID != 0)
  42. filter.LoadString(filterID);
  43. // replace '!'s in this string to null chars
  44. for (int i = 0; i < filter.GetLength(); i++)
  45. {
  46. if (filter[i] == L'!')
  47. filter.SetAt(i, L'\0');
  48. }
  49. }
  50. CChooseFileNamePage::~CChooseFileNamePage()
  51. {
  52. }
  53. void CChooseFileNamePage::DoDataExchange(CDataExchange* pDX)
  54. {
  55. CIISWizardPage::DoDataExchange(pDX);
  56. //{{AFX_DATA_MAP(CChooseFileNamePage)
  57. DDX_Text(pDX, IDC_FILE_NAME, m_FileName);
  58. //}}AFX_DATA_MAP
  59. }
  60. LRESULT
  61. CChooseFileNamePage::OnWizardBack()
  62. {
  63. ASSERT(FALSE);
  64. return 1;
  65. }
  66. #if 0
  67. #define SHOW_MESSAGE_BOX(id,str)\
  68. do {\
  69. CString strMessage;\
  70. AfxFormatString1(strMessage, (id), (str));\
  71. if (IDNO == AfxMessageBox(strMessage, MB_ICONEXCLAMATION | MB_YESNO))\
  72. {\
  73. CEdit * pEdit = (CEdit *)CWnd::FromHandle(GetDlgItem(IDC_FILE_NAME)->m_hWnd);\
  74. pEdit->SetSel(0, -1);\
  75. pEdit->SetFocus();\
  76. return 1;\
  77. }\
  78. } while(FALSE)
  79. #endif
  80. LRESULT CChooseFileNamePage::DoWizardNext(LRESULT id)
  81. {
  82. if (id != 1)
  83. {
  84. ASSERT(m_pOutFileName != NULL);
  85. *m_pOutFileName = m_FileName;
  86. }
  87. else
  88. {
  89. UpdateData(FALSE);
  90. SetWizardButtons(PSWIZB_BACK);
  91. GetDlgItem(IDC_FILE_NAME)->SendMessage(EM_SETSEL, 0, -1);
  92. GetDlgItem(IDC_FILE_NAME)->SetFocus();
  93. MessageBeep(MB_ICONQUESTION);
  94. }
  95. return id;
  96. }
  97. BOOL CChooseFileNamePage::OnSetActive()
  98. {
  99. SetWizardButtons(m_FileName.IsEmpty() ?
  100. PSWIZB_BACK : PSWIZB_BACK | PSWIZB_NEXT);
  101. return CIISWizardPage::OnSetActive();
  102. }
  103. BEGIN_MESSAGE_MAP(CChooseFileNamePage, CIISWizardPage)
  104. //{{AFX_MSG_MAP(CChooseCAPage)
  105. ON_BN_CLICKED(IDC_BROWSE_BTN, OnBrowseBtn)
  106. ON_EN_CHANGE(IDC_FILE_NAME, OnChangeFileName)
  107. //}}AFX_MSG_MAP
  108. END_MESSAGE_MAP()
  109. /////////////////////////////////////////////////////////////////////////////
  110. // CChooseCAPage message handlers
  111. void CChooseFileNamePage::OnBrowseBtn()
  112. {
  113. ASSERT(FALSE);
  114. }
  115. void CChooseFileNamePage::Browse(CString& strPath, CString& strFile)
  116. {
  117. if (strPath.IsEmpty())
  118. {
  119. ::GetCurrentDirectory(MAX_PATH, strPath.GetBuffer(MAX_PATH + 1));
  120. strPath.ReleaseBuffer();
  121. }
  122. CFileDialog fileName(IsReadFileDlg());
  123. fileName.m_ofn.Flags |= OFN_NOCHANGEDIR | OFN_OVERWRITEPROMPT;
  124. if (IsReadFileDlg())
  125. fileName.m_ofn.Flags |= OFN_PATHMUSTEXIST;
  126. else
  127. fileName.m_ofn.Flags |= OFN_NOREADONLYRETURN;
  128. // We need to disable hook to show new style of File Dialog
  129. fileName.m_ofn.Flags &= ~(OFN_ENABLEHOOK);
  130. CString strExt = _T("*");
  131. strExt += ext;
  132. fileName.m_ofn.lpstrDefExt = strExt;
  133. fileName.m_ofn.lpstrFile = strFile.GetBuffer(MAX_PATH+1);
  134. fileName.m_ofn.nMaxFile = MAX_PATH;
  135. fileName.m_ofn.lpstrInitialDir = strPath.IsEmpty() ? NULL : (LPCTSTR)strPath;
  136. fileName.m_ofn.lpstrFilter = filter;
  137. fileName.m_ofn.nFilterIndex = 0;
  138. if (IDOK == fileName.DoModal())
  139. {
  140. ASSERT(NULL != GetDlgItem(IDC_FILE_NAME));
  141. CString strPrev;
  142. GetDlgItemText(IDC_FILE_NAME, strPrev);
  143. if (strPrev.CompareNoCase(strFile) != 0)
  144. {
  145. SetDlgItemText(IDC_FILE_NAME, strFile);
  146. m_DoReplaceFile = TRUE;
  147. FileNameChanged();
  148. }
  149. }
  150. strFile.ReleaseBuffer();
  151. }
  152. BOOL CChooseFileNamePage::OnInitDialog()
  153. {
  154. CIISWizardPage::OnInitDialog();
  155. if (GetDlgItem(IDC_FILE_NAME) != NULL)
  156. {
  157. SHAutoComplete(GetDlgItem(IDC_FILE_NAME)->m_hWnd, SHACF_FILESYSTEM);
  158. GetDlgItem(IDC_FILE_NAME)->SetFocus();
  159. }
  160. SetWizardButtons(m_FileName.IsEmpty() ?
  161. PSWIZB_BACK : PSWIZB_BACK | PSWIZB_NEXT);
  162. return FALSE;
  163. }
  164. void CChooseFileNamePage::OnChangeFileName()
  165. {
  166. UpdateData(TRUE);
  167. //
  168. // Our replacement flag is not valid now:
  169. // It may be set to TRUE only when name was entered through
  170. // FileOpen dialog box which asks user about replacing itself
  171. //
  172. m_DoReplaceFile = FALSE;
  173. SetWizardButtons(m_FileName.IsEmpty() ?
  174. PSWIZB_BACK : PSWIZB_BACK | PSWIZB_NEXT);
  175. // call virtual handler to notify inherited classes
  176. FileNameChanged();
  177. }
  178. BOOL IsValidFilenameChar(TCHAR cChar)
  179. {
  180. switch (PathGetCharType((TCHAR)cChar))
  181. {
  182. case GCT_INVALID:
  183. case GCT_WILD:
  184. case GCT_SEPARATOR:
  185. return FALSE;
  186. case GCT_LFNCHAR:
  187. case GCT_SHORTCHAR:
  188. break;
  189. }
  190. return TRUE;
  191. }
  192. CString GimmieValidFilenameFromString(LPCTSTR path)
  193. {
  194. CString str;
  195. // remove all bad characters
  196. // remove forward slashes
  197. // remove commas, semicolons...
  198. str = _T("");
  199. UINT len = lstrlen(path);
  200. TCHAR c = _T('');
  201. for (UINT i = 0; i < len; i++)
  202. {
  203. c = path[i];
  204. if (c != _T('\"'))
  205. {
  206. if (TRUE == IsValidFilenameChar(c))
  207. {
  208. str = str + c;
  209. }
  210. }
  211. }
  212. return str;
  213. }
  214. void
  215. CChooseFileNamePage::GetDefaultFileName(CString& str)
  216. {
  217. if (m_defaultID != 0)
  218. {
  219. // check for special type of file
  220. // which includes a %s string...
  221. if (m_defaultID == IDS_PFX_FILE_DEFAULT)
  222. {
  223. CString str1;
  224. str1.LoadString(m_defaultID);
  225. if (str1.Find(_T("%s")) != -1)
  226. {
  227. TCHAR szComputerName[MAX_COMPUTERNAME_LENGTH + 1];
  228. DWORD dwSize = sizeof(szComputerName);
  229. if (GetComputerName(szComputerName, &dwSize))
  230. {
  231. CString csOurFileName;
  232. csOurFileName = szComputerName;
  233. // m_AdditionalInfo should contain
  234. // /LM/W3SVC/1 at this point
  235. // let's make a filename from it.
  236. if (m_AdditionalInfo.GetLength() >= 4)
  237. {
  238. CString key_path_lm = SZ_MBN_SEP_STR SZ_MBN_MACHINE SZ_MBN_SEP_STR;
  239. if (m_AdditionalInfo.Left(4) == key_path_lm)
  240. {
  241. m_AdditionalInfo = m_AdditionalInfo.Right(m_AdditionalInfo.GetLength() - 4);
  242. }
  243. else
  244. {
  245. key_path_lm = SZ_MBN_MACHINE SZ_MBN_SEP_STR;
  246. if (m_AdditionalInfo.Left(3) == key_path_lm)
  247. {
  248. m_AdditionalInfo = m_AdditionalInfo.Right(m_AdditionalInfo.GetLength() - 3);
  249. }
  250. }
  251. }
  252. csOurFileName = csOurFileName + _T("_") + GimmieValidFilenameFromString(m_AdditionalInfo);
  253. // add on other things...
  254. str.Format(str1, csOurFileName);
  255. }
  256. else
  257. {
  258. str.Format(str1, _T("1"));
  259. }
  260. }
  261. else
  262. {
  263. str.LoadString(m_defaultID);
  264. }
  265. }
  266. else
  267. {
  268. str.LoadString(m_defaultID);
  269. }
  270. }
  271. // set system disk letter to the string
  272. TCHAR sz[MAX_PATH];
  273. if (MAX_PATH >= GetSystemDirectory(sz, MAX_PATH))
  274. {
  275. str.SetAt(0, sz[0]);
  276. str.MakeLower();
  277. }
  278. }
  279. /////////////////////////////////////////////////////////////////////////////
  280. // CChooseReadFileName property page
  281. IMPLEMENT_DYNCREATE(CChooseReadFileName, CChooseFileNamePage)
  282. CChooseReadFileName::CChooseReadFileName(UINT id,
  283. UINT defaultID,
  284. UINT extID,
  285. UINT filterID,
  286. CString * pOutFileName,
  287. CString csAdditionalInfo
  288. )
  289. : CChooseFileNamePage(id, defaultID, extID, filterID, pOutFileName, csAdditionalInfo)
  290. {
  291. }
  292. BEGIN_MESSAGE_MAP(CChooseReadFileName, CChooseFileNamePage)
  293. //{{AFX_MSG_MAP(CChooseReadFileName)
  294. ON_BN_CLICKED(IDC_BROWSE_BTN, OnBrowseBtn)
  295. //}}AFX_MSG_MAP
  296. END_MESSAGE_MAP()
  297. BOOL
  298. CChooseReadFileName::OnInitDialog()
  299. {
  300. GetDefaultFileName(m_FileName);
  301. // check if this default file exists
  302. if (!PathFileExists(m_FileName))
  303. {
  304. // try to find first file with this extension
  305. CString find_str = m_FileName;
  306. WIN32_FIND_DATA find_data;
  307. PathRemoveFileSpec(find_str.GetBuffer(MAX_PATH));
  308. find_str.ReleaseBuffer();
  309. find_str += _T("*");
  310. find_str += ext;
  311. HANDLE hFind = FindFirstFile(find_str, &find_data);
  312. if ( hFind != INVALID_HANDLE_VALUE
  313. && (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0
  314. )
  315. {
  316. PathRemoveFileSpec(m_FileName.GetBuffer(MAX_PATH));
  317. m_FileName.ReleaseBuffer();
  318. m_FileName += find_data.cFileName;
  319. FindClose(hFind);
  320. }
  321. else
  322. {
  323. // if nothing found, just attach *.exe to the path
  324. // it will prevent user from just clicking Next
  325. m_FileName = find_str;
  326. }
  327. }
  328. return CChooseFileNamePage::OnInitDialog();
  329. }
  330. LRESULT
  331. CChooseReadFileName::OnWizardNext()
  332. {
  333. LRESULT id = 0;
  334. CString buf;
  335. UpdateData();
  336. // check if this file exists
  337. if ( !PathFileExists(m_FileName)
  338. && !PathIsDirectory(m_FileName)
  339. )
  340. {
  341. // try with default extension if it is just filename
  342. CString str = m_FileName;
  343. LPTSTR p = PathFindExtension(str);
  344. if (p != NULL && *p == 0)
  345. {
  346. str += ext;
  347. if (PathFileExists(str))
  348. {
  349. m_FileName = str;
  350. goto DoNext;
  351. }
  352. }
  353. AfxFormatString1(buf, IDS_FILE_DOES_NOT_EXIST, m_FileName);
  354. AfxMessageBox(buf, MB_OK);
  355. id = 1;
  356. }
  357. else if (PathIsDirectory(m_FileName))
  358. {
  359. AfxFormatString1(buf, IDS_FILE_IS_DIRECTORY, m_FileName);
  360. AfxMessageBox(buf, MB_OK);
  361. if (m_FileName.Right(1) != L'\\')
  362. m_FileName += _T("\\");
  363. id = 1;
  364. }
  365. DoNext:
  366. return DoWizardNext(id);
  367. }
  368. void CChooseReadFileName::OnBrowseBtn()
  369. {
  370. CString strFile, strPath;
  371. GetDlgItemText(IDC_FILE_NAME, m_FileName);
  372. if (!PathFileExists(m_FileName))
  373. {
  374. int n = m_FileName.ReverseFind(_T('\\'));
  375. if (n != -1)
  376. {
  377. strPath = m_FileName.Left(n);
  378. if (!PathFileExists(strPath))
  379. {
  380. strPath.Empty();
  381. strFile = m_FileName.Right(m_FileName.GetLength() - n - 1);
  382. }
  383. else if (PathIsDirectory(strPath))
  384. {
  385. strFile = m_FileName.Right(m_FileName.GetLength() - n - 1);
  386. }
  387. }
  388. else
  389. strFile = m_FileName;
  390. }
  391. else if (PathIsDirectory(m_FileName))
  392. {
  393. strPath = m_FileName;
  394. }
  395. else
  396. {
  397. // split filename and path
  398. strPath = m_FileName;
  399. PathRemoveFileSpec(strPath.GetBuffer(0));
  400. strPath.ReleaseBuffer();
  401. strFile = PathFindFileName(m_FileName);
  402. }
  403. CChooseFileNamePage::Browse(strPath, strFile);
  404. }
  405. /////////////////////////////////////////////////////////////////////////////
  406. // CChooseWriteFileName
  407. IMPLEMENT_DYNCREATE(CChooseWriteFileName, CChooseFileNamePage)
  408. CChooseWriteFileName::CChooseWriteFileName(UINT id,
  409. UINT defaultID,
  410. UINT extID,
  411. UINT filterID,
  412. CString * pOutFileName,
  413. CString csAdditionalInfo
  414. )
  415. : CChooseFileNamePage(id, defaultID, extID, filterID, pOutFileName, csAdditionalInfo)
  416. {
  417. }
  418. BEGIN_MESSAGE_MAP(CChooseWriteFileName, CChooseFileNamePage)
  419. //{{AFX_MSG_MAP(CChooseWriteFileName)
  420. ON_BN_CLICKED(IDC_BROWSE_BTN, OnBrowseBtn)
  421. //}}AFX_MSG_MAP
  422. END_MESSAGE_MAP()
  423. BOOL
  424. CChooseWriteFileName::OnInitDialog()
  425. {
  426. GetDefaultFileName(m_FileName);
  427. return CChooseFileNamePage::OnInitDialog();
  428. }
  429. LRESULT
  430. CChooseWriteFileName::OnWizardNext()
  431. {
  432. LRESULT id = 0;
  433. UpdateData();
  434. CString fileName = m_FileName, strPathOnly;
  435. if (PathIsURL(fileName))
  436. {
  437. // we cannot use URLs
  438. id = 1;
  439. goto ExitPoint;
  440. }
  441. if (PathIsUNC(fileName))
  442. {
  443. if (PathIsUNCServer(fileName))
  444. {
  445. // path is incomplete
  446. id = 1;
  447. goto ExitPoint;
  448. }
  449. if (PathIsUNCServerShare(fileName))
  450. {
  451. // path is incomplete
  452. id = 1;
  453. goto ExitPoint;
  454. }
  455. }
  456. // If it is not an UNC, then make sure we have absolute path
  457. else if (PathIsRelative(fileName))
  458. {
  459. // We will make path from default drive root,
  460. // not from current directory
  461. CString path;
  462. if (0 != GetCurrentDirectory(MAX_PATH, path.GetBuffer(MAX_PATH)))
  463. {
  464. TCHAR szRoot[5];
  465. fileName = PathBuildRoot(szRoot, PathGetDriveNumber(path));
  466. PathAppend(fileName.GetBuffer(MAX_PATH), m_FileName);
  467. fileName.ReleaseBuffer();
  468. }
  469. else
  470. ASSERT(FALSE);
  471. }
  472. // Check if we already have file with this name
  473. if (PathFileExists(fileName))
  474. {
  475. // if it is directory, do nothing, file spec is incomplete
  476. if (PathIsDirectory(fileName))
  477. id = 1;
  478. else
  479. {
  480. if (!m_DoReplaceFile)
  481. id = AnswerIsYes(IDS_REPLACE_FILE, fileName) ? 0 : 1;
  482. }
  483. goto ExitPoint;
  484. }
  485. // File does not exists
  486. //
  487. // we should check, if target directory exists
  488. strPathOnly = fileName;
  489. if (strPathOnly.Right(1) != _T('\\'))
  490. {
  491. if (PathRemoveFileSpec(strPathOnly.GetBuffer(MAX_PATH)))
  492. {
  493. if (PathIsUNCServerShare(strPathOnly))
  494. {
  495. // check if we have write access to this
  496. if (GetFileAttributes(strPathOnly) & FILE_ATTRIBUTE_READONLY)
  497. {
  498. id = 1;
  499. goto ExitPoint;
  500. }
  501. }
  502. if (!PathIsDirectory(strPathOnly))
  503. {
  504. id = AnswerIsYes(IDS_ASK_CREATE_DIR, strPathOnly) ? 0 : 1;
  505. goto ExitPoint;
  506. }
  507. }
  508. strPathOnly.ReleaseBuffer();
  509. // If user entered filename with dot only (qqqq.) it means
  510. // that no extension should be used
  511. if (fileName.Right(1) == _T("."))
  512. {
  513. // remove this dot and check if this file exists
  514. fileName.ReleaseBuffer(fileName.GetLength() - 1);
  515. if (PathIsDirectory(fileName))
  516. {
  517. id = 1;
  518. }
  519. else if (PathFileExists(fileName))
  520. {
  521. id = AnswerIsYes(IDS_REPLACE_FILE, fileName) ? 0 : 1;
  522. }
  523. goto ExitPoint;
  524. }
  525. }
  526. else
  527. {
  528. // not clear, what to do with this
  529. id = 1;
  530. goto ExitPoint;
  531. }
  532. // It could be just a file name, without extension, try
  533. // with default extension now
  534. if (PathFindExtension(fileName) == NULL)
  535. {
  536. fileName += ext;
  537. if (PathIsDirectory(fileName))
  538. {
  539. id = 1;
  540. }
  541. else if (PathFileExists(fileName))
  542. {
  543. id = AnswerIsYes(IDS_REPLACE_FILE, fileName) ? 0 : 1;
  544. }
  545. goto ExitPoint;
  546. }
  547. ExitPoint:
  548. fileName.MakeLower();
  549. m_FileName = fileName;
  550. // prepare to go to the next page
  551. return DoWizardNext(id);
  552. }
  553. // I try to start FileOpen dialog in some reasonable directory
  554. //
  555. void CChooseWriteFileName::OnBrowseBtn()
  556. {
  557. CString strPath, strFile;
  558. UpdateData();
  559. strPath = m_FileName;
  560. if (!PathIsDirectory(strPath))
  561. {
  562. LPTSTR pPath = strPath.GetBuffer(strPath.GetLength());
  563. if (PathRemoveFileSpec(pPath))
  564. {
  565. // check if path part of filename exists
  566. if (PathIsDirectory(pPath))
  567. {
  568. // we will use non-path part of spec as a filename
  569. strFile = PathFindFileName(m_FileName);
  570. }
  571. else
  572. {
  573. // it is wrong path, use default one
  574. // TODO: actually I need to take from filespec all existent
  575. // chunks of path and filename, for example c:\aa\bb\cc\dd.txt,
  576. // if c:\aa\bb exists, then strPath should be set to c:\aa\bb,
  577. // and strFile to dd.txt
  578. strPath.Empty();
  579. }
  580. }
  581. else
  582. {
  583. // it is filename only
  584. strFile = m_FileName;
  585. strPath.Empty();
  586. }
  587. strPath.ReleaseBuffer();
  588. }
  589. CChooseFileNamePage::Browse(strPath, strFile);
  590. }
  591. /////////////////////////////////////////////////////////////////////////////
  592. // CChooseRespFile property page
  593. IMPLEMENT_DYNCREATE(CChooseRespFile, CChooseFileNamePage)
  594. CChooseRespFile::CChooseRespFile(CCertificate * pCert)
  595. : CChooseReadFileName(CChooseRespFile::IDD,
  596. IDS_RESP_FILE_DEFAULT,
  597. IDS_RESP_FILE_EXT,
  598. IDS_RESP_FILE_FILTER,
  599. &pCert->m_RespFileName,
  600. pCert->m_WebSiteInstanceName
  601. ),
  602. m_pCert(pCert)
  603. {
  604. //{{AFX_DATA_INIT(CChooseRespFile)
  605. // NOTE: the ClassWizard will add member initialization here
  606. //}}AFX_DATA_INIT
  607. }
  608. CChooseRespFile::~CChooseRespFile()
  609. {
  610. }
  611. void CChooseRespFile::FileNameChanged()
  612. {
  613. // we should remove any error messages now
  614. SetDlgItemText(IDC_ERROR_MSG, _T(""));
  615. GetDlgItem(IDC_ERROR_MSG)->InvalidateRect(NULL, TRUE);
  616. GetDlgItem(IDC_ERROR_MSG)->UpdateWindow();
  617. }
  618. void CChooseRespFile::DoDataExchange(CDataExchange* pDX)
  619. {
  620. CChooseReadFileName::DoDataExchange(pDX);
  621. //{{AFX_DATA_MAP(CChooseRespFile)
  622. //}}AFX_DATA_MAP
  623. }
  624. BEGIN_MESSAGE_MAP(CChooseRespFile, CChooseReadFileName)
  625. //{{AFX_MSG_MAP(CChooseRespFile)
  626. ON_WM_CTLCOLOR()
  627. //}}AFX_MSG_MAP
  628. END_MESSAGE_MAP()
  629. /////////////////////////////////////////////////////////////////////////////
  630. // CChooseRespFile message handlers
  631. HBRUSH
  632. CChooseRespFile::OnCtlColor(
  633. IN CDC * pDC,
  634. IN CWnd * pWnd,
  635. IN UINT nCtlColor
  636. )
  637. {
  638. if (pWnd->GetDlgCtrlID() == IDC_ERROR_MSG)
  639. {
  640. //
  641. // Default processing...
  642. //
  643. return CPropertyPage::OnCtlColor(pDC, pWnd, nCtlColor);
  644. }
  645. else
  646. return CIISWizardPage::OnCtlColor(pDC, pWnd, nCtlColor);
  647. }
  648. LRESULT CChooseRespFile::OnWizardNext()
  649. {
  650. LRESULT id = 1;
  651. // Parent class will check all about files
  652. if (1 != CChooseReadFileName::OnWizardNext())
  653. {
  654. m_pCert->m_RespFileName = m_FileName;
  655. if (m_pCert->GetResponseCert() == NULL)
  656. {
  657. CString strInstanceName;
  658. CString str;
  659. // it is possible, that this is wrong response file
  660. // we will try to inform user, for which site this response
  661. // file was created
  662. if (m_pCert->FindInstanceNameForResponse(strInstanceName))
  663. {
  664. AfxFormatString1(str, IDS_CERTKEY_MISMATCH_ERROR1, strInstanceName);
  665. }
  666. // it is possible that this certificate response file already have been processed
  667. // in this case it should be in MY store
  668. else if (m_pCert->IsResponseInstalled(strInstanceName))
  669. {
  670. if (!strInstanceName.IsEmpty())
  671. AfxFormatString1(str,
  672. IDS_CERTKEY_ALREADY_INSTALLED_WHERE, strInstanceName);
  673. else
  674. str.LoadString(IDS_CERTKEY_ALREADY_INSTALLED);
  675. }
  676. else
  677. {
  678. // request probably was canceled
  679. str.LoadString(IDS_CERTKEY_MISMATCH_ERROR2);
  680. }
  681. SetDlgItemText(IDC_ERROR_MSG, str);
  682. SetWizardButtons(PSWIZB_BACK);
  683. }
  684. else
  685. id = IDD_PAGE_NEXT;
  686. }
  687. return id;
  688. }
  689. LRESULT
  690. CChooseRespFile::OnWizardBack()
  691. {
  692. return IDD_PAGE_PREV;
  693. }
  694. /////////////////////////////////////////////////////////////////////////////
  695. // CChooseReqFile property page
  696. IMPLEMENT_DYNCREATE(CChooseReqFile, CChooseWriteFileName)
  697. CChooseReqFile::CChooseReqFile(CCertificate * pCert)
  698. : CChooseWriteFileName(CChooseReqFile::IDD,
  699. IDS_REQ_FILE_DEFAULT,
  700. IDS_REQ_FILE_EXT,
  701. IDS_REQ_FILE_FILTER,
  702. &pCert->m_ReqFileName,
  703. pCert->m_WebSiteInstanceName
  704. ),
  705. m_pCert(pCert)
  706. {
  707. //{{AFX_DATA_INIT(CChooseRespFile)
  708. //}}AFX_DATA_INIT
  709. }
  710. CChooseReqFile::~CChooseReqFile()
  711. {
  712. }
  713. void CChooseReqFile::DoDataExchange(CDataExchange* pDX)
  714. {
  715. CChooseWriteFileName::DoDataExchange(pDX);
  716. //{{AFX_DATA_MAP(CChooseRespFile)
  717. //}}AFX_DATA_MAP
  718. }
  719. LRESULT
  720. CChooseReqFile::OnWizardBack()
  721. {
  722. return IDD_PAGE_PREV;
  723. }
  724. LRESULT
  725. CChooseReqFile::OnWizardNext()
  726. {
  727. if (CChooseWriteFileName::OnWizardNext() != 1)
  728. return IDD_PAGE_NEXT;
  729. return 1;
  730. }
  731. BEGIN_MESSAGE_MAP(CChooseReqFile, CChooseWriteFileName)
  732. //{{AFX_MSG_MAP(CChooseReqFile)
  733. //}}AFX_MSG_MAP
  734. END_MESSAGE_MAP()
  735. /////////////////////////////////////////////////////////////////////////////
  736. // CChooseReqFile property page
  737. IMPLEMENT_DYNCREATE(CChooseReqFileRenew, CChooseWriteFileName)
  738. CChooseReqFileRenew::CChooseReqFileRenew(CCertificate * pCert)
  739. : CChooseWriteFileName(CChooseReqFileRenew::IDD,
  740. IDS_REQ_FILE_DEFAULT,
  741. IDS_REQ_FILE_EXT,
  742. IDS_REQ_FILE_FILTER,
  743. &pCert->m_ReqFileName,
  744. pCert->m_WebSiteInstanceName
  745. ),
  746. m_pCert(pCert)
  747. {
  748. //{{AFX_DATA_INIT(CChooseRespFile)
  749. //}}AFX_DATA_INIT
  750. }
  751. CChooseReqFileRenew::~CChooseReqFileRenew()
  752. {
  753. }
  754. void CChooseReqFileRenew::DoDataExchange(CDataExchange* pDX)
  755. {
  756. CChooseWriteFileName::DoDataExchange(pDX);
  757. //{{AFX_DATA_MAP(CChooseRespFile)
  758. //}}AFX_DATA_MAP
  759. }
  760. LRESULT
  761. CChooseReqFileRenew::OnWizardBack()
  762. {
  763. return IDD_PAGE_PREV;
  764. }
  765. LRESULT
  766. CChooseReqFileRenew::OnWizardNext()
  767. {
  768. if (CChooseWriteFileName::OnWizardNext() != 1)
  769. return IDD_PAGE_NEXT;
  770. return 1;
  771. }
  772. BEGIN_MESSAGE_MAP(CChooseReqFileRenew, CChooseWriteFileName)
  773. //{{AFX_MSG_MAP(CChooseReqFileRenew)
  774. //}}AFX_MSG_MAP
  775. END_MESSAGE_MAP()
  776. /////////////////////////////////////////////////////////////////////////////
  777. // CChooseReqFileRenew message handlers
  778. /////////////////////////////////////////////////////////////////////////////
  779. // CChooseKeyFile property page
  780. IMPLEMENT_DYNCREATE(CChooseKeyFile, CChooseReadFileName)
  781. CChooseKeyFile::CChooseKeyFile(CCertificate * pCert)
  782. : CChooseReadFileName(CChooseKeyFile::IDD,
  783. IDS_KEY_FILE_DEFAULT,
  784. IDS_KEY_FILE_EXT,
  785. IDS_KEY_FILE_FILTER,
  786. &pCert->m_KeyFileName,
  787. pCert->m_WebSiteInstanceName),
  788. m_pCert(pCert)
  789. {
  790. }
  791. CChooseKeyFile::~CChooseKeyFile()
  792. {
  793. }
  794. void CChooseKeyFile::DoDataExchange(CDataExchange* pDX)
  795. {
  796. CChooseReadFileName::DoDataExchange(pDX);
  797. //{{AFX_DATA_MAP(CChooseRespFile)
  798. //}}AFX_DATA_MAP
  799. }
  800. LRESULT
  801. CChooseKeyFile::OnWizardBack()
  802. {
  803. return IDD_PAGE_PREV;
  804. }
  805. LRESULT
  806. CChooseKeyFile::OnWizardNext()
  807. {
  808. CString strFileName = m_pCert->m_KeyFileName;
  809. if (CChooseReadFileName::OnWizardNext() != 1)
  810. {
  811. // if file name was changed then probably password is wrong now
  812. // and if cert context was imported before -- it is also invalid
  813. //
  814. if (m_pCert->m_KeyFileName.CompareNoCase(strFileName))
  815. {
  816. m_pCert->m_KeyPassword.Empty();
  817. m_pCert->DeleteKeyRingCert();
  818. }
  819. return IDD_PAGE_NEXT;
  820. }
  821. return 1;
  822. }
  823. BEGIN_MESSAGE_MAP(CChooseKeyFile, CChooseReadFileName)
  824. //{{AFX_MSG_MAP(CChooseKeyFile)
  825. //}}AFX_MSG_MAP
  826. END_MESSAGE_MAP()
  827. /////////////////////////////////////////////////////////////////////////////
  828. // CChooseImportPFXFile property page
  829. IMPLEMENT_DYNCREATE(CChooseImportPFXFile, CChooseReadFileName)
  830. CChooseImportPFXFile::CChooseImportPFXFile(CCertificate * pCert)
  831. : CChooseReadFileName(CChooseImportPFXFile::IDD,
  832. IDS_PFX_FILE_DEFAULT,
  833. IDS_PFX_FILE_EXT,
  834. IDS_PFX_FILE_FILTER,
  835. &pCert->m_KeyFileName,
  836. pCert->m_WebSiteInstanceName),
  837. m_pCert(pCert)
  838. {
  839. //{{AFX_DATA_INIT(CChooseImportPFXFile)
  840. m_MarkAsExportable = FALSE;
  841. //}}AFX_DATA_INIT
  842. }
  843. CChooseImportPFXFile::~CChooseImportPFXFile()
  844. {
  845. }
  846. void CChooseImportPFXFile::DoDataExchange(CDataExchange* pDX)
  847. {
  848. CChooseReadFileName::DoDataExchange(pDX);
  849. //{{AFX_DATA_MAP(CChooseImportPFXFile)
  850. DDX_Check(pDX, IDC_MARK_AS_EXPORTABLE, m_MarkAsExportable);
  851. //}}AFX_DATA_MAP
  852. }
  853. LRESULT
  854. CChooseImportPFXFile::OnWizardBack()
  855. {
  856. return IDD_PAGE_PREV;
  857. }
  858. LRESULT
  859. CChooseImportPFXFile::OnWizardNext()
  860. {
  861. m_pCert->m_MarkAsExportable = m_MarkAsExportable;
  862. CString strFileName = m_pCert->m_KeyFileName;
  863. if (CChooseReadFileName::OnWizardNext() != 1)
  864. {
  865. /*
  866. // if file name was changed then probably password is wrong now
  867. // and if cert context was imported before -- it is also invalid
  868. //
  869. if (m_pCert->m_KeyFileName.CompareNoCase(strFileName))
  870. {
  871. m_pCert->m_KeyPassword.Empty();
  872. m_pCert->DeleteKeyRingCert();
  873. }
  874. */
  875. return IDD_PAGE_NEXT;
  876. }
  877. return 1;
  878. }
  879. void CChooseImportPFXFile::OnExportable()
  880. {
  881. UpdateData();
  882. }
  883. BEGIN_MESSAGE_MAP(CChooseImportPFXFile, CChooseReadFileName)
  884. //{{AFX_MSG_MAP(CChooseImportPFXFile)
  885. ON_BN_CLICKED(IDC_MARK_AS_EXPORTABLE, OnExportable)
  886. //}}AFX_MSG_MAP
  887. END_MESSAGE_MAP()
  888. /////////////////////////////////////////////////////////////////////////////
  889. // CChooseExportPFXFile property page
  890. IMPLEMENT_DYNCREATE(CChooseExportPFXFile, CChooseWriteFileName)
  891. CChooseExportPFXFile::CChooseExportPFXFile(CCertificate * pCert)
  892. : CChooseWriteFileName(CChooseExportPFXFile::IDD,
  893. IDS_PFX_FILE_DEFAULT,
  894. IDS_PFX_FILE_EXT,
  895. IDS_PFX_FILE_FILTER,
  896. &pCert->m_KeyFileName,
  897. pCert->m_WebSiteInstanceName
  898. ),
  899. m_pCert(pCert)
  900. {
  901. //{{AFX_DATA_INIT(CChooseExportPFXFile)
  902. //}}AFX_DATA_INIT
  903. }
  904. CChooseExportPFXFile::~CChooseExportPFXFile()
  905. {
  906. }
  907. void CChooseExportPFXFile::DoDataExchange(CDataExchange* pDX)
  908. {
  909. CChooseWriteFileName::DoDataExchange(pDX);
  910. //{{AFX_DATA_MAP(CChooseExportPFXFile)
  911. //}}AFX_DATA_MAP
  912. }
  913. LRESULT
  914. CChooseExportPFXFile::OnWizardBack()
  915. {
  916. return IDD_PAGE_PREV;
  917. }
  918. LRESULT
  919. CChooseExportPFXFile::OnWizardNext()
  920. {
  921. if (CChooseWriteFileName::OnWizardNext() != 1)
  922. return IDD_PAGE_NEXT;
  923. return 1;
  924. }
  925. BEGIN_MESSAGE_MAP(CChooseExportPFXFile, CChooseWriteFileName)
  926. //{{AFX_MSG_MAP(CChooseExportPFXFile)
  927. //}}AFX_MSG_MAP
  928. END_MESSAGE_MAP()