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.

197 lines
4.4 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation 1996-2001.
  5. //
  6. // File: newprof.cpp
  7. //
  8. // Contents: implementation of CNewProfile
  9. //
  10. //----------------------------------------------------------------------------
  11. #include "stdafx.h"
  12. #include "wsecmgr.h"
  13. #include "cookie.h"
  14. #include "snapmgr.h"
  15. #include "NewProf.h"
  16. #include "util.h"
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CNewProfile dialog
  24. CNewProfile::CNewProfile(CWnd* pParent /*=NULL*/)
  25. : CHelpDialog(a225HelpIDs, IDD, pParent)
  26. {
  27. //{{AFX_DATA_INIT(CNewProfile)
  28. m_strNewFile = _T("");
  29. m_strDescription = _T("");
  30. //}}AFX_DATA_INIT
  31. }
  32. void CNewProfile::DoDataExchange(CDataExchange* pDX)
  33. {
  34. CDialog::DoDataExchange(pDX);
  35. //{{AFX_DATA_MAP(CNewProfile)
  36. DDX_Control(pDX, IDOK, m_btnOK);
  37. DDX_Text(pDX, IDC_CONFIG_NAME, m_strNewFile);
  38. DDX_Text(pDX, IDC_DESCRIPTION, m_strDescription);
  39. //}}AFX_DATA_MAP
  40. }
  41. BEGIN_MESSAGE_MAP(CNewProfile, CHelpDialog)
  42. //{{AFX_MSG_MAP(CNewProfile)
  43. ON_EN_CHANGE(IDC_CONFIG_NAME, OnChangeConfigName)
  44. //}}AFX_MSG_MAP
  45. END_MESSAGE_MAP()
  46. void CNewProfile::Initialize(CFolder *pFolder, CComponentDataImpl *pCDI) {
  47. m_pFolder = pFolder;
  48. m_pCDI = pCDI;
  49. m_strDescription.Empty();
  50. m_strNewFile.Empty(); //Raid #401939.
  51. }
  52. /////////////////////////////////////////////////////////////////////////////
  53. // CNewProfile message handlers
  54. void CNewProfile::OnChangeConfigName()
  55. {
  56. UpdateData(TRUE);
  57. m_btnOK.EnableWindow(!m_strNewFile.IsEmpty());
  58. }
  59. void CNewProfile::OnOK()
  60. {
  61. CString strExt;
  62. CString strFile;
  63. int i = 0;
  64. UpdateData(TRUE);
  65. //
  66. // Make sure the file name is correct.
  67. //
  68. i = m_strNewFile.ReverseFind( L'.' );
  69. if ( i >= 0 ) {
  70. //
  71. // If they provided an extension then replace it
  72. //
  73. strFile = m_strNewFile.Left(i);
  74. } else {
  75. //
  76. // Otherwise add our own
  77. //
  78. strFile = m_strNewFile;
  79. }
  80. strExt.LoadString(IDS_PROFILE_DEF_EXT);
  81. strExt = strFile + TEXT(".") + strExt;
  82. strFile = m_pFolder->GetName();
  83. strFile += TEXT("\\") + strExt;
  84. CString strMsg;
  85. //
  86. // Make sure we can create the file
  87. //
  88. HANDLE hFile;
  89. hFile = ExpandAndCreateFile(
  90. strFile,
  91. GENERIC_WRITE,
  92. 0,
  93. NULL,
  94. CREATE_NEW,
  95. FILE_ATTRIBUTE_ARCHIVE,
  96. NULL
  97. );
  98. if (hFile == INVALID_HANDLE_VALUE) {
  99. LPTSTR pszErr;
  100. CString strMsg;
  101. FormatMessage(
  102. FORMAT_MESSAGE_ALLOCATE_BUFFER |
  103. FORMAT_MESSAGE_FROM_SYSTEM,
  104. NULL,
  105. GetLastError(),
  106. 0,
  107. (LPTSTR)&pszErr,
  108. 0,
  109. NULL
  110. );
  111. strMsg = pszErr + strFile;
  112. AfxMessageBox(strMsg, MB_OK);
  113. strFile.Empty();
  114. return;
  115. } else {
  116. //
  117. // Successfully Created the File
  118. //
  119. if (hFile) {
  120. ::CloseHandle( hFile );
  121. }
  122. //
  123. // Delete it so we can create a new one in its place
  124. //
  125. DeleteFile( strFile );
  126. CreateNewProfile(strFile);
  127. LPNOTIFY pNotifier = NULL;
  128. if (m_pCDI) {
  129. pNotifier = m_pCDI->GetNotifier();
  130. }
  131. //
  132. // Save the description in the template
  133. //
  134. if (!m_strDescription.IsEmpty()) {
  135. CEditTemplate *pet;
  136. if (m_pCDI) {
  137. pet = m_pCDI->GetTemplate(strFile);
  138. if (pet) {
  139. pet->SetDescription(m_strDescription);
  140. pet->Save();
  141. }
  142. }
  143. }
  144. if( LOCATIONS == m_pFolder->GetType() && !m_pFolder->IsEnumerated() ) //Raid #191582, 4/26/2001
  145. {
  146. DestroyWindow();
  147. return;
  148. }
  149. if (pNotifier) {
  150. pNotifier->ReloadLocation(m_pFolder,m_pCDI);
  151. }
  152. }
  153. DestroyWindow();
  154. }
  155. BOOL CNewProfile::OnInitDialog()
  156. {
  157. CDialog::OnInitDialog();
  158. m_btnOK.EnableWindow(!m_strNewFile.IsEmpty());
  159. return TRUE; // return TRUE unless you set the focus to a control
  160. // EXCEPTION: OCX Property Pages should return FALSE
  161. }
  162. void CNewProfile::OnCancel()
  163. {
  164. DestroyWindow();
  165. }