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.

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