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.

368 lines
9.3 KiB

  1. #include "stdafx.h"
  2. #include "RoutingMethodProp.h"
  3. #include "RoutingMethodConfig.h"
  4. #include <shlobj.h>
  5. #include <faxutil.h>
  6. #include <faxreg.h>
  7. #include <faxres.h>
  8. #include <StoreConfigPage.h>
  9. #include <Util.h>
  10. HRESULT
  11. CStoreConfigPage::Init(
  12. LPCTSTR lpctstrServerName,
  13. DWORD dwDeviceId
  14. )
  15. {
  16. DEBUG_FUNCTION_NAME(TEXT("CStoreConfigPage::Init"));
  17. DWORD ec = ERROR_SUCCESS;
  18. m_bstrServerName = lpctstrServerName;
  19. m_dwDeviceId = dwDeviceId;
  20. if (!m_bstrServerName)
  21. {
  22. ec = ERROR_NOT_ENOUGH_MEMORY;
  23. DebugPrintEx(DEBUG_ERR, TEXT("Out of memory while copying server name (ec: %ld)"), ec);
  24. DisplayRpcErrorMessage(ERROR_NOT_ENOUGH_MEMORY, IDS_STORE_TITLE, m_hWnd);
  25. goto exit;
  26. }
  27. if (!FaxConnectFaxServer(lpctstrServerName, &m_hFax))
  28. {
  29. ec = GetLastError();
  30. DebugPrintEx(
  31. DEBUG_ERR,
  32. TEXT("FaxConnectFaxServer failed (ec: %ld)"),
  33. ec);
  34. DisplayRpcErrorMessage(ec, IDS_STORE_TITLE, m_hWnd);
  35. goto exit;
  36. }
  37. //
  38. // Retrieve the data
  39. //
  40. ec = ReadExtStringData (
  41. m_hFax,
  42. m_dwDeviceId,
  43. REGVAL_RM_FOLDER_GUID,
  44. m_bstrFolder,
  45. TEXT(""),
  46. IDS_STORE_TITLE,
  47. m_hWnd);
  48. exit:
  49. if ((ERROR_SUCCESS != ec) && m_hFax)
  50. {
  51. if (!FaxClose(m_hFax))
  52. {
  53. DebugPrintEx(
  54. DEBUG_ERR,
  55. TEXT("FaxClose() failed on fax handle (0x%08X : %s). (ec: %ld)"),
  56. m_hFax,
  57. m_bstrServerName,
  58. GetLastError());
  59. }
  60. m_hFax = NULL;
  61. }
  62. return HRESULT_FROM_WIN32(ec);
  63. } // CStoreConfigPage::Init
  64. LRESULT CStoreConfigPage::OnInitDialog(
  65. UINT uiMsg,
  66. WPARAM wParam,
  67. LPARAM lParam,
  68. BOOL& fHandled
  69. )
  70. {
  71. DEBUG_FUNCTION_NAME( _T("CStoreConfigPage::OnInitDialog"));
  72. //
  73. // An edit control should be LTR
  74. //
  75. SetLTREditDirection (m_hWnd,IDC_EDIT_FOLDER);
  76. //
  77. // Attach and set values to the controls
  78. //
  79. m_edtFolder.Attach (GetDlgItem (IDC_EDIT_FOLDER));
  80. m_edtFolder.SetWindowText (m_bstrFolder);
  81. m_edtFolder.SetLimitText (MAX_PATH);
  82. SHAutoComplete (GetDlgItem (IDC_EDIT_FOLDER), SHACF_FILESYSTEM);
  83. m_fIsDialogInitiated = TRUE;
  84. if ( 0 != m_bstrServerName.Length()) //not a local server
  85. {
  86. ::EnableWindow(GetDlgItem(IDC_BUT_BROWSE), FALSE);
  87. }
  88. return 1;
  89. }
  90. BOOL
  91. DirectoryExists(
  92. LPTSTR pDirectoryName
  93. )
  94. /*++
  95. Routine Description:
  96. Check the existancy of given folder name
  97. Arguments:
  98. pDirectoryName - point to folder name
  99. Return Value:
  100. if the folder exists, return TRUE; else, return FALSE.
  101. --*/
  102. {
  103. DWORD dwFileAttributes;
  104. if(!pDirectoryName || lstrlen(pDirectoryName) == 0)
  105. {
  106. return FALSE;
  107. }
  108. dwFileAttributes = GetFileAttributes(pDirectoryName);
  109. if ( dwFileAttributes != 0xffffffff &&
  110. dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
  111. {
  112. return TRUE;
  113. }
  114. return FALSE;
  115. }
  116. BOOL
  117. CStoreConfigPage::OnApply()
  118. {
  119. DEBUG_FUNCTION_NAME(TEXT("CStoreConfigPage::OnApply"));
  120. if (!m_fIsDirty)
  121. {
  122. return TRUE;
  123. }
  124. //
  125. // Collect data from the controls
  126. //
  127. m_edtFolder.GetWindowText (m_bstrFolder.m_str);
  128. if (!m_bstrFolder.Length())
  129. {
  130. DisplayErrorMessage (IDS_STORE_TITLE, IDS_FOLDER_EMPTY, FALSE, m_hWnd);
  131. return FALSE;
  132. }
  133. if(!FaxCheckValidFaxFolder(m_hFax, m_bstrFolder))
  134. {
  135. DWORD dwRes = ::GetLastError();
  136. DebugPrintEx(DEBUG_ERR, TEXT("FaxCheckValidFaxFolder failed (ec: %ld)"), dwRes);
  137. //
  138. // Try to adjust folder
  139. //
  140. PropSheet_SetCurSelByID( GetParent(), IDD);
  141. GotoDlgCtrl(GetDlgItem(IDC_EDIT_FOLDER));
  142. dwRes = AskUserAndAdjustFaxFolder(m_hWnd, m_bstrServerName, m_bstrFolder, dwRes);
  143. if(ERROR_SUCCESS != dwRes)
  144. {
  145. if(ERROR_BAD_PATHNAME != dwRes)
  146. {
  147. //
  148. // The error message has not been shown by AskUserAndAdjustFaxFolder
  149. //
  150. DisplayErrorMessage (IDS_STORE_TITLE, IDS_FOLDER_INVALID, FALSE, m_hWnd);
  151. }
  152. return FALSE;
  153. }
  154. }
  155. //
  156. // Validation passed. Now write the data using RPC
  157. //
  158. if (ERROR_SUCCESS != WriteExtData (m_hFax,
  159. m_dwDeviceId,
  160. REGVAL_RM_FOLDER_GUID,
  161. (LPBYTE)(LPCWSTR)m_bstrFolder,
  162. sizeof (WCHAR) * (1 + m_bstrFolder.Length()),
  163. IDS_STORE_TITLE,
  164. m_hWnd))
  165. {
  166. return FALSE;
  167. }
  168. //Success
  169. m_fIsDirty = FALSE;
  170. return TRUE;
  171. } // CStoreConfigPage::OnApply
  172. CComBSTR CStoreConfigPage::m_bstrFolder;
  173. int CALLBACK
  174. BrowseCallbackProc(
  175. HWND hwnd,
  176. UINT uMsg,
  177. LPARAM lp,
  178. LPARAM pData
  179. )
  180. {
  181. switch(uMsg)
  182. {
  183. case BFFM_INITIALIZED:
  184. {
  185. LPCWSTR lpcwstrCurrentFolder = CStoreConfigPage::GetFolder();
  186. ::SendMessage (hwnd,
  187. BFFM_SETSELECTION,
  188. TRUE, // Passing a path string and not a pidl.
  189. (LPARAM)(lpcwstrCurrentFolder));
  190. break;
  191. }
  192. case BFFM_SELCHANGED:
  193. {
  194. BOOL bFolderIsOK = FALSE;
  195. TCHAR szPath [MAX_PATH + 1];
  196. if (SHGetPathFromIDList ((LPITEMIDLIST) lp, szPath))
  197. {
  198. DWORD dwFileAttr = GetFileAttributes(szPath);
  199. if (-1 != dwFileAttr && (dwFileAttr & FILE_ATTRIBUTE_DIRECTORY))
  200. {
  201. //
  202. // The directory exists - enable the 'Ok' button
  203. //
  204. bFolderIsOK = TRUE;
  205. }
  206. }
  207. //
  208. // Enable / disable the 'ok' button
  209. //
  210. ::SendMessage(hwnd, BFFM_ENABLEOK , 0, (LPARAM)bFolderIsOK);
  211. break;
  212. }
  213. default:
  214. break;
  215. }
  216. return 0;
  217. } // BrowseCallbackProc
  218. LRESULT
  219. CStoreConfigPage::OnBrowseForFolder(
  220. WORD wNotifyCode,
  221. WORD wID,
  222. HWND hWndCtl,
  223. BOOL& bHandled
  224. )
  225. {
  226. DEBUG_FUNCTION_NAME(TEXT("CStoreConfigPage::OnBrowseForFolder"));
  227. CComBSTR bstrSelectedFolder;
  228. BROWSEINFO bi = {0};
  229. HRESULT hr = NOERROR;
  230. TCHAR szDisplayName[MAX_PATH + 1];
  231. bi.hwndOwner = hWndCtl;
  232. bi.pidlRoot = NULL;
  233. bi.pszDisplayName = szDisplayName;
  234. bi.lpszTitle = AllocateAndLoadString (_pModule->m_hInstResource, IDS_SELECT_FOLDER);
  235. bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE | BIF_NONEWFOLDERBUTTON;
  236. bi.lpfn = BrowseCallbackProc;
  237. m_edtFolder.GetWindowText (m_bstrFolder.m_str);
  238. LPITEMIDLIST pItemIdList = SHBrowseForFolder (&bi);
  239. MemFree ((LPVOID)bi.lpszTitle);
  240. if (NULL == pItemIdList)
  241. {
  242. //
  243. // User pressed cancel
  244. //
  245. return hr;
  246. }
  247. if(!::SHGetPathFromIDList(pItemIdList, szDisplayName))
  248. {
  249. hr = HRESULT_FROM_WIN32(ERROR_CAN_NOT_COMPLETE);
  250. DebugPrintEx(
  251. DEBUG_ERR,
  252. TEXT("SHGetPathFromIDList() failed. (hr = 0x%08X)"),
  253. hr);
  254. }
  255. else
  256. {
  257. m_edtFolder.SetWindowText (szDisplayName);
  258. SetModified(TRUE);
  259. }
  260. //
  261. // free pItemIdList
  262. //
  263. LPMALLOC pMalloc;
  264. HRESULT hRes = ::SHGetMalloc(&pMalloc);
  265. if(E_FAIL == hRes)
  266. {
  267. hr = HRESULT_FROM_WIN32(ERROR_CAN_NOT_COMPLETE);
  268. DebugPrintEx(
  269. DEBUG_ERR,
  270. TEXT("SHGetMalloc() failed. (hr = 0x%08X)"),
  271. hr);
  272. }
  273. else
  274. {
  275. pMalloc->Free(pItemIdList);
  276. pMalloc->Release();
  277. }
  278. return hr;
  279. } // CStoreConfigPage::OnBrowseForFolder
  280. //////////////////////////////////////////////////////////////////////////////
  281. /*++
  282. CStoreConfigPage::OnHelpRequest
  283. This is called in response to the WM_HELP Notify
  284. message and to the WM_CONTEXTMENU Notify message.
  285. WM_HELP Notify message.
  286. This message is sent when the user presses F1 or <Shift>-F1
  287. over an item or when the user clicks on the ? icon and then
  288. presses the mouse over an item.
  289. WM_CONTEXTMENU Notify message.
  290. This message is sent when the user right clicks over an item
  291. and then clicks "What's this?"
  292. --*/
  293. /////////////////////////////////////////////////////////////////////////////
  294. LRESULT
  295. CStoreConfigPage::OnHelpRequest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
  296. {
  297. DEBUG_FUNCTION_NAME(_T("CStoreConfigPage::OnHelpRequest"));
  298. switch (uMsg)
  299. {
  300. case WM_HELP:
  301. WinContextHelp(((LPHELPINFO)lParam)->dwContextId, m_hWnd);
  302. break;
  303. case WM_CONTEXTMENU:
  304. WinContextHelp(::GetWindowContextHelpId((HWND)wParam), m_hWnd);
  305. break;
  306. }
  307. return TRUE;
  308. }