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.

396 lines
10 KiB

  1. // svcprop1.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "compdata.h"
  5. #include "resource.h"
  6. #include "shrprop.h"
  7. #include "filesvc.h"
  8. #include "dataobj.h" // CFileMgmtDataObject::m_CFMachineName
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CSharePage property page
  16. IMPLEMENT_DYNCREATE(CSharePage, CPropertyPage)
  17. CSharePage::CSharePage(UINT nIDTemplate) :
  18. CPropertyPage(nIDTemplate ? nIDTemplate : CSharePageGeneral::IDD),
  19. m_pFileMgmtData( NULL ),
  20. m_transport( FILEMGMT_OTHER ),
  21. m_refcount( 1 ), // number of pages
  22. m_handle (0),
  23. m_pDataObject (0),
  24. m_bChanged (FALSE)
  25. {
  26. }
  27. CSharePage::~CSharePage()
  28. {
  29. if (NULL != m_pFileMgmtData)
  30. {
  31. ((IComponentData*)m_pFileMgmtData)->Release();
  32. m_pFileMgmtData = NULL;
  33. }
  34. if ( m_pDataObject )
  35. m_pDataObject->Release ();
  36. if ( m_handle )
  37. {
  38. ::MMCFreeNotifyHandle (m_handle);
  39. m_handle = NULL;
  40. }
  41. }
  42. BOOL CSharePage::Load( CFileMgmtComponentData* pFileMgmtData, LPDATAOBJECT piDataObject )
  43. {
  44. ASSERT( NULL == m_pFileMgmtData && NULL != pFileMgmtData && NULL != piDataObject );
  45. if ( !pFileMgmtData || !piDataObject )
  46. return FALSE;
  47. m_pDataObject = piDataObject;
  48. m_pDataObject->AddRef ();
  49. m_pFileMgmtData = pFileMgmtData;
  50. ((IComponentData*)m_pFileMgmtData)->AddRef();
  51. HRESULT hr = ExtractString( piDataObject, CFileMgmtDataObject::m_CFMachineName, &m_strMachineName, MAX_PATH );
  52. if ( FAILED(hr) )
  53. {
  54. ASSERT( FALSE );
  55. return FALSE;
  56. }
  57. if (m_strMachineName.IsEmpty())
  58. {
  59. // local computer
  60. TCHAR achComputerName[ MAX_COMPUTERNAME_LENGTH+1 ];
  61. DWORD dwSize = sizeof(achComputerName)/sizeof(TCHAR);
  62. GetComputerName( achComputerName, &dwSize );
  63. m_strMachineName = achComputerName;
  64. }
  65. hr = ExtractString( piDataObject, CFileMgmtDataObject::m_CFShareName, &m_strShareName, MAX_PATH );
  66. if ( FAILED(hr) )
  67. {
  68. ASSERT( FALSE );
  69. return FALSE;
  70. }
  71. hr = ExtractData( piDataObject,
  72. CFileMgmtDataObject::m_CFTransport,
  73. &m_transport,
  74. sizeof(DWORD) );
  75. if ( FAILED(hr) )
  76. {
  77. ASSERT( FALSE );
  78. return FALSE;
  79. }
  80. return TRUE;
  81. }
  82. void CSharePage::DoDataExchange(CDataExchange* pDX)
  83. {
  84. CPropertyPage::DoDataExchange(pDX);
  85. //{{AFX_DATA_MAP(CSharePage)
  86. //}}AFX_DATA_MAP
  87. } // CSharePage::DoDataExchange()
  88. BEGIN_MESSAGE_MAP(CSharePage, CPropertyPage)
  89. //{{AFX_MSG_MAP(CSharePage)
  90. //}}AFX_MSG_MAP
  91. END_MESSAGE_MAP()
  92. /////////////////////////////////////////////////////////////////////////////
  93. // CSharePage message handlers
  94. BOOL CSharePage::OnApply()
  95. {
  96. if ( IsModified () )
  97. {
  98. m_pDataObject->AddRef ();
  99. HRESULT hr = MMCPropertyChangeNotify (m_handle, reinterpret_cast <LONG_PTR>(m_pDataObject));
  100. ASSERT (SUCCEEDED (hr));
  101. if ( !SUCCEEDED (hr) )
  102. m_pDataObject->Release (); // released in OnPropertyChange () if successful
  103. }
  104. BOOL bResult = CPropertyPage::OnApply();
  105. if ( bResult )
  106. m_bChanged = FALSE;
  107. return bResult;
  108. }
  109. // This mechanism deletes the CFileMgmtGeneral when the property sheet is finished
  110. UINT CALLBACK CSharePage::PropSheetPageProc(
  111. HWND hwnd,
  112. UINT uMsg,
  113. LPPROPSHEETPAGE ppsp )
  114. {
  115. CSharePage* pThis = reinterpret_cast<CSharePage*>(ppsp->lParam);
  116. switch (uMsg)
  117. {
  118. case PSPCB_RELEASE:
  119. if (--(pThis->m_refcount) <= 0)
  120. {
  121. // Remember callback on stack since "this" will be deleted
  122. LPFNPSPCALLBACK pfnOrig = pThis->m_pfnOriginalPropSheetPageProc;
  123. delete pThis;
  124. return (pfnOrig)(hwnd,uMsg,ppsp);
  125. }
  126. break;
  127. case PSPCB_CREATE:
  128. // do not increase refcount, PSPCB_CREATE may or may not be called
  129. // depending on whether the page was created. PSPCB_RELEASE can be
  130. // depended upon to be called exactly once per page however.
  131. // fall through
  132. default:
  133. break;
  134. }
  135. return (pThis->m_pfnOriginalPropSheetPageProc)(hwnd,uMsg,ppsp);
  136. }
  137. void CSharePage::SetModified(BOOL bChanged)
  138. {
  139. m_bChanged = bChanged;
  140. CPropertyPage::SetModified (bChanged);
  141. }
  142. BOOL CSharePage::IsModified() const
  143. {
  144. return m_bChanged;
  145. }
  146. /////////////////////////////////////////////////////////////////////////////
  147. // CSharePageGeneral property page
  148. IMPLEMENT_DYNCREATE(CSharePageGeneral, CSharePage)
  149. CSharePageGeneral::CSharePageGeneral(UINT nIDTemplate) :
  150. CSharePage(nIDTemplate ? nIDTemplate : CSharePageGeneral::IDD),
  151. m_pvPropertyBlock( NULL ),
  152. m_fEnableDescription( TRUE ),
  153. m_fEnablePath( TRUE ),
  154. m_dwShareType(0)
  155. {
  156. //{{AFX_DATA_INIT(CSharePageGeneral)
  157. m_strShareName = _T("");
  158. m_strPath = _T("");
  159. m_strDescription = _T("");
  160. m_iMaxUsersAllowed = -1;
  161. m_dwMaxUsers = 0;
  162. //}}AFX_DATA_INIT
  163. }
  164. CSharePageGeneral::~CSharePageGeneral()
  165. {
  166. if (NULL != m_pvPropertyBlock)
  167. {
  168. ASSERT( NULL != m_pFileMgmtData && FILEMGMT_OTHER != m_transport );
  169. m_pFileMgmtData->GetFileServiceProvider(m_transport)->FreeData(m_pvPropertyBlock);
  170. }
  171. }
  172. BOOL CSharePageGeneral::Load( CFileMgmtComponentData* pFileMgmtData, LPDATAOBJECT piDataObject )
  173. {
  174. if (FALSE == CSharePage::Load(pFileMgmtData, piDataObject))
  175. return FALSE;
  176. BOOL fEditDescription = TRUE;
  177. BOOL fEditPath = TRUE;
  178. NET_API_STATUS retval =
  179. m_pFileMgmtData->GetFileServiceProvider(m_transport)->ReadShareProperties(
  180. m_strMachineName,
  181. m_strShareName,
  182. &m_pvPropertyBlock,
  183. m_strDescription,
  184. m_strPath,
  185. &m_fEnableDescription,
  186. &m_fEnablePath,
  187. &m_dwShareType);
  188. if (0L != retval)
  189. {
  190. (void) DoErrMsgBox(m_hWnd, MB_OK | MB_ICONSTOP, retval, IDS_POPUP_QUERY_SHARE, m_strShareName );
  191. return FALSE;
  192. }
  193. m_dwMaxUsers = m_pFileMgmtData->GetFileServiceProvider(
  194. m_transport)->QueryMaxUsers(m_pvPropertyBlock);
  195. if ((DWORD)-1 == m_dwMaxUsers)
  196. {
  197. m_iMaxUsersAllowed = 0;
  198. m_dwMaxUsers = 1;
  199. }
  200. else
  201. {
  202. m_iMaxUsersAllowed = 1;
  203. }
  204. return TRUE;
  205. }
  206. #define SHARE_DESCRIPTION_LIMIT MAXCOMMENTSZ
  207. #define MYUD_MAXVAL32 0x7FFFFFFF
  208. void CSharePageGeneral::DoDataExchange(CDataExchange* pDX)
  209. {
  210. CSharePage::DoDataExchange(pDX);
  211. //{{AFX_DATA_MAP(CSharePageGeneral)
  212. DDX_Control(pDX, IDC_SHRPROP_SPIN_USERS, m_spinMaxUsers);
  213. DDX_Control(pDX, IDC_EDIT_SHARE_NAME, m_editShareName);
  214. DDX_Control(pDX, IDC_EDIT_PATH_NAME, m_editPath);
  215. DDX_Control(pDX, IDC_EDIT_DESCRIPTION, m_editDescription);
  216. DDX_Control(pDX, IDC_SHRPROP_ALLOW_SPECIFIC, m_checkboxAllowSpecific);
  217. DDX_Control(pDX, IDC_SHRPROP_MAX_ALLOWED, m_checkBoxMaxAllowed);
  218. DDX_Text(pDX, IDC_EDIT_SHARE_NAME, m_strShareName);
  219. DDX_Text(pDX, IDC_EDIT_PATH_NAME, m_strPath);
  220. DDX_Text(pDX, IDC_EDIT_DESCRIPTION, m_strDescription);
  221. DDV_MaxChars(pDX, m_strDescription, SHARE_DESCRIPTION_LIMIT);
  222. DDX_Radio(pDX, IDC_SHRPROP_MAX_ALLOWED, m_iMaxUsersAllowed);
  223. DDX_Text(pDX, IDC_SHRPROP_EDIT_USERS, m_dwMaxUsers);
  224. DDV_MinMaxDWord(pDX, m_dwMaxUsers, 1, MYUD_MAXVAL32);
  225. //}}AFX_DATA_MAP
  226. if ( !pDX->m_bSaveAndValidate )
  227. {
  228. m_spinMaxUsers.SendMessage(UDM_SETRANGE32, 1, MYUD_MAXVAL32);
  229. if (0 == m_iMaxUsersAllowed)
  230. {
  231. GetDlgItem(IDC_SHRPROP_EDIT_USERS)->EnableWindow(FALSE);
  232. GetDlgItem(IDC_SHRPROP_SPIN_USERS)->EnableWindow(FALSE);
  233. }
  234. if ( !m_fEnableDescription ) {
  235. // m_staticDescription.SetWindowText(m_strDescription);
  236. // m_staticDescription.EnableWindow();
  237. // m_staticDescription.ShowWindow(SW_SHOW);
  238. m_editDescription.EnableWindow(FALSE);
  239. m_editDescription.ShowWindow(SW_HIDE);
  240. GetDlgItem(IDC_STATIC_COMMENT_STATIC)->EnableWindow(FALSE);
  241. GetDlgItem(IDC_STATIC_COMMENT_STATIC)->ShowWindow(SW_HIDE);
  242. // make read-only
  243. // m_editDescription.SetReadOnly(TRUE);
  244. }
  245. if ( m_fEnablePath ) {
  246. // m_staticPath.EnableWindow(FALSE);
  247. // m_staticPath.ShowWindow(SW_HIDE);
  248. // m_editPath.EnableWindow();
  249. // m_editPath.ShowWindow(SW_SHOW);
  250. // make read-write
  251. m_editPath.SetReadOnly(FALSE);
  252. }
  253. else {
  254. // m_staticPath.SetWindowText(m_strPath);
  255. // leave read-only
  256. }
  257. }
  258. } // CSharePageGeneral::DoDataExchange()
  259. BEGIN_MESSAGE_MAP(CSharePageGeneral, CSharePage)
  260. //{{AFX_MSG_MAP(CSharePageGeneral)
  261. ON_MESSAGE(WM_HELP, OnHelp)
  262. ON_MESSAGE(WM_CONTEXTMENU, OnContextHelp)
  263. ON_EN_CHANGE(IDC_EDIT_PATH_NAME, OnChangeEditPathName)
  264. ON_EN_CHANGE(IDC_EDIT_DESCRIPTION, OnChangeEditDescription)
  265. ON_EN_CHANGE(IDC_EDIT_SHARE_NAME, OnChangeEditShareName)
  266. ON_BN_CLICKED(IDC_SHRPROP_ALLOW_SPECIFIC, OnShrpropAllowSpecific)
  267. ON_BN_CLICKED(IDC_SHRPROP_MAX_ALLOWED, OnShrpropMaxAllowed)
  268. ON_EN_CHANGE(IDC_SHRPROP_EDIT_USERS, OnChangeShrpropEditUsers)
  269. //}}AFX_MSG_MAP
  270. END_MESSAGE_MAP()
  271. /////////////////////////////////////////////////////////////////////////////
  272. // CSharePageGeneral message handlers
  273. /////////////////////////////////////////////////////////////////////
  274. // Help
  275. BOOL CSharePageGeneral::OnHelp(WPARAM /*wParam*/, LPARAM lParam)
  276. {
  277. return DoHelp(lParam, HELP_DIALOG_TOPIC(IDD_SHAREPROP_GENERAL));
  278. }
  279. BOOL CSharePageGeneral::OnContextHelp(WPARAM wParam, LPARAM /*lParam*/)
  280. {
  281. return DoContextHelp(wParam, HELP_DIALOG_TOPIC(IDD_SHAREPROP_GENERAL));
  282. }
  283. BOOL CSharePageGeneral::OnApply()
  284. {
  285. if ( IsModified () )
  286. {
  287. ASSERT(NULL != m_pFileMgmtData);
  288. // UpdateData (TRUE) has already been called by OnKillActive () just before OnApply ()
  289. DWORD dwMaxUsers = (0 == m_iMaxUsersAllowed) ? (DWORD)-1 : m_dwMaxUsers;
  290. m_pFileMgmtData->GetFileServiceProvider(
  291. m_transport)->SetMaxUsers(m_pvPropertyBlock,dwMaxUsers);
  292. NET_API_STATUS retval =
  293. m_pFileMgmtData->GetFileServiceProvider(m_transport)->WriteShareProperties(
  294. m_strMachineName,
  295. m_strShareName,
  296. m_pvPropertyBlock,
  297. m_strDescription,
  298. m_strPath);
  299. if (0L != retval)
  300. {
  301. DoErrMsgBox(m_hWnd, MB_OK | MB_ICONEXCLAMATION, retval, IDS_POPUP_WRITE_SHARE, m_strShareName);
  302. return FALSE;
  303. }
  304. }
  305. return CSharePage::OnApply();
  306. }
  307. void CSharePageGeneral::OnChangeEditPathName()
  308. {
  309. SetModified (TRUE);
  310. }
  311. void CSharePageGeneral::OnChangeEditDescription()
  312. {
  313. SetModified (TRUE);
  314. }
  315. void CSharePageGeneral::OnChangeEditShareName()
  316. {
  317. SetModified (TRUE);
  318. }
  319. void CSharePageGeneral::OnShrpropAllowSpecific()
  320. {
  321. GetDlgItem(IDC_SHRPROP_EDIT_USERS)->EnableWindow(TRUE);
  322. GetDlgItem(IDC_SHRPROP_SPIN_USERS)->EnableWindow(TRUE);
  323. SetModified (TRUE);
  324. }
  325. void CSharePageGeneral::OnShrpropMaxAllowed()
  326. {
  327. SetDlgItemText(IDC_SHRPROP_EDIT_USERS, _T("1"));
  328. GetDlgItem(IDC_SHRPROP_EDIT_USERS)->EnableWindow(FALSE);
  329. GetDlgItem(IDC_SHRPROP_SPIN_USERS)->EnableWindow(FALSE);
  330. SetModified (TRUE);
  331. }
  332. void CSharePageGeneral::OnChangeShrpropEditUsers()
  333. {
  334. SetModified (TRUE);
  335. }