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.

460 lines
13 KiB

  1. // svcprop3.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #ifdef _DEBUG
  5. #define new DEBUG_NEW
  6. #undef THIS_FILE
  7. static char THIS_FILE[] = __FILE__;
  8. #endif
  9. const UINT rgidComboFailureAction[cActionsMax] =
  10. {
  11. IDC_COMBO_FIRST_ATTEMPT,
  12. IDC_COMBO_SECOND_ATTEMPT,
  13. IDC_COMBO_SUBSEQUENT_ATTEMPTS,
  14. };
  15. const TStringParamEntry rgzspeRecoveryAction[] =
  16. {
  17. { IDS_SVC_RECOVERY_NOACTION, SC_ACTION_NONE },
  18. { IDS_SVC_RECOVERY_RESTARTSERVICE, SC_ACTION_RESTART },
  19. { IDS_SVC_RECOVERY_RUNFILE, SC_ACTION_RUN_COMMAND },
  20. { IDS_SVC_RECOVERY_REBOOTCOMPUTER, SC_ACTION_REBOOT },
  21. { 0, 0 }
  22. };
  23. // Group of control Ids to restart service
  24. const UINT rgzidRestartService[] =
  25. {
  26. // IDC_GROUP_RESTARTSERVICE,
  27. IDC_STATIC_RESTARTSERVICE,
  28. IDC_STATIC_RESTARTSERVICE_3,
  29. IDC_EDIT_SERVICE_RESTART_DELAY,
  30. 0
  31. };
  32. const UINT rgzidRunFile[] =
  33. {
  34. IDC_STATIC_RUNFILE_1,
  35. IDC_STATIC_RUNFILE_2,
  36. IDC_STATIC_RUNFILE_3,
  37. IDC_EDIT_RUNFILE_FILENAME,
  38. IDC_BUTTON_BROWSE,
  39. IDC_EDIT_RUNFILE_PARAMETERS,
  40. IDC_CHECK_APPEND_ABENDNO,
  41. 0
  42. };
  43. const UINT rgzidRebootComputer[] =
  44. {
  45. IDC_BUTTON_REBOOT_COMPUTER,
  46. 0
  47. };
  48. /////////////////////////////////////////////////////////////////////////////
  49. // CServicePageRecovery property page
  50. IMPLEMENT_DYNCREATE(CServicePageRecovery, CPropertyPage)
  51. CServicePageRecovery::CServicePageRecovery() : CPropertyPage(CServicePageRecovery::IDD)
  52. , m_pData( NULL ) // 581167-2002/03/07-JonN initialize m_pData
  53. {
  54. //{{AFX_DATA_INIT(CServicePageRecovery)
  55. m_strRunFileCommand = _T("");
  56. m_strRunFileParam = _T("");
  57. m_fAppendAbendCount = FALSE;
  58. //}}AFX_DATA_INIT
  59. }
  60. CServicePageRecovery::~CServicePageRecovery()
  61. {
  62. }
  63. void CServicePageRecovery::DoDataExchange(CDataExchange* pDX)
  64. {
  65. // ISSUE-2002/03/07-JonN should handle these better
  66. Assert(m_pData != NULL);
  67. Assert(m_pData->m_SFA.cActions >= cActionsMax);
  68. Assert(m_pData->m_SFA.lpsaActions != NULL);
  69. if (m_pData->m_SFA.lpsaActions == NULL) // Temporary checking for safety
  70. return;
  71. if (!pDX->m_bSaveAndValidate)
  72. {
  73. //
  74. // Initialize data from m_pData into UI
  75. //
  76. for (INT i = 0; i < cActionsMax; i++)
  77. {
  78. // Fill each combobox with the list of failure/actions
  79. // and select the right failure/action
  80. HWND hwndCombo = HGetDlgItem(m_hWnd, rgidComboFailureAction[i]);
  81. ComboBox_FlushContent(hwndCombo);
  82. (void)ComboBox_FFill(
  83. hwndCombo,
  84. IN rgzspeRecoveryAction,
  85. m_pData->m_SFA.lpsaActions[i].Type);
  86. } // for
  87. Service_SplitCommandLine(
  88. IN m_pData->m_strRunFileCommand,
  89. OUT &m_strRunFileCommand,
  90. OUT &m_strRunFileParam,
  91. OUT &m_fAppendAbendCount);
  92. } // if
  93. CPropertyPage::DoDataExchange(pDX);
  94. //{{AFX_DATA_MAP(CServicePageRecovery)
  95. DDX_Text(pDX, IDC_EDIT_RUNFILE_FILENAME, m_strRunFileCommand);
  96. DDX_Text(pDX, IDC_EDIT_RUNFILE_PARAMETERS, m_strRunFileParam);
  97. DDX_Check(pDX, IDC_CHECK_APPEND_ABENDNO, m_fAppendAbendCount);
  98. //}}AFX_DATA_MAP
  99. (void) SendDlgItemMessage(IDC_EDIT_SERVICE_RESET_ABEND_COUNT, EM_LIMITTEXT, 4);
  100. (void) SendDlgItemMessage(IDC_EDIT_SERVICE_RESTART_DELAY, EM_LIMITTEXT, 4);
  101. DDX_Text(pDX, IDC_EDIT_SERVICE_RESET_ABEND_COUNT, m_pData->m_daysDisplayAbendCount);
  102. DDX_Text(pDX, IDC_EDIT_SERVICE_RESTART_DELAY, m_pData->m_minDisplayRestartService);
  103. if (pDX->m_bSaveAndValidate)
  104. {
  105. TrimString(m_strRunFileCommand);
  106. TrimString(m_strRunFileParam);
  107. Service_UnSplitCommandLine(
  108. OUT &m_pData->m_strRunFileCommand,
  109. IN m_strRunFileCommand,
  110. IN m_strRunFileParam);
  111. if (m_fAppendAbendCount)
  112. m_pData->m_strRunFileCommand += szAbend;
  113. } // if
  114. } // CServicePageRecovery::DoDataExchange()
  115. BEGIN_MESSAGE_MAP(CServicePageRecovery, CPropertyPage)
  116. //{{AFX_MSG_MAP(CServicePageRecovery)
  117. ON_CBN_SELCHANGE(IDC_COMBO_FIRST_ATTEMPT, OnSelchangeComboFirstAttempt)
  118. ON_CBN_SELCHANGE(IDC_COMBO_SECOND_ATTEMPT, OnSelchangeComboSecondAttempt)
  119. ON_CBN_SELCHANGE(IDC_COMBO_SUBSEQUENT_ATTEMPTS, OnSelchangeComboSubsequentAttempts)
  120. ON_BN_CLICKED(IDC_BUTTON_BROWSE, OnButtonBrowse)
  121. ON_BN_CLICKED(IDC_BUTTON_REBOOT_COMPUTER, OnButtonRebootComputer)
  122. ON_BN_CLICKED(IDC_CHECK_APPEND_ABENDNO, OnCheckAppendAbendno)
  123. ON_EN_CHANGE(IDC_EDIT_RUNFILE_FILENAME, OnChangeEditRunfileFilename)
  124. ON_EN_CHANGE(IDC_EDIT_RUNFILE_PARAMETERS, OnChangeEditRunfileParameters)
  125. ON_EN_CHANGE(IDC_EDIT_SERVICE_RESET_ABEND_COUNT, OnChangeEditServiceResetAbendCount)
  126. ON_EN_CHANGE(IDC_EDIT_SERVICE_RESTART_DELAY, OnChangeEditServiceRestartDelay)
  127. ON_MESSAGE(WM_HELP, OnHelp)
  128. ON_MESSAGE(WM_CONTEXTMENU, OnContextHelp)
  129. //}}AFX_MSG_MAP
  130. END_MESSAGE_MAP()
  131. /////////////////////////////////////////////////////////////////////////////
  132. // CServicePageRecovery message handlers
  133. BOOL CServicePageRecovery::OnInitDialog()
  134. {
  135. CPropertyPage::OnInitDialog();
  136. UpdateUI();
  137. return TRUE;
  138. } // CServicePageRecovery::OnInitDialog()
  139. void CServicePageRecovery::UpdateUI()
  140. {
  141. // ISSUE-2002/03/07-JonN should handle these better
  142. Assert(m_pData->m_SFA.cActions >= cActionsMax);
  143. Assert(m_pData->m_SFA.lpsaActions != NULL);
  144. // Get the failure/action code of each combobox
  145. for (INT i = 0; i < cActionsMax; i++)
  146. {
  147. m_pData->m_SFA.lpsaActions[i].Type = (SC_ACTION_TYPE)ComboBox_GetSelectedItemData(
  148. HGetDlgItem(m_hWnd, rgidComboFailureAction[i]));
  149. Assert((int)m_pData->m_SFA.lpsaActions[i].Type != CB_ERR);
  150. } // for
  151. // The idea here is to enable/disable controls
  152. // depending on the chosen failure/action from
  153. // the comboboxes.
  154. BOOL fFound = FALSE;
  155. (void)m_pData->GetDelayForActionType(SC_ACTION_RESTART, OUT &fFound);
  156. EnableDlgItemGroup(m_hWnd, rgzidRestartService, fFound);
  157. (void)m_pData->GetDelayForActionType(SC_ACTION_RUN_COMMAND, OUT &fFound);
  158. EnableDlgItemGroup(m_hWnd, rgzidRunFile, fFound);
  159. (void)m_pData->GetDelayForActionType(SC_ACTION_REBOOT, OUT &fFound);
  160. EnableDlgItemGroup(m_hWnd, rgzidRebootComputer, fFound);
  161. //
  162. // JonN 9/4/01 463674
  163. // Services targeted to another computer: Service_ Properties->Recovery->Browse: Path...
  164. //
  165. if (!m_pData->m_strMachineName.IsEmpty())
  166. {
  167. GetDlgItem(IDC_BUTTON_BROWSE)->EnableWindow(FALSE);
  168. }
  169. }
  170. // ISSUE-2002/03/18-JonN We probably only need one MarkDirtyActionType method
  171. void CServicePageRecovery::OnSelchangeComboFirstAttempt()
  172. {
  173. UpdateUI();
  174. SetModified();
  175. m_pData->SetDirty(CServicePropertyData::mskfDirtyActionType);
  176. }
  177. void CServicePageRecovery::OnSelchangeComboSecondAttempt()
  178. {
  179. UpdateUI();
  180. SetModified();
  181. m_pData->SetDirty(CServicePropertyData::mskfDirtyActionType);
  182. }
  183. void CServicePageRecovery::OnSelchangeComboSubsequentAttempts()
  184. {
  185. UpdateUI();
  186. SetModified();
  187. m_pData->SetDirty(CServicePropertyData::mskfDirtyActionType);
  188. }
  189. void CServicePageRecovery::OnButtonBrowse()
  190. {
  191. TCHAR szFileName[MAX_PATH];
  192. szFileName[0] = 0;
  193. if (UiGetFileName(m_hWnd,
  194. OUT szFileName,
  195. LENGTH(szFileName)))
  196. {
  197. SetDlgItemText(IDC_EDIT_RUNFILE_FILENAME, szFileName);
  198. SetModified();
  199. }
  200. }
  201. void CServicePageRecovery::OnButtonRebootComputer()
  202. {
  203. Assert(m_pData != NULL);
  204. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  205. CServiceDlgRebootComputer dlg(this);
  206. dlg.m_pData = m_pData;
  207. CThemeContextActivator activator;
  208. if (dlg.DoModal() == IDOK)
  209. {
  210. // The user has modified some data
  211. SetModified();
  212. }
  213. }
  214. // ISSUE-2002/03/18-JonN We probably only need one MarkDirtySFA method
  215. /////////////////////////////////////////////////////////////////////
  216. // "Reset 'Fail Count' after %d days"
  217. void CServicePageRecovery::OnChangeEditServiceResetAbendCount()
  218. {
  219. SetModified();
  220. m_pData->SetDirty(CServicePropertyData::mskfDirtySFA);
  221. }
  222. /////////////////////////////////////////////////////////////////////
  223. // "Restart service in %d minutes"
  224. void CServicePageRecovery::OnChangeEditServiceRestartDelay()
  225. {
  226. SetModified();
  227. m_pData->SetDirty(CServicePropertyData::mskfDirtySFA);
  228. }
  229. // ISSUE-2002/03/18-JonN We probably only need one MarkDirtyRunFile method
  230. /////////////////////////////////////////////////////////////////////
  231. // "Run %s file"
  232. void CServicePageRecovery::OnChangeEditRunfileFilename()
  233. {
  234. SetModified();
  235. m_pData->SetDirty(CServicePropertyData::mskfDirtyRunFile);
  236. }
  237. void CServicePageRecovery::OnChangeEditRunfileParameters()
  238. {
  239. SetModified();
  240. m_pData->SetDirty(CServicePropertyData::mskfDirtyRunFile);
  241. }
  242. void CServicePageRecovery::OnCheckAppendAbendno()
  243. {
  244. SetModified();
  245. m_pData->SetDirty(CServicePropertyData::mskfDirtyRunFile);
  246. }
  247. /////////////////////////////////////////////////////////////////////
  248. // Help
  249. BOOL CServicePageRecovery::OnHelp(WPARAM /*wParam*/, LPARAM lParam)
  250. {
  251. return DoHelp(lParam, HELP_DIALOG_TOPIC(IDD_PROPPAGE_SERVICE_RECOVERY));
  252. }
  253. BOOL CServicePageRecovery::OnContextHelp(WPARAM wParam, LPARAM /*lParam*/)
  254. {
  255. return DoContextHelp(wParam, HELP_DIALOG_TOPIC(IDD_PROPPAGE_SERVICE_RECOVERY));
  256. }
  257. /////////////////////////////////////////////////////////////////////////////
  258. // CServicePageRecovery2 property page
  259. // JonN 4/20/01 348163
  260. IMPLEMENT_DYNCREATE(CServicePageRecovery2, CPropertyPage)
  261. CServicePageRecovery2::CServicePageRecovery2() : CPropertyPage(CServicePageRecovery2::IDD)
  262. , m_pData( NULL ) // 581167-2002/03/07-JonN should initialize m_pData
  263. {
  264. //{{AFX_DATA_INIT(CServicePageRecovery2)
  265. //}}AFX_DATA_INIT
  266. }
  267. CServicePageRecovery2::~CServicePageRecovery2()
  268. {
  269. }
  270. BEGIN_MESSAGE_MAP(CServicePageRecovery2, CPropertyPage)
  271. //{{AFX_MSG_MAP(CServicePageRecovery2)
  272. //}}AFX_MSG_MAP
  273. END_MESSAGE_MAP()
  274. /////////////////////////////////////////////////////////////////////////////
  275. /////////////////////////////////////////////////////////////////////////////
  276. // CServiceDlgRebootComputer dialog
  277. CServiceDlgRebootComputer::CServiceDlgRebootComputer(CWnd* pParent /*=NULL*/)
  278. : CDialog(CServiceDlgRebootComputer::IDD, pParent)
  279. , m_pData( NULL ) // 581167-2002/03/07-JonN should initialize m_pData
  280. {
  281. //{{AFX_DATA_INIT(CServiceDlgRebootComputer)
  282. m_uDelayRebootComputer = 0;
  283. m_fRebootMessage = FALSE;
  284. //}}AFX_DATA_INIT
  285. }
  286. void CServiceDlgRebootComputer::DoDataExchange(CDataExchange* pDX)
  287. {
  288. CDialog::DoDataExchange(pDX);
  289. //{{AFX_DATA_MAP(CServiceDlgRebootComputer)
  290. DDX_Text(pDX, IDC_EDIT_REBOOT_COMPUTER_DELAY, m_uDelayRebootComputer);
  291. DDV_MinMaxUInt(pDX, m_uDelayRebootComputer, 0, 100000);
  292. DDX_Check(pDX, IDC_REBOOT_MESSAGE_CHECKBOX, m_fRebootMessage);
  293. DDX_Text(pDX, IDC_EDIT_REBOOT_MESSAGE, m_strRebootMessage);
  294. //}}AFX_DATA_MAP
  295. }
  296. BEGIN_MESSAGE_MAP(CServiceDlgRebootComputer, CDialog)
  297. //{{AFX_MSG_MAP(CServiceDlgRebootComputer)
  298. ON_BN_CLICKED(IDC_REBOOT_MESSAGE_CHECKBOX, OnCheckboxClicked)
  299. ON_EN_CHANGE(IDC_EDIT_REBOOT_MESSAGE, OnChangeEditRebootMessage)
  300. ON_MESSAGE(WM_HELP, OnHelp)
  301. ON_MESSAGE(WM_CONTEXTMENU, OnContextHelp)
  302. //}}AFX_MSG_MAP
  303. END_MESSAGE_MAP()
  304. BOOL CServiceDlgRebootComputer::OnInitDialog()
  305. {
  306. // ISSUE-2002/03/18-JonN handle null m_pData
  307. Assert(m_pData != NULL);
  308. m_uDelayRebootComputer = m_pData->m_minDisplayRebootComputer;
  309. m_strRebootMessage = m_pData->m_strRebootMessage;
  310. TrimString(m_strRebootMessage);
  311. m_fRebootMessage = !m_strRebootMessage.IsEmpty();
  312. CDialog::OnInitDialog();
  313. if (m_strRebootMessage.IsEmpty())
  314. {
  315. // Load a default message
  316. if (NULL != m_pData)
  317. {
  318. TCHAR szName[MAX_COMPUTERNAME_LENGTH + 1];
  319. LPCTSTR pszTargetMachine = L"";
  320. if ( !m_pData->m_strMachineName.IsEmpty() )
  321. {
  322. pszTargetMachine = m_pData->m_strMachineName;
  323. }
  324. else
  325. {
  326. // JonN 11/21/00 PREFIX 226771
  327. DWORD dwSize = sizeof(szName)/sizeof(TCHAR);
  328. ::ZeroMemory( szName, sizeof(szName) );
  329. VERIFY( ::GetComputerName(szName, &dwSize) );
  330. pszTargetMachine = szName;
  331. }
  332. m_strRebootMessage.FormatMessage(
  333. IDS_SVC_REBOOT_MESSAGE_DEFAULT,
  334. m_pData->m_strServiceDisplayName,
  335. pszTargetMachine );
  336. }
  337. else
  338. {
  339. ASSERT(FALSE);
  340. }
  341. }
  342. return TRUE;
  343. }
  344. void CServiceDlgRebootComputer::OnCheckboxClicked()
  345. {
  346. if ( IsDlgButtonChecked(IDC_REBOOT_MESSAGE_CHECKBOX) )
  347. {
  348. SetDlgItemText(IDC_EDIT_REBOOT_MESSAGE, m_strRebootMessage);
  349. }
  350. else
  351. {
  352. CString strTemp;
  353. GetDlgItemText(IDC_EDIT_REBOOT_MESSAGE, OUT strTemp);
  354. if (!strTemp.IsEmpty())
  355. m_strRebootMessage = strTemp;
  356. SetDlgItemText(IDC_EDIT_REBOOT_MESSAGE, _T(""));
  357. }
  358. }
  359. void CServiceDlgRebootComputer::OnChangeEditRebootMessage()
  360. {
  361. LRESULT cch = SendDlgItemMessage(IDC_EDIT_REBOOT_MESSAGE, WM_GETTEXTLENGTH);
  362. if ( (cch==0) != !IsDlgButtonChecked(IDC_REBOOT_MESSAGE_CHECKBOX) )
  363. CheckDlgButton(IDC_REBOOT_MESSAGE_CHECKBOX, (cch!=0));
  364. }
  365. BOOL CServiceDlgRebootComputer::OnHelp(WPARAM /*wParam*/, LPARAM lParam)
  366. {
  367. return DoHelp(lParam, HELP_DIALOG_TOPIC(IDD_SERVICE_REBOOT_COMPUTER));
  368. }
  369. BOOL CServiceDlgRebootComputer::OnContextHelp(WPARAM wParam, LPARAM /*lParam*/)
  370. {
  371. return DoContextHelp(wParam, HELP_DIALOG_TOPIC(IDD_SERVICE_REBOOT_COMPUTER));
  372. }
  373. void CServiceDlgRebootComputer::OnOK()
  374. {
  375. if (!UpdateData())
  376. {
  377. return;
  378. }
  379. Assert(m_pData != NULL);
  380. if (m_uDelayRebootComputer != m_pData->m_minDisplayRebootComputer)
  381. {
  382. m_pData->m_minDisplayRebootComputer = m_uDelayRebootComputer;
  383. m_pData->SetDirty(CServicePropertyData::mskfDirtyRebootMessage);
  384. }
  385. if (!m_fRebootMessage)
  386. {
  387. // No reboot message
  388. m_strRebootMessage.Empty();
  389. }
  390. else
  391. {
  392. TrimString(m_strRebootMessage);
  393. }
  394. if (m_strRebootMessage != m_pData->m_strRebootMessage)
  395. {
  396. m_pData->m_strRebootMessage = m_strRebootMessage;
  397. m_pData->SetDirty(CServicePropertyData::mskfDirtyRebootMessage);
  398. }
  399. EndDialog(IDOK);
  400. } // CServiceDlgRebootComputer::OnOK()