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.

269 lines
7.2 KiB

  1. #include "stdafx.h"
  2. #include "WizardSheet.h"
  3. #include "UIUtils.h"
  4. // Valid indexees for the different options in OptNames, OptValues
  5. enum OptIndex
  6. {
  7. optInherited = 0,
  8. optContent,
  9. optCert,
  10. optReuseCerts,
  11. optPostProcess,
  12. optACLs,
  13. optPurgeOld,
  14. OptCount
  15. };
  16. static bool CImportOptions::* OptValues[ OptCount ] = { &CImportOptions::m_bImportInherited,
  17. &CImportOptions::m_bImportContent,
  18. &CImportOptions::m_bImportCert,
  19. &CImportOptions::m_bReuseCerts,
  20. &CImportOptions::m_bPerformPostProcess,
  21. &CImportOptions::m_bApplyACLs,
  22. &CImportOptions::m_bPurgeOldData };
  23. CImportOptions::CImportOptions( CWizardSheet* pTheSheet ) :
  24. m_pTheSheet( pTheSheet )
  25. {
  26. m_strTitle.LoadString( IDS_TITLE_IMPOPT );
  27. m_strSubTitle.LoadString( IDS_SUBTITLE_IMPOPT );
  28. SetHeaderTitle( m_strTitle );
  29. SetHeaderSubTitle( m_strSubTitle );
  30. }
  31. LRESULT CImportOptions::OnInitDialog( UINT, WPARAM, LPARAM, BOOL& )
  32. {
  33. Edit_LimitText( GetDlgItem( IDC_PATH ), MAX_PATH );
  34. // Enable auto complete for the filename control
  35. m_pTheSheet->SetAutocomplete( GetDlgItem( IDC_PATH ), SHACF_FILESYSTEM );
  36. m_Options = GetDlgItem( IDC_OPTIONS );
  37. CRect rectOpt;
  38. ::GetClientRect( m_Options.m_hWnd, &rectOpt );
  39. m_Options.InsertColumn( 0, NULL, LVCFMT_LEFT, rectOpt.Width(), 0);
  40. m_Options.SetExtendedListViewStyle( LVS_EX_CHECKBOXES );
  41. return 1;
  42. }
  43. LRESULT CImportOptions::OnBrowse( WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/ )
  44. {
  45. CString strTitle;
  46. strTitle.LoadString( IDS_MSG_WEBROOT );
  47. CFolderDialog dlg( m_hWnd, strTitle );
  48. if ( dlg.DoModal() == IDOK )
  49. {
  50. VERIFY( SetDlgItemText( IDC_PATH, dlg.m_szFolderPath ) );
  51. }
  52. return 0;
  53. }
  54. LRESULT CImportOptions::OnCustomPath( WORD /*wNotifyCode*/, WORD /*wID*/, HWND hWndCtl, BOOL& /*bHandled*/ )
  55. {
  56. BOOL bCustomEnabled = Button_GetCheck( hWndCtl );
  57. ::EnableWindow( GetDlgItem( IDC_PATH ), bCustomEnabled );
  58. ::EnableWindow( GetDlgItem( IDC_BROWSE ), bCustomEnabled );
  59. ::EnableWindow( GetDlgItem( IDC_PATHLABEL ), bCustomEnabled );
  60. return 0;
  61. }
  62. BOOL CImportOptions::OnSetActive()
  63. {
  64. SetWizardButtons( PSWIZB_NEXT | PSWIZB_BACK );
  65. SetupOptions();
  66. return TRUE;
  67. }
  68. int CImportOptions::OnWizardNext()
  69. {
  70. bool bContinue = true;
  71. if ( Button_GetCheck( GetDlgItem( IDC_CUSTOMPATH ) ) )
  72. {
  73. m_bUseCustomPath = true;
  74. GetDlgItemText( IDC_PATH, m_strCustomPath.GetBuffer( MAX_PATH + 1 ), MAX_PATH );
  75. m_strCustomPath.ReleaseBuffer();
  76. bContinue = VerifyCustomPath();
  77. }
  78. else
  79. {
  80. m_bUseCustomPath = false;
  81. m_strCustomPath.Empty();
  82. }
  83. // Parse the options
  84. if ( bContinue )
  85. {
  86. ParseSelectedOptions();
  87. }
  88. return bContinue ? 0 : -1;
  89. }
  90. void CImportOptions::SetupOptions()
  91. {
  92. int nIndex = 0;
  93. VARIANT_BOOL vbFlag = VARIANT_FALSE;
  94. IImportPackagePtr spImport;
  95. ISiteInfoPtr spInfo;
  96. VERIFY( m_Options.DeleteAllItems() );
  97. // The "import inherited" and "PurgeOldData" always exists
  98. CString strOptName;
  99. VERIFY( strOptName.LoadString( IDS_IMPOPT_INHERITED ) );
  100. nIndex = m_Options.InsertItem( 0, strOptName, 0 );
  101. m_Options.SetItemData( nIndex, optInherited );
  102. VERIFY( strOptName.LoadString( IDS_IMPOPT_PURGEOLDDATA ) );
  103. nIndex = m_Options.InsertItem( 0, strOptName, 0 );
  104. m_Options.SetItemData( nIndex, optPurgeOld );
  105. HRESULT hr = spImport.CreateInstance( CLSID_ImportPackage );
  106. if ( SUCCEEDED( hr ) )
  107. {
  108. CComBSTR bstrPkg( m_pTheSheet->m_pageLoadPkg.m_strFilename );
  109. CComBSTR bstrPwd( m_pTheSheet->m_pageLoadPkg.m_strPassword );
  110. if ( ( NULL != bstrPkg.m_str ) && ( NULL != bstrPwd.m_str ) )
  111. {
  112. hr = spImport->LoadPackage( bstrPkg, bstrPwd );
  113. }
  114. }
  115. if ( SUCCEEDED( hr ) )
  116. {
  117. hr = spImport->GetSiteInfo( 0, &spInfo );
  118. }
  119. if ( SUCCEEDED( hr ) )
  120. {
  121. hr = spInfo->get_ContentIncluded( &vbFlag );
  122. if ( SUCCEEDED( hr ) && ( vbFlag != VARIANT_FALSE ) )
  123. {
  124. VERIFY( strOptName.LoadString( IDS_IMPOPT_CONTENT ) );
  125. nIndex = m_Options.InsertItem( 0, strOptName, 0 );
  126. m_Options.SetItemData( nIndex, optContent );
  127. }
  128. }
  129. if ( SUCCEEDED( hr ) )
  130. {
  131. hr = spInfo->get_ACLsIncluded( &vbFlag );
  132. if ( SUCCEEDED( hr ) && ( vbFlag != VARIANT_FALSE ) )
  133. {
  134. VERIFY( strOptName.LoadString( IDS_IMPOPT_APPLYACLS ) );
  135. nIndex = m_Options.InsertItem( 0, strOptName, 0 );
  136. m_Options.SetItemData( nIndex, optACLs );
  137. }
  138. }
  139. if ( SUCCEEDED( hr ) )
  140. {
  141. hr = spInfo->get_HaveCommands( &vbFlag );
  142. if ( SUCCEEDED( hr ) && ( vbFlag != VARIANT_FALSE ) )
  143. {
  144. VERIFY( strOptName.LoadString( IDS_IMPOPT_DOPOSTPROCESS ) );
  145. nIndex = m_Options.InsertItem( 0, strOptName, 0 );
  146. m_Options.SetItemData( nIndex, optPostProcess );
  147. }
  148. }
  149. if ( SUCCEEDED( hr ) )
  150. {
  151. hr = spInfo->get_HaveCertificates( &vbFlag );
  152. if ( SUCCEEDED( hr ) && ( vbFlag != VARIANT_FALSE ) )
  153. {
  154. VERIFY( strOptName.LoadString( IDS_IMPOPT_CERT ) );
  155. nIndex = m_Options.InsertItem( 0, strOptName, 0 );
  156. m_Options.SetItemData( nIndex, optCert );
  157. VERIFY( strOptName.LoadString( IDS_IMPOPT_REUSECERTS ) );
  158. nIndex = m_Options.InsertItem( 0, strOptName, 0 );
  159. m_Options.SetItemData( nIndex, optReuseCerts );
  160. }
  161. }
  162. if ( FAILED( hr ) )
  163. {
  164. m_Options.DeleteAllItems();
  165. UIUtils::ShowCOMError( m_hWnd, IDS_E_LOAD_PKG, IDS_APPTITLE, hr );
  166. SetWizardButtons( PSWIZB_BACK );
  167. }
  168. }
  169. void CImportOptions::ParseSelectedOptions()
  170. {
  171. for ( int i = 0; i < OptCount; ++i )
  172. {
  173. this->*OptValues[ i ] = false;
  174. }
  175. for ( int i = 0; i < m_Options.GetItemCount(); ++i )
  176. {
  177. OptIndex Index = static_cast<OptIndex>( m_Options.GetItemData( i ) );
  178. this->*OptValues[ Index ] = m_Options.GetCheckState( i ) != FALSE;
  179. }
  180. }
  181. bool CImportOptions::VerifyCustomPath()
  182. {
  183. // Check that this is a path
  184. if ( !::PathIsDirectoryW( m_strCustomPath ) )
  185. {
  186. UIUtils::MessageBox( m_hWnd, IDS_E_CUSTOMPATH_INVALID, IDS_APPTITLE, MB_OK | MB_ICONSTOP );
  187. return false;
  188. }
  189. // Check if it is empty
  190. if ( !::PathIsDirectoryEmptyW( m_strCustomPath ) )
  191. {
  192. int nRes = UIUtils::MessageBox( m_hWnd, IDS_W_CUSTOMPATH_NOTEMPTY, IDS_APPTITLE, MB_YESNO | MB_ICONWARNING );
  193. if ( nRes == IDNO ) return false;
  194. }
  195. return true;
  196. }