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.

242 lines
6.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. if( m_strNewFile.Find(L' ') == 0 ) //Raid #477191, yanggao, 11/5/01
  58. {
  59. m_strNewFile.TrimLeft();
  60. GetDlgItem(IDC_CONFIG_NAME)->SetWindowText(m_strNewFile);
  61. }
  62. m_btnOK.EnableWindow(!m_strNewFile.IsEmpty());
  63. }
  64. void CNewProfile::OnOK()
  65. {
  66. CString strExt;
  67. CString strFile;
  68. int i = 0;
  69. UpdateData(TRUE);
  70. //
  71. // Make sure the file name is correct.
  72. //
  73. strExt.LoadString(IDS_PROFILE_DEF_EXT); //Raid #533425, #574018, yanggao, 4/1/2002.
  74. strExt = TEXT(".") + strExt;
  75. //Raid #533432, yanggao, 4/3/2002
  76. if( !IsValidFileName(m_strNewFile) || IsNameReserved(m_strNewFile, strExt) ) //Raid #484084, Yanggao, 12/23/2001
  77. {
  78. CWnd* pwnd = GetDlgItem(IDC_CONFIG_NAME); //Raid #498477, yanggao
  79. if( pwnd )
  80. {
  81. pwnd->SendMessage(EM_SETSEL, (WPARAM)0, (LPARAM)-1);
  82. pwnd->SetFocus();
  83. }
  84. return;
  85. }
  86. i = m_strNewFile.ReverseFind(L'.');
  87. if( i >= 0 && strExt == m_strNewFile.Right(m_strNewFile.GetLength()-i) )
  88. {
  89. //
  90. // If they provided a correct extension then use it
  91. //
  92. strExt = m_strNewFile;
  93. } else {
  94. //
  95. // Otherwise add our own
  96. //
  97. strFile = m_strNewFile;
  98. strExt = strFile + strExt;
  99. }
  100. strFile = m_pFolder->GetName();
  101. if( strExt.GetAt(0) == L'\\' || strExt.GetAt(0) == L'/' ) //Raid #498480, yanggao, 11/21/2001
  102. {
  103. strFile += strExt;
  104. }
  105. else
  106. {
  107. strFile += TEXT("\\") + strExt;
  108. }
  109. //
  110. // Make sure we can create the file
  111. //
  112. HANDLE hFile;
  113. hFile = ExpandAndCreateFile(
  114. strFile,
  115. GENERIC_WRITE,
  116. 0,
  117. NULL,
  118. CREATE_NEW,
  119. FILE_ATTRIBUTE_ARCHIVE,
  120. NULL
  121. );
  122. if (hFile == INVALID_HANDLE_VALUE) {
  123. LPTSTR pszErr;
  124. CString strMsg;
  125. FormatMessage(
  126. FORMAT_MESSAGE_ALLOCATE_BUFFER |
  127. FORMAT_MESSAGE_FROM_SYSTEM,
  128. NULL,
  129. GetLastError(),
  130. 0,
  131. (LPTSTR)&pszErr,
  132. 0,
  133. NULL
  134. );
  135. strMsg = pszErr + strFile;
  136. if( strFile.GetLength() > MAX_PATH ) //Raid 501615, yanggao
  137. {
  138. CString strTemp;
  139. strTemp.LoadString(IDS_PATH_TOO_LONG);
  140. strMsg = strMsg + L"\n" + strTemp;
  141. }
  142. AfxMessageBox(strMsg, MB_OK);
  143. strFile.Empty();
  144. CWnd* pwnd = GetDlgItem(IDC_CONFIG_NAME); //Raid #502392, yanggao
  145. if( pwnd )
  146. {
  147. pwnd->SendMessage(EM_SETSEL, (WPARAM)0, (LPARAM)-1);
  148. pwnd->SetFocus();
  149. }
  150. return;
  151. } else {
  152. //
  153. // Successfully Created the File
  154. //
  155. if (hFile) {
  156. ::CloseHandle( hFile );
  157. }
  158. //
  159. // Delete it so we can create a new one in its place
  160. //
  161. DeleteFile( strFile );
  162. CreateNewProfile(strFile);
  163. LPNOTIFY pNotifier = NULL;
  164. if (m_pCDI) {
  165. pNotifier = m_pCDI->GetNotifier();
  166. }
  167. //
  168. // Save the description in the template
  169. //
  170. if (!m_strDescription.IsEmpty()) {
  171. CEditTemplate *pet;
  172. if (m_pCDI) {
  173. pet = m_pCDI->GetTemplate(strFile);
  174. if (pet) {
  175. pet->SetDescription(m_strDescription);
  176. pet->Save();
  177. }
  178. }
  179. }
  180. if( LOCATIONS == m_pFolder->GetType() && !m_pFolder->IsEnumerated() ) //Raid #191582, 4/26/2001
  181. {
  182. ::EnableWindow(m_pCDI->GetParentWindow(), TRUE); //Raid #492433, yanggao
  183. DestroyWindow();
  184. return;
  185. }
  186. if (pNotifier) {
  187. pNotifier->ReloadLocation(m_pFolder,m_pCDI);
  188. }
  189. }
  190. ::EnableWindow(m_pCDI->GetParentWindow(), TRUE); //Raid #492433, yanggao
  191. DestroyWindow();
  192. }
  193. BOOL CNewProfile::OnInitDialog()
  194. {
  195. CDialog::OnInitDialog();
  196. GetDlgItem(IDC_CONFIG_NAME)->SendMessage(EM_LIMITTEXT, MAX_PATH, 0); //Raid #481595, Yanggao, 10/17/2001
  197. GetDlgItem(IDC_DESCRIPTION)->SendMessage(EM_LIMITTEXT, MAX_PATH, 0); //Raid #525155, Yanggao, 2/28/2002
  198. m_btnOK.EnableWindow(!m_strNewFile.IsEmpty());
  199. ::EnableWindow(m_pCDI->GetParentWindow(), FALSE); //Raid #492433, yanggao, avoid closing snapin window.
  200. return TRUE; // return TRUE unless you set the focus to a control
  201. // EXCEPTION: OCX Property Pages should return FALSE
  202. }
  203. void CNewProfile::OnCancel()
  204. {
  205. ::EnableWindow(m_pCDI->GetParentWindow(), TRUE); //Raid #492433, yanggao
  206. DestroyWindow();
  207. }