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.

189 lines
5.1 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation 1996-2001.
  5. //
  6. // File: locdesc.cpp
  7. //
  8. // Contents: implementation of CSetLocationDescription
  9. //
  10. //----------------------------------------------------------------------------
  11. #include "stdafx.h"
  12. #include "wsecmgr.h"
  13. #include "snapmgr.h"
  14. #include "cookie.h"
  15. #include "LocDesc.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. // CSetLocationDescription dialog
  24. CSetLocationDescription::CSetLocationDescription(CWnd* pParent /*=NULL*/)
  25. : CHelpDialog(a218HelpIDs, IDD, pParent)
  26. {
  27. //{{AFX_DATA_INIT(CSetLocationDescription)
  28. m_strDesc = _T("");
  29. //}}AFX_DATA_INIT
  30. }
  31. void CSetLocationDescription::DoDataExchange(CDataExchange* pDX)
  32. {
  33. CDialog::DoDataExchange(pDX);
  34. //{{AFX_DATA_MAP(CSetLocationDescription)
  35. DDX_Text(pDX, IDC_DESCRIPTION, m_strDesc);
  36. //}}AFX_DATA_MAP
  37. }
  38. BEGIN_MESSAGE_MAP(CSetLocationDescription, CHelpDialog)
  39. //{{AFX_MSG_MAP(CSetLocationDescription)
  40. //}}AFX_MSG_MAP
  41. END_MESSAGE_MAP()
  42. void CSetLocationDescription::Initialize(CFolder *pFolder, CComponentDataImpl *pCDI) {
  43. m_pFolder = pFolder;
  44. m_pCDI = pCDI;
  45. m_strDesc = pFolder->GetDesc();
  46. }
  47. /////////////////////////////////////////////////////////////////////////////
  48. // CSetLocationDescription message handlers
  49. DWORD
  50. SetDescHelper(HKEY hKey,CFolder *pFolder,CString strDesc) {
  51. DWORD status = RegSetValueEx(hKey,
  52. L"Description", // Value name (not localized)
  53. 0, // Reserved
  54. REG_SZ,
  55. (CONST BYTE *)(LPCTSTR)strDesc,
  56. (strDesc.GetLength()+1)*sizeof(TCHAR));
  57. if (NO_ERROR == status) {
  58. pFolder->SetDesc(strDesc);
  59. } else {
  60. // Couldn't set a value
  61. }
  62. RegCloseKey(hKey);
  63. return status;
  64. }
  65. void CSetLocationDescription::OnOK()
  66. {
  67. DWORD status = 0;
  68. HKEY hKey = 0;
  69. CString strLocKey;
  70. CString strErr;
  71. LPTSTR szName = 0;
  72. LPTSTR sz = 0;
  73. UpdateData(TRUE);
  74. strLocKey.LoadString(IDS_TEMPLATE_LOCATION_KEY);
  75. strLocKey += L'\\';
  76. szName = m_pFolder->GetName();
  77. // replace '\' with '/' because Registry does not
  78. // take '/' in a single key
  79. //
  80. sz = wcschr(szName, L'\\');
  81. while (sz) {
  82. *sz = L'/';
  83. sz = wcschr(sz, L'\\');
  84. }
  85. strLocKey += szName;
  86. if( !m_strDesc.IsEmpty() ) //Raid #482845, Yanggao
  87. {
  88. m_strDesc.Replace(L"\r\n", NULL);
  89. }
  90. PCWSTR szInvalidCharSet = INVALID_DESC_CHARS;
  91. if( m_strDesc.FindOneOf(szInvalidCharSet) != -1 )
  92. {
  93. CString text;
  94. text.FormatMessage (IDS_INVALID_DESC, szInvalidCharSet);
  95. AfxMessageBox(text);
  96. GetDlgItem(IDC_DESCRIPTION)->SetFocus();
  97. return;
  98. }
  99. status = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  100. strLocKey,
  101. 0,
  102. KEY_SET_VALUE,
  103. &hKey);
  104. if (NO_ERROR == status) {
  105. status = SetDescHelper(hKey,m_pFolder,m_strDesc);
  106. } else {
  107. //
  108. // Only display an error if we can read (and thus displayed)
  109. // this key
  110. //
  111. if (NO_ERROR == RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  112. strLocKey,
  113. 0,
  114. KEY_READ,
  115. &hKey)) {
  116. strErr.LoadString(IDS_ERR_GLOBAL_LOC_DESC);
  117. MessageBox(strErr);
  118. RegCloseKey(hKey);
  119. }
  120. }
  121. if (NO_ERROR != status) {
  122. //
  123. // Bug 375324: if we can't succeed under HKLM try under HKCU
  124. //
  125. status = RegOpenKeyEx(HKEY_CURRENT_USER,
  126. strLocKey,
  127. 0,
  128. KEY_SET_VALUE,
  129. &hKey);
  130. if (NO_ERROR == status) {
  131. status = SetDescHelper(hKey,m_pFolder,m_strDesc);
  132. } else {
  133. //
  134. // Only display an error if we can read (and thus displayed)
  135. // this key
  136. //
  137. if (NO_ERROR == RegOpenKeyEx(HKEY_CURRENT_USER,
  138. strLocKey,
  139. 0,
  140. KEY_READ,
  141. &hKey)) {
  142. strErr.LoadString(IDS_ERR_LOCAL_LOC_DESC);
  143. MessageBox(strErr);
  144. RegCloseKey(hKey);
  145. }
  146. }
  147. }
  148. szName = m_pFolder->GetName();
  149. // replace '/' with '\' because Registry does not
  150. sz = wcschr(szName, L'/');
  151. while (sz) {
  152. *sz = L'\\';
  153. sz = wcschr(sz, L'/');
  154. }
  155. LPCONSOLENAMESPACE tempnamespace = m_pCDI->GetNameSpace(); //Raid #252638, 5/2/2001
  156. if( tempnamespace )
  157. {
  158. tempnamespace->SetItem(m_pFolder->GetScopeItem());
  159. }
  160. DestroyWindow();
  161. }
  162. void CSetLocationDescription::OnCancel()
  163. {
  164. DestroyWindow();
  165. }