LINUX: afs_create infinite fetchStatus loop
[pkg-k5-afs_openafs.git] / src / WINNT / client_config / tab_general.cpp
blob89118e866a8b6bce86a507a27d5a54a907848e0c
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
8 */
10 #include <winsock2.h>
11 #include <ws2tcpip.h>
13 extern "C" {
14 #include <afsconfig.h>
15 #include <afs/param.h>
16 #include <roken.h>
17 #include <afs/stds.h>
18 #include <afs/cm.h>
19 #include <rx/rxkad.h>
20 #include <afs/cm_config.h>
23 #include "afs_config.h"
24 #include "tab_general.h"
25 #include "tab_hosts.h"
26 #include "tab_advanced.h"
28 #include "drivemap.h"
29 #include <adssts.h>
32 * VARIABLES __________________________________________________________________
36 static struct l
38 BOOL fWarnIfStopped;
39 BOOL fWarnIfNotStopped;
40 BOOL fRestartIfStopped;
41 BOOL fServiceIsRunning;
42 BOOL fStarting;
43 HWND hStatus;
44 } l;
48 * DEFINITIONS ________________________________________________________________
52 #define ID_TIMER 0
54 #define cmsecIDLE_REFRESH 10000
55 #define cmsecFAST_REFRESH 1000
59 * PROTOTYPES _________________________________________________________________
63 void GeneralTab_OnInitDialog (HWND hDlg);
64 void GeneralTab_OnTimer (HWND hDlg);
65 BOOL GeneralTab_OnApply (HWND hDlg, BOOL fForce, BOOL fComplainIfInvalid);
66 void GeneralTab_OnRefresh (HWND hDlg, BOOL fRequery);
67 void GeneralTab_OnStartStop (HWND hDlg, BOOL fStart);
68 void GeneralTab_OnConnect (HWND hDlg);
69 void GeneralTab_OnGateway (HWND hDlg);
70 void GeneralTab_OnCell (HWND hDlg);
72 void GeneralTab_DoStartStop (HWND hDlg, BOOL fStart, BOOL fRestart);
73 void GeneralTab_FixRefreshTimer (HWND hDlg, UINT cmsec = 0);
74 DWORD GeneralTab_GetDisplayState (HWND hDlg);
75 void GeneralTab_ShowCurrentState (HWND hDlg);
76 BOOL GeneralTab_AskIfStopped (HWND hDlg);
78 BOOL fIsCellInCellServDB (LPCTSTR pszCell);
80 BOOL CALLBACK Status_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
81 void Status_OnRefresh (HWND hDlg);
84 * ROUTINES ___________________________________________________________________
88 BOOL CALLBACK GeneralTab_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
90 switch (msg)
92 case WM_INITDIALOG:
93 Main_OnInitDialog (GetParent(hDlg));
94 GeneralTab_OnInitDialog (hDlg);
95 break;
97 case WM_DESTROY:
98 GeneralTab_FixRefreshTimer (hDlg, 0);
99 break;
101 case WM_TIMER:
102 GeneralTab_OnTimer (hDlg);
103 break;
105 case WM_COMMAND:
106 switch (LOWORD(wp))
108 case IDAPPLY:
109 if (!GeneralTab_OnApply (hDlg, FALSE, TRUE))
110 SetWindowLongPtr (hDlg, DWLP_MSGRESULT, TRUE);
111 else if (g.fIsWinNT && !GeneralTab_AskIfStopped (hDlg))
112 SetWindowLongPtr (hDlg, DWLP_MSGRESULT, TRUE);
113 break;
115 case IDC_REFRESH:
116 GeneralTab_OnRefresh (hDlg, FALSE);
117 break;
119 case IDC_SERVICE_START:
120 GeneralTab_OnStartStop (hDlg, TRUE);
121 break;
123 case IDC_SERVICE_STOP:
124 GeneralTab_OnStartStop (hDlg, FALSE);
125 break;
127 case IDC_GATEWAY_CONN:
128 GeneralTab_OnConnect (hDlg);
129 break;
131 case IDC_GATEWAY:
132 GeneralTab_OnGateway (hDlg);
133 break;
135 case IDC_CELL:
136 GeneralTab_OnCell (hDlg);
137 break;
139 case IDHELP:
140 GeneralTab_DlgProc (hDlg, WM_HELP, 0, 0);
141 break;
143 break;
145 case WM_HELP:
146 if (g.fIsWinNT)
147 WinHelp (hDlg, g.szHelpFile, HELP_CONTEXT, IDH_AFSCONFIG_GENERAL_NT);
148 else
149 WinHelp (hDlg, g.szHelpFile, HELP_CONTEXT, IDH_AFSCONFIG_GENERAL_95);
150 break;
153 return FALSE;
157 void GeneralTab_OnInitDialog (HWND hDlg)
159 DWORD CurrentState = Config_GetServiceState();
160 BOOL fNeedFastRefresh = ((CurrentState == SERVICE_STOPPED) || (CurrentState == SERVICE_RUNNING)) ? FALSE : TRUE;
161 GeneralTab_FixRefreshTimer (hDlg, ((fNeedFastRefresh) ? cmsecFAST_REFRESH : cmsecIDLE_REFRESH));
162 GeneralTab_OnTimer (hDlg);
163 GeneralTab_OnRefresh (hDlg, TRUE);
167 BOOL GeneralTab_VerifyCell (HWND hDlg, BOOL fComplainIfInvalid, LPCTSTR pszCell)
169 TCHAR szNoCell[ cchRESOURCE ];
170 GetString (szNoCell, IDS_CELL_UNKNOWN);
172 TCHAR szCell[ cchRESOURCE ];
173 if (pszCell)
174 lstrcpy (szCell, pszCell);
175 else
176 GetDlgItemText (hDlg, IDC_CELL, szCell, cchRESOURCE);
177 if ((!szCell[0]) || (!lstrcmpi (szNoCell, szCell)))
179 if (fComplainIfInvalid)
181 if (g.fIsWinNT)
182 Message (MB_ICONASTERISK | MB_OK, GetErrorTitle(), IDS_NOCELL_DESC);
183 else
184 Message (MB_ICONASTERISK | MB_OK, GetErrorTitle(), IDS_BADGATEWAY_DESC);
186 return FALSE;
189 if (!fIsCellInCellServDB (szCell))
191 if (fComplainIfInvalid)
193 if (g.fIsWinNT)
194 Message (MB_ICONASTERISK | MB_OK, GetErrorTitle(), IDS_BADCELL_DESC);
195 else
196 Message (MB_ICONASTERISK | MB_OK, GetErrorTitle(), IDS_BADGWCELL_DESC, TEXT("%s"), szCell);
198 return FALSE;
201 return TRUE;
205 BOOL GeneralTab_VerifyOK (HWND hDlg, BOOL fComplainIfInvalid)
207 // If it's Windows 95, make sure there's a valid Gateway entry
209 if (!g.fIsWinNT)
211 TCHAR szGateway[ cchRESOURCE ];
212 GetDlgItemText (hDlg, IDC_GATEWAY, szGateway, cchRESOURCE);
213 if (!szGateway[0])
215 if (fComplainIfInvalid)
216 Message (MB_ICONASTERISK | MB_OK, IDS_NOGATEWAY_TITLE, IDS_NOGATEWAY_DESC);
217 return FALSE;
221 // Make sure the cell is in our CellServDB.
223 if (g.fIsWinNT)
225 if (!GeneralTab_VerifyCell (hDlg, fComplainIfInvalid, NULL))
226 return FALSE;
229 return TRUE;
232 BOOL GeneralTab_OnApply (HWND hDlg, BOOL fForce, BOOL fComplainIfInvalid)
234 if (!fForce)
236 // Don't try to do anything if we've already failed the apply
237 if (GetWindowLongPtr (hDlg, DWLP_MSGRESULT))
238 return FALSE;
241 // If the user has changed CellServDB, configuration parameters for
242 // the driver or anything else, we want to commit those changes first.
243 // We *won't* commit server prefs changes yet, because we haven't yet
244 // checked to see if the service is running.
246 if (!HostsTab_CommitChanges (fForce))
247 return FALSE;
249 if (!AdvancedTab_CommitChanges (fForce))
250 return FALSE;
252 if (!GeneralTab_VerifyOK (hDlg, fComplainIfInvalid))
253 return FALSE;
255 TCHAR szText[ MAX_PATH ];
257 if (g.fIsWinNT)
259 GetDlgItemText (hDlg, IDC_CELL, szText, MAX_PATH);
260 if (lstrcmpi (szText, g.Configuration.szCell))
262 if (!Config_SetCellName (szText))
263 return FALSE;
264 lstrcpy (g.Configuration.szCell, szText);
268 BOOL fLogonAuthent = IsDlgButtonChecked (hDlg, IDC_LOGON);
269 if (fLogonAuthent != g.Configuration.fLogonAuthent)
271 SetBitLogonOption(fLogonAuthent,LOGON_OPTION_INTEGRATED);
272 g.Configuration.fLogonAuthent = fLogonAuthent;
275 if (GetDlgItem(hDlg, IDC_TRAYICON) != NULL)
276 Config_SetTrayIconFlag (IsDlgButtonChecked(hDlg, IDC_TRAYICON));
278 if (g.fIsWinNT)
280 BOOL fBeGateway = IsDlgButtonChecked (hDlg, IDC_GATEWAY);
281 if (fBeGateway != g.Configuration.fBeGateway)
283 if (!Config_SetGatewayFlag (fBeGateway))
284 return FALSE;
285 g.fNeedRestart = TRUE;
286 g.Configuration.fBeGateway = fBeGateway;
289 else // (!g.fIsWinNT)
291 GetDlgItemText (hDlg, IDC_GATEWAY, szText, MAX_PATH);
292 if (lstrcmpi (szText, g.Configuration.szGateway))
294 TCHAR szNewCell[ MAX_PATH ];
295 if (!Config_ContactGateway (szText, szNewCell))
297 Message (MB_ICONASTERISK | MB_OK, GetErrorTitle(), IDS_BADGATEWAY_DESC);
298 return FALSE;
301 if (!GeneralTab_VerifyCell (hDlg, fComplainIfInvalid, szNewCell))
302 return FALSE;
304 if (!Config_SetGatewayName (szText))
305 return FALSE;
307 if (!Config_SetCellName (szNewCell))
308 return FALSE;
310 Config_FixGatewayDrives();
312 SetDlgItemText (hDlg, IDC_CELL, szNewCell);
313 lstrcpy (g.Configuration.szGateway, szText);
314 lstrcpy (g.Configuration.szCell, szNewCell);
316 GeneralTab_OnGateway (hDlg);
320 return TRUE;
324 void GeneralTab_OnRefresh (HWND hDlg, BOOL fRequery)
326 // If necessary, update any fields in g.Configuration that we care about
328 if (fRequery)
330 if (g.fIsWinNT)
331 Config_GetGatewayFlag (&g.Configuration.fBeGateway);
332 else
333 Config_GetGatewayName (g.Configuration.szGateway);
335 Config_GetCellName (g.Configuration.szCell);
336 g.Configuration.fLogonAuthent=RWLogonOption(TRUE,LOGON_OPTION_INTEGRATED);
337 Config_GetTrayIconFlag (&g.Configuration.fShowTrayIcon);
339 if (!g.fIsWinNT)
340 SetDlgItemText (hDlg, IDC_GATEWAY, g.Configuration.szGateway);
341 else
342 CheckDlgButton (hDlg, IDC_GATEWAY, g.Configuration.fBeGateway);
344 SetDlgItemText (hDlg, IDC_CELL, g.Configuration.szCell);
345 CheckDlgButton (hDlg, IDC_LOGON, g.Configuration.fLogonAuthent);
346 CheckDlgButton (hDlg, IDC_TRAYICON, g.Configuration.fShowTrayIcon);
349 // Update our display of the service's status
351 DWORD CurrentState = Config_GetServiceState();
352 BOOL fIfServiceStopped = !(g.fIsWinNT && !g.fIsAdmin);
353 BOOL fIfServiceRunning = fIfServiceStopped && (CurrentState == SERVICE_RUNNING);
355 GeneralTab_ShowCurrentState (hDlg);
357 EnableWindow (GetDlgItem (hDlg, IDC_CELL), fIfServiceStopped && g.fIsWinNT);
359 EnableWindow (GetDlgItem (hDlg, IDC_LOGON), fIfServiceStopped);
360 EnableWindow (GetDlgItem (hDlg, IDC_GATEWAY), fIfServiceStopped);
362 // Update our warning. Note that under WinNT, this tab doesn't have any
363 // controls (other than Start Service) which disable just because the
364 // service isn't running...so don't show that warning in that case.
366 TCHAR szText[ cchRESOURCE ];
367 if ((!g.fIsWinNT) && (CurrentState != SERVICE_RUNNING))
369 GetString (szText, IDS_WARN_STOPPED);
370 SetDlgItemText (hDlg, IDC_WARN, szText);
371 ShowWindow (GetDlgItem (hDlg, IDC_WARN), SW_SHOW);
373 else if (g.fIsWinNT && !g.fIsAdmin)
375 GetString (szText, IDS_WARN_ADMIN);
376 SetDlgItemText (hDlg, IDC_WARN, szText);
377 ShowWindow (GetDlgItem (hDlg, IDC_WARN), SW_SHOW);
379 else // ((CurrentState == SERVICE_RUNNING) && (g.fIsAdmin))
381 ShowWindow (GetDlgItem (hDlg, IDC_WARN), SW_HIDE);
384 GeneralTab_OnGateway (hDlg);
386 // If the service isn't running/stopped, we may need to complain
388 if ((CurrentState == SERVICE_RUNNING) && (l.fWarnIfNotStopped))
390 Message (MB_ICONHAND, GetErrorTitle(), IDS_SERVICE_FAIL_STOP, TEXT("%08lX"), ERROR_SERVICE_SPECIFIC_ERROR);
392 else if ((CurrentState == SERVICE_STOPPED) && (l.fWarnIfStopped))
394 Message (MB_ICONHAND, GetErrorTitle(), IDS_SERVICE_FAIL_START, TEXT("%08lX"), ERROR_SERVICE_SPECIFIC_ERROR);
397 if ((CurrentState == SERVICE_RUNNING) || (CurrentState == SERVICE_STOPPED))
399 BOOL fRestart = ((CurrentState == SERVICE_STOPPED) && (l.fRestartIfStopped));
400 l.fWarnIfStopped = FALSE;
401 l.fWarnIfNotStopped = FALSE;
402 l.fRestartIfStopped = FALSE;
403 l.fServiceIsRunning = (CurrentState == SERVICE_RUNNING);
405 if (fRestart)
407 GeneralTab_DoStartStop (hDlg, TRUE, FALSE);
413 void GeneralTab_OnTimer (HWND hDlg)
415 DWORD CurrentState = Config_GetServiceState();
416 DWORD DisplayState = GeneralTab_GetDisplayState(hDlg);
417 TestAndDoMapShare(CurrentState); //Re map mounted drives if necessary
419 BOOL fInEndState = ((CurrentState == SERVICE_RUNNING) || (CurrentState == SERVICE_STOPPED));
420 if (fInEndState && l.hStatus)
422 if (IsWindow (l.hStatus))
423 DestroyWindow (l.hStatus);
424 l.hStatus = NULL;
426 else if (!fInEndState && !l.hStatus)
428 l.hStatus = ModelessDialog (IDD_STARTSTOP, GetParent (hDlg), (DLGPROC)Status_DlgProc);
431 if (CurrentState != DisplayState)
433 GeneralTab_OnRefresh (hDlg, FALSE);
434 Main_RefreshAllTabs();
436 if (l.hStatus && IsWindow (l.hStatus))
437 PostMessage (l.hStatus, WM_COMMAND, IDINIT, 0);
440 BOOL fNeedFastRefresh = ((CurrentState == SERVICE_STOPPED) || (CurrentState == SERVICE_RUNNING)) ? FALSE : TRUE;
441 BOOL fHaveFastRefresh = ((DisplayState == SERVICE_STOPPED) || (DisplayState == SERVICE_RUNNING)) ? FALSE : TRUE;
443 if (fNeedFastRefresh != fHaveFastRefresh)
445 GeneralTab_FixRefreshTimer (hDlg, ((fNeedFastRefresh) ? cmsecFAST_REFRESH : cmsecIDLE_REFRESH));
450 void GeneralTab_OnStartStop (HWND hDlg, BOOL fStart)
452 BOOL fSuccess = FALSE;
453 ULONG error = 0;
455 // Don't let the user stop the service on a whim; warn him first
457 if (!fStart)
459 if (Message (MB_ICONEXCLAMATION | MB_OKCANCEL, GetCautionTitle(), IDS_STOP_DESC) != IDOK)
460 return;
463 // To start the service, we'll need to successfully commit our new
464 // configuration. To stop the service, we'll *try*, but it's not
465 // fatal if something goes wrong.
467 if (!GeneralTab_OnApply (hDlg, TRUE, ((fStart) ? TRUE : FALSE)))
469 if (fStart)
470 return;
473 // Okay, start the service
475 GeneralTab_DoStartStop (hDlg, fStart, FALSE);
479 void GeneralTab_OnConnect (HWND hDlg)
481 if (!GeneralTab_OnApply (hDlg, TRUE, TRUE))
482 return;
483 GeneralTab_OnGateway (hDlg);
484 GeneralTab_OnApply (hDlg, TRUE, TRUE);
488 void GeneralTab_OnGateway (HWND hDlg)
490 if (!g.fIsWinNT)
492 TCHAR szGateway[ cchRESOURCE ];
493 GetDlgItemText (hDlg, IDC_GATEWAY, szGateway, cchRESOURCE);
495 BOOL fEnable = TRUE;
496 if (!szGateway[0])
497 fEnable = FALSE;
498 if (!lstrcmpi (szGateway, g.Configuration.szGateway))
499 fEnable = FALSE;
500 EnableWindow (GetDlgItem (hDlg, IDC_GATEWAY_CONN), fEnable);
505 void GeneralTab_OnCell (HWND hDlg)
507 if (g.fIsWinNT)
509 GeneralTab_ShowCurrentState (hDlg);
514 void GeneralTab_FixRefreshTimer (HWND hDlg, UINT cmsec)
516 static BOOL fTimerActive = FALSE;
517 if (fTimerActive)
519 KillTimer (hDlg, ID_TIMER);
520 fTimerActive = FALSE;
523 if (g.fIsWinNT && (cmsec != 0))
525 SetTimer (hDlg, ID_TIMER, cmsec, NULL);
530 DWORD GeneralTab_GetDisplayState (HWND hDlg)
532 TCHAR szText[ cchRESOURCE ];
533 TCHAR szTextNow[ cchRESOURCE ];
534 GetDlgItemText (hDlg, IDC_STATUS, szTextNow, cchRESOURCE);
536 GetString (szText, IDS_STATE_STOPPED);
537 if (!lstrcmpi (szTextNow, szText))
538 return SERVICE_STOPPED;
540 GetString (szText, IDS_STATE_RUNNING);
541 if (!lstrcmpi (szTextNow, szText))
542 return SERVICE_RUNNING;
544 GetString (szText, IDS_STATE_STARTING);
545 if (!lstrcmpi (szTextNow, szText))
546 return SERVICE_START_PENDING;
548 GetString (szText, IDS_STATE_STOPPING);
549 if (!lstrcmpi (szTextNow, szText))
550 return SERVICE_STOP_PENDING;
552 return 0;
556 void GeneralTab_ShowCurrentState (HWND hDlg)
558 TCHAR szNoCell[ cchRESOURCE ];
559 GetString (szNoCell, IDS_CELL_UNKNOWN);
561 TCHAR szCell[ cchRESOURCE ];
562 GetDlgItemText (hDlg, IDC_CELL, szCell, cchRESOURCE);
564 BOOL fValidCell = TRUE;
565 if (!szCell[0])
566 fValidCell = FALSE;
567 if (!lstrcmpi (szCell, szNoCell))
568 fValidCell = FALSE;
570 DWORD CurrentState = Config_GetServiceState();
572 TCHAR szText[ cchRESOURCE ];
573 switch (CurrentState)
575 case SERVICE_STOPPED:
576 GetString (szText, (fValidCell) ? IDS_STATE_STOPPED : IDS_STOPPED_NOCELL);
577 break;
578 case SERVICE_RUNNING:
579 GetString (szText, IDS_STATE_RUNNING);
580 break;
581 case SERVICE_START_PENDING:
582 GetString (szText, IDS_STATE_STARTING);
583 break;
584 case SERVICE_STOP_PENDING:
585 GetString (szText, IDS_STATE_STOPPING);
586 break;
587 default:
588 GetString (szText, IDS_STATE_UNKNOWN);
589 break;
591 SetDlgItemText (hDlg, IDC_STATUS, szText);
593 // Enable or disable controls as necessary
595 BOOL fIfServiceStopped = !(g.fIsWinNT && !g.fIsAdmin);
596 BOOL fIfServiceRunning = fIfServiceStopped && (CurrentState == SERVICE_RUNNING);
598 EnableWindow (GetDlgItem (hDlg, IDC_SERVICE_START), ((CurrentState == SERVICE_STOPPED) && (g.fIsAdmin) && (fValidCell)));
599 EnableWindow (GetDlgItem (hDlg, IDC_SERVICE_STOP), ((CurrentState == SERVICE_RUNNING) && (g.fIsAdmin)));
603 BOOL GeneralTab_AskIfStopped (HWND hDlg)
605 BOOL fStopService = FALSE;
606 BOOL fStartService = FALSE;
608 // If we changed things, ask if we should restart the service.
609 // Otherwise, if it's stopped, ask the user if we should start the service.
611 DWORD CurrentState = Config_GetServiceState();
612 if (g.fIsAdmin)
614 if ((CurrentState == SERVICE_RUNNING) && (g.fNeedRestart))
616 if (Message (MB_YESNO | MB_ICONQUESTION, IDS_RESTART_TITLE, IDS_RESTART_DESC) == IDYES)
618 fStopService = TRUE;
619 fStartService = TRUE;
622 if (CurrentState == SERVICE_STOPPED)
624 if (Message (MB_YESNO | MB_ICONQUESTION, GetCautionTitle(), IDS_OKSTOP_DESC) == IDYES)
626 fStartService = TRUE;
631 // If we need to, start or stop-n-restart the service
633 if (fStartService && fStopService)
635 GeneralTab_DoStartStop (hDlg, FALSE, TRUE); // Stop and restart the thing
637 else if (fStartService && !fStopService)
639 GeneralTab_DoStartStop (hDlg, TRUE, FALSE); // Just start it
642 if (fStartService)
644 while ( (l.fRestartIfStopped) ||
645 (l.fWarnIfNotStopped) ||
646 (l.fWarnIfStopped) )
648 MSG msg;
649 if (!GetMessage (&msg, NULL, 0, 0))
650 break;
651 if (IsMemoryManagerMessage (&msg))
652 continue;
653 TranslateMessage (&msg);
654 DispatchMessage (&msg);
658 if (fStartService && !l.fServiceIsRunning)
659 return FALSE;
661 return TRUE;
665 BOOL fIsCellInCellServDB (LPCTSTR pszCell)
667 BOOL fFound = FALSE;
668 CELLSERVDB CellServDB;
669 char cellname[256], i;
671 /* we pray for all ascii cellnames */
672 for ( i=0 ; pszCell[i] && i < (sizeof(cellname)-1) ; i++ )
673 cellname[i] = pszCell[i];
674 cellname[i] = '\0';
676 ULONG code = cm_SearchCellRegistry(1, cellname, NULL, NULL, NULL, NULL);
677 if (code == 0)
678 fFound = TRUE;
679 if (!fFound &&
680 (code != CM_ERROR_FORCE_DNS_LOOKUP) &&
681 CSDB_ReadFile (&CellServDB, NULL))
683 if (CSDB_FindCell (&CellServDB, pszCell))
684 fFound = TRUE;
685 CSDB_FreeFile (&CellServDB);
687 if ( fFound == FALSE ) {
688 int ttl;
689 fFound = !cm_SearchCellByDNS(cellname, NULL, &ttl, NULL, NULL);
691 done:
693 return fFound;
697 void GeneralTab_DoStartStop (HWND hDlg, BOOL fStart, BOOL fRestart)
699 BOOL fSuccess = FALSE;
700 ULONG error = 0;
702 SC_HANDLE hManager;
703 if ((hManager = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS)) != NULL)
705 SC_HANDLE hService;
706 if ((hService = OpenService (hManager, TEXT("TransarcAFSDaemon"), SERVICE_ALL_ACCESS)) != NULL)
708 if (fStart)
710 g.fNeedRestart = FALSE;
711 if (StartService (hService, 0, 0))
712 TestAndDoMapShare(SERVICE_START_PENDING);
713 fSuccess = TRUE;
715 else // (!fStart)
717 SERVICE_STATUS Status;
718 if (ControlService (hService, SERVICE_CONTROL_STOP, &Status))
719 fSuccess = TRUE;
720 if (g.Configuration.fLogonAuthent)
721 DoUnMapShare(FALSE);
724 CloseServiceHandle (hService);
727 CloseServiceHandle (hManager);
730 if (fSuccess)
732 l.fWarnIfStopped = fStart;
733 l.fWarnIfNotStopped = !fStart;
734 l.fRestartIfStopped = fRestart && !fStart;
735 l.fStarting = fStart;
736 GeneralTab_OnTimer (hDlg);
738 else
740 l.fWarnIfStopped = FALSE;
741 l.fWarnIfNotStopped = FALSE;
742 l.fRestartIfStopped = FALSE;
743 GeneralTab_OnTimer (hDlg);
745 if (!error)
746 error = GetLastError();
747 Message (MB_OK | MB_ICONHAND, GetErrorTitle(), ((fStart) ? IDS_SERVICE_FAIL_START : IDS_SERVICE_FAIL_STOP), TEXT("%08lX"), error);
752 BOOL CALLBACK Status_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
754 switch (msg)
756 case WM_INITDIALOG:
757 l.hStatus = hDlg;
758 ShowWindow (l.hStatus, SW_SHOW);
759 Status_OnRefresh (hDlg);
760 break;
762 case WM_DESTROY:
763 l.hStatus = NULL;
764 break;
766 case WM_COMMAND:
767 switch (LOWORD(wp))
769 case IDCANCEL:
770 DestroyWindow (hDlg);
771 break;
773 case IDINIT:
774 Status_OnRefresh (hDlg);
775 break;
777 break;
780 return FALSE;
784 void Status_OnRefresh (HWND hDlg)
786 DWORD CurrentState = Config_GetServiceState();
787 if (CurrentState == SERVICE_START_PENDING)
788 l.fStarting = TRUE;
789 else if (CurrentState == SERVICE_STOP_PENDING)
790 l.fStarting = FALSE;
792 ShowWindow (GetDlgItem (l.hStatus, IDC_STARTING), l.fStarting);
793 ShowWindow (GetDlgItem (l.hStatus, IDC_STOPPING), !l.fStarting);