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.

129 lines
3.7 KiB

  1. #include "StdAfx.h"
  2. #include "WizardSheet.h"
  3. #include "UIUtils.h"
  4. CLoadPackage::CLoadPackage( CWizardSheet* pTheSheet ) :
  5. m_pTheSheet( pTheSheet )
  6. {
  7. m_strTitle.LoadString( IDS_TITLE_LOADPKG );
  8. m_strSubTitle.LoadString( IDS_SUBTITLE_LOADPKG );
  9. SetHeaderTitle( m_strTitle );
  10. SetHeaderSubTitle( m_strSubTitle );
  11. }
  12. BOOL CLoadPackage::OnSetActive()
  13. {
  14. bool bHavePwd = m_editPwd.GetWindowTextLength() > 0;
  15. bool bHaveName= m_editPkgName.GetWindowTextLength() > 0;
  16. SetWizardButtons( PSWIZB_BACK | ( bHaveName && bHavePwd ? PSWIZB_NEXT : 0 ) );
  17. return TRUE;
  18. }
  19. LRESULT CLoadPackage::OnInitDialog( UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/ )
  20. {
  21. Edit_LimitText( GetDlgItem( IDC_PWD ), CPackageConfig::MAX_PWD_LEN );
  22. Edit_LimitText( GetDlgItem( IDC_PKGNAME ), MAX_PATH );
  23. // Enable autocomplete
  24. m_pTheSheet->SetAutocomplete( GetDlgItem( IDC_PKGNAME ), SHACF_FILESYSTEM );
  25. m_editPwd = GetDlgItem( IDC_PWD );
  26. m_editPkgName = GetDlgItem( IDC_PKGNAME );
  27. return 1;
  28. }
  29. LRESULT CLoadPackage::OnBrowse( WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/ )
  30. {
  31. CString strFilter;
  32. UIUtils::LoadOFNFilterFromRes( IDS_FILTER_PACKAGE, /*r*/strFilter );
  33. CFileDialog dlg( TRUE,
  34. NULL,
  35. NULL,
  36. OFN_ENABLESIZING | OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY,
  37. strFilter,
  38. m_hWnd );
  39. if ( dlg.DoModal() == IDCANCEL ) return 0;
  40. VERIFY( SetDlgItemText( IDC_PKGNAME, dlg.m_szFileName ) );
  41. return 0;
  42. }
  43. int CLoadPackage::OnWizardNext()
  44. {
  45. GetDlgItemText( IDC_PKGNAME, m_strFilename.GetBuffer( MAX_PATH + 1 ), MAX_PATH );
  46. GetDlgItemText( IDC_PWD, m_strPassword.GetBuffer( CPackageConfig::MAX_PWD_LEN + 1 ), CPackageConfig::MAX_PWD_LEN );
  47. m_strFilename.ReleaseBuffer();
  48. m_strPassword.ReleaseBuffer();
  49. TFileHandle shFile( ::CreateFile( m_strFilename,
  50. GENERIC_READ,
  51. 0,
  52. NULL,
  53. OPEN_EXISTING,
  54. FILE_ATTRIBUTE_NORMAL,
  55. NULL ) );
  56. // Check the existance only. Other errors will be handled by the engine
  57. if ( !shFile.IsValid() && ( ::GetLastError() == ERROR_FILE_NOT_FOUND ) )
  58. {
  59. UIUtils::MessageBox( m_hWnd, IDC_PKGFILE_NOTFOUND, IDS_APPTITLE, MB_OK | MB_ICONSTOP );
  60. m_editPkgName.SetFocus();
  61. return -1;
  62. }
  63. shFile.Close();
  64. // Check if we can load the package
  65. IImportPackagePtr spImport;
  66. HRESULT hr = spImport.CreateInstance( CLSID_ImportPackage );
  67. if ( SUCCEEDED( hr ) )
  68. {
  69. CComBSTR bstrPkg( m_pTheSheet->m_pageLoadPkg.m_strFilename );
  70. CComBSTR bstrPwd( m_pTheSheet->m_pageLoadPkg.m_strPassword );
  71. if ( ( NULL != bstrPkg.m_str ) && ( NULL != bstrPwd.m_str ) )
  72. {
  73. hr = spImport->LoadPackage( bstrPkg, bstrPwd );
  74. }
  75. }
  76. if ( FAILED( hr ) )
  77. {
  78. UIUtils::ShowCOMError( m_hWnd, IDS_E_LOAD_PKG, IDS_APPTITLE, hr );
  79. return -1;
  80. }
  81. return 0;
  82. }
  83. LRESULT CLoadPackage::OnEditChange( WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/ )
  84. {
  85. bool bHavePwd = m_editPwd.GetWindowTextLength() > 0;
  86. bool bHaveName= m_editPkgName.GetWindowTextLength() > 0;
  87. SetWizardButtons( PSWIZB_BACK | ( bHaveName && bHavePwd ? PSWIZB_NEXT : 0 ) );
  88. return 0;
  89. }
  90. int CLoadPackage::OnWizardBack()
  91. {
  92. return IDD_WP_IMPORTOREXPORT;
  93. }