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.

244 lines
6.7 KiB

  1. #include "stdafx.h"
  2. #include "fspext.h"
  3. #include "FSP.h"
  4. /////////////////////////////////////////////////////////////////////////////
  5. // CFSPComponentData
  6. static const GUID CFSPGUID_NODETYPE =
  7. { 0xde58ae00, 0x4c0f, 0x11d1, {0x90, 0x83, 0x00, 0xa0, 0xc9, 0x0a, 0xb5, 0x04}};
  8. const GUID* CFSPData::m_NODETYPE = &CFSPGUID_NODETYPE;
  9. const TCHAR* CFSPData::m_SZNODETYPE = _T("de58ae00-4c0f-11d1-9083-00a0c90ab504");
  10. const TCHAR* CFSPData::m_SZDISPLAY_NAME = _T("CFSP");
  11. const CLSID* CFSPData::m_SNAPIN_CLASSID = &CLSID_FSP;
  12. LRESULT CFSPPage::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  13. {
  14. //::SendMessage(GetParent(), PSM_SETWIZBUTTONS, 0, PSWIZB_FINISH);
  15. SetChangedFlag (FALSE);
  16. switch (m_LoggingLevel) {
  17. case LOGGING_NONE:
  18. CheckDlgButton( IDC_LOG_NONE, TRUE);
  19. ::EnableWindow( GetDlgItem( IDC_LOGLOCATION ), FALSE );
  20. ::EnableWindow( GetDlgItem( IDC_LOCATION_LABEL ), FALSE );
  21. ::EnableWindow( GetDlgItem( IDC_LOGBROWSE ), FALSE );
  22. break;
  23. case LOGGING_ERRORS:
  24. CheckDlgButton( IDC_LOG_ERRORS, TRUE);
  25. ::EnableWindow( GetDlgItem( IDC_LOGLOCATION ), TRUE );
  26. ::EnableWindow( GetDlgItem( IDC_LOCATION_LABEL ), TRUE );
  27. ::EnableWindow( GetDlgItem( IDC_LOGBROWSE ), TRUE );
  28. break;
  29. case LOGGING_ALL:
  30. CheckDlgButton( IDC_LOG_ALL , TRUE);
  31. ::EnableWindow( GetDlgItem( IDC_LOGLOCATION ), TRUE );
  32. ::EnableWindow( GetDlgItem( IDC_LOCATION_LABEL ), TRUE );
  33. ::EnableWindow( GetDlgItem( IDC_LOGBROWSE ), TRUE );
  34. break;
  35. default:
  36. CheckDlgButton( IDC_LOG_NONE , TRUE);
  37. ::EnableWindow( GetDlgItem( IDC_LOGLOCATION ), FALSE );
  38. ::EnableWindow( GetDlgItem( IDC_LOCATION_LABEL ), FALSE );
  39. ::EnableWindow( GetDlgItem( IDC_LOGBROWSE ), FALSE );
  40. }
  41. SendDlgItemMessage( IDC_LOGLOCATION, EM_SETLIMITTEXT, MAX_PATH - 2, 0 );
  42. if (m_LoggingDirectory) {
  43. SetDlgItemText( IDC_LOGLOCATION, m_LoggingDirectory );
  44. }
  45. return 1;
  46. }
  47. VOID CFSPPage::SetChangedFlag( BOOL Flag ) {
  48. PropSheet_Changed( GetParent(), m_hWnd );
  49. m_bChanged = TRUE;
  50. }
  51. LRESULT CFSPPage::DisableLogging(INT code, INT id, HWND hwnd, BOOL& bHandled)
  52. {
  53. ::EnableWindow( GetDlgItem( IDC_LOGLOCATION ), FALSE );
  54. ::EnableWindow( GetDlgItem( IDC_LOCATION_LABEL ), FALSE );
  55. ::EnableWindow( GetDlgItem( IDC_LOGBROWSE ), FALSE );
  56. SetChangedFlag(TRUE);
  57. return 1;
  58. }
  59. LRESULT CFSPPage::EnableLogging(INT code, INT id, HWND hwnd, BOOL& bHandled)
  60. {
  61. ::EnableWindow( GetDlgItem( IDC_LOGLOCATION ), TRUE );
  62. ::EnableWindow( GetDlgItem( IDC_LOCATION_LABEL ), TRUE );
  63. ::EnableWindow( GetDlgItem( IDC_LOGBROWSE ), TRUE );
  64. SetChangedFlag(TRUE);
  65. return 1;
  66. }
  67. LRESULT CFSPPage::OnBrowseDir(INT code, INT id, HWND hwnd, BOOL& bHandled) {
  68. BrowseForDirectory();
  69. return 1;
  70. }
  71. BOOL CFSPPage::OnApply()
  72. {
  73. //
  74. // if there aren't any changes, don't commit anything
  75. //
  76. if (!m_bChanged) {
  77. return TRUE;
  78. }
  79. if (IsDlgButtonChecked(IDC_LOG_NONE)== BST_CHECKED) {
  80. m_LoggingLevel = LOGGING_NONE;
  81. } else if (IsDlgButtonChecked(IDC_LOG_ERRORS)== BST_CHECKED) {
  82. m_LoggingLevel = LOGGING_ERRORS;
  83. } else if (IsDlgButtonChecked(IDC_LOG_ALL)== BST_CHECKED) {
  84. m_LoggingLevel = LOGGING_ALL;
  85. } else
  86. m_LoggingLevel = LOGGING_NONE;
  87. if (m_LoggingLevel != LOGGING_NONE) {
  88. if (m_LoggingDirectory) {
  89. MemFree(m_LoggingDirectory);
  90. }
  91. m_LoggingDirectory = (LPTSTR) MemAlloc ( MAX_PATH );
  92. if (!GetDlgItemText( IDC_LOGLOCATION,m_LoggingDirectory, MAX_PATH - 1 ) ) {
  93. MessageBox(TEXT("You must enter a logging location"),
  94. TEXT("Logging Error"),
  95. MB_OK | MB_ICONEXCLAMATION);
  96. MemFree(m_LoggingDirectory);
  97. m_LoggingDirectory = NULL;
  98. ::SetFocus(GetDlgItem(IDC_LOGLOCATION));
  99. return FALSE;
  100. } else {
  101. if (!ValidateLogLocation()) {
  102. MessageBox(TEXT("You must enter a logging location"),
  103. TEXT("Logging Error"),
  104. MB_OK | MB_ICONEXCLAMATION);
  105. MemFree(m_LoggingDirectory);
  106. m_LoggingDirectory = NULL;
  107. ::SetFocus(GetDlgItem(IDC_LOGLOCATION));
  108. return FALSE;
  109. }
  110. }
  111. } else
  112. if (m_LoggingDirectory) {
  113. MemFree(m_LoggingDirectory);
  114. m_LoggingDirectory = TEXT("");
  115. }
  116. if (!m_LogKey) {
  117. Assert(FALSE);
  118. }
  119. SetRegistryDword(m_LogKey,LOGLEVEL,m_LoggingLevel);
  120. SetRegistryString(m_LogKey,LOGLOCATION,m_LoggingDirectory);
  121. MessageBox(TEXT("You must restart the fax service for your logging changes to take effect"),
  122. TEXT("Logging Change"),
  123. MB_OK);
  124. SetChangedFlag(FALSE);
  125. return TRUE;
  126. }
  127. BOOL
  128. CFSPPage::BrowseForDirectory(
  129. )
  130. /*++
  131. Routine Description:
  132. Browse for a directory
  133. Arguments:
  134. hDlg - Specifies the dialog window on which the Browse button is displayed
  135. textFieldId - Specifies the text field adjacent to the Browse button
  136. titleStrId - Specifies the title to be displayed in the browse window
  137. Return Value:
  138. TRUE if successful, FALSE if the user presses Cancel
  139. --*/
  140. {
  141. LPITEMIDLIST pidl;
  142. WCHAR buffer[MAX_PATH];
  143. WCHAR title[MAX_TITLE_LEN];
  144. VOID SHFree(LPVOID);
  145. BOOL result = FALSE;
  146. LPMALLOC pMalloc;
  147. BROWSEINFO bi = {
  148. m_hWnd,
  149. NULL,
  150. buffer,
  151. title,
  152. BIF_RETURNONLYFSDIRS,
  153. NULL,
  154. (LPARAM) buffer,
  155. };
  156. if (! LoadString(_Module.m_hInst, IDS_BROWSE_TITLE, title, MAX_TITLE_LEN))
  157. title[0] = 0;
  158. if (! GetDlgItemText( IDC_LOGLOCATION, buffer, MAX_PATH))
  159. buffer[0] = 0;
  160. if (pidl = SHBrowseForFolder(&bi)) {
  161. if (SHGetPathFromIDList(pidl, buffer)) {
  162. if (wcslen(buffer) > MAX_PATH-2) {
  163. Assert(FALSE);
  164. } else {
  165. SetDlgItemText(IDC_LOGLOCATION, buffer);
  166. result = TRUE;
  167. }
  168. }
  169. SHGetMalloc(&pMalloc);
  170. pMalloc->Free(pidl);
  171. pMalloc->Release();
  172. }
  173. return result;
  174. }
  175. BOOL CFSPPage::ValidateLogLocation()
  176. {
  177. HANDLE hFile = INVALID_HANDLE_VALUE;
  178. TCHAR file[MAX_PATH];
  179. wsprintf(file,TEXT("%s\\faxt30.log"),m_LoggingDirectory);
  180. hFile = CreateFile(file,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_ARCHIVE,NULL);
  181. if (hFile == INVALID_HANDLE_VALUE) {
  182. CloseHandle(hFile);
  183. return FALSE;
  184. }
  185. CloseHandle(hFile);
  186. DeleteFile(m_LoggingDirectory);
  187. return TRUE;
  188. }