2 * Copyright 2000, International Business Machines Corporation and others.
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
11 #include <afs/param.h>
19 * PROTOTYPES _________________________________________________________________
23 void Advanced_OnInitDialog (HWND hDlg);
24 void Advanced_StartTimer (HWND hDlg);
25 void Advanced_OnServiceTimer (HWND hDlg);
26 void Advanced_OnOpenCPL (HWND hDlg);
27 void Advanced_OnChangeService (HWND hDlg, WORD wCmd);
28 void Advanced_OnStartup (HWND hDlg);
32 * ROUTINES ___________________________________________________________________
36 BOOL CALLBACK Advanced_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
42 GetClientRect (GetParent(hDlg), &rTab);
43 TabCtrl_AdjustRect (GetParent (hDlg), FALSE, &rTab);
44 SetWindowPos (hDlg, NULL, rTab.left, rTab.top, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER);
46 Advanced_OnInitDialog (hDlg);
50 Advanced_OnServiceTimer (hDlg);
56 case IDC_SERVICE_STOP:
57 case IDC_SERVICE_START:
58 case IDC_SERVICE_AUTO:
59 Advanced_OnChangeService (hDlg, LOWORD(wp));
63 Advanced_OnOpenCPL (hDlg);
67 Advanced_OnStartup (hDlg);
71 Advanced_DlgProc (hDlg, WM_HELP, 0, 0);
77 WinHelp (hDlg, g.szHelpFile, HELP_CONTEXT, IDH_AFSCREDS_TAB_ADVANCED);
84 void Advanced_OnInitDialog (HWND hDlg)
86 CheckDlgButton (hDlg, IDC_STARTUP, g.fStartup);
87 Advanced_OnServiceTimer (hDlg);
88 Advanced_StartTimer (hDlg);
92 void Advanced_StartTimer (HWND hDlg)
94 KillTimer (hDlg, ID_SERVICE_TIMER);
95 SetTimer (hDlg, ID_SERVICE_TIMER, (ULONG)cmsecSERVICE, NULL);
99 void Advanced_OnServiceTimer (HWND hDlg)
105 QUERY_SERVICE_CONFIG Config;
108 memset (&Config, 0x00, sizeof(Config));
109 Config.Config.dwStartType = SERVICE_DEMAND_START;
111 SERVICE_STATUS Status;
112 memset (&Status, 0x00, sizeof(Status));
113 Status.dwCurrentState = SERVICE_STOPPED;
116 if ((hManager = OpenSCManager (NULL, NULL, GENERIC_READ)) != NULL)
119 if ((hService = OpenService (hManager, TEXT("TransarcAFSDaemon"), GENERIC_READ)) != NULL)
122 DWORD dwSize = sizeof(Config);
123 QueryServiceConfig (hService, (QUERY_SERVICE_CONFIG*)&Config, sizeof(Config), &dwSize);
124 QueryServiceStatus (hService, &Status);
125 TestAndDoMapShare(Status.dwCurrentState);
127 CloseServiceHandle (hService);
130 CloseServiceHandle (hManager);
135 if ((Status.dwCurrentState == SERVICE_STOP_PENDING) ||
136 (Status.dwCurrentState == SERVICE_START_PENDING))
142 EnableWindow (GetDlgItem (hDlg, IDC_SERVICE_START), fFound && (Status.dwCurrentState == SERVICE_STOPPED));
143 EnableWindow (GetDlgItem (hDlg, IDC_SERVICE_STOP), fFound && (Status.dwCurrentState == SERVICE_RUNNING));
144 EnableWindow (GetDlgItem (hDlg, IDC_SERVICE_AUTO), fFound);
145 CheckDlgButton (hDlg, IDC_SERVICE_AUTO, fFound && (Config.Config.dwStartType == SERVICE_AUTO_START));
147 TCHAR szStatus[cchRESOURCE];
149 GetString (szStatus, IDS_SERVICE_BROKEN);
150 else if (Status.dwCurrentState == SERVICE_RUNNING)
151 GetString (szStatus, IDS_SERVICE_RUNNING);
152 else if (Status.dwCurrentState == SERVICE_STOPPED)
153 GetString (szStatus, IDS_SERVICE_STOPPED);
154 else if (Status.dwCurrentState == SERVICE_STOP_PENDING)
155 GetString (szStatus, IDS_SERVICE_STOPPING);
156 else if (Status.dwCurrentState == SERVICE_START_PENDING)
157 GetString (szStatus, IDS_SERVICE_STARTING);
159 GetString (szStatus, IDS_SERVICE_UNKNOWN);
160 TestAndDoMapShare(Status.dwCurrentState);
161 SetDlgItemText (hDlg, IDC_SERVICE_STATUS, szStatus);
163 if (fFinal && GetWindowLong (hDlg, DWL_USER))
165 SetWindowLong (hDlg, DWL_USER, 0);
166 Main_RepopulateTabs (FALSE);
171 KillTimer (hDlg, ID_SERVICE_TIMER);
176 void Advanced_OnChangeService (HWND hDlg, WORD wCmd)
178 BOOL fSuccess = FALSE;
182 if ((hManager = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS)) != NULL)
185 if ((hService = OpenService (hManager, TEXT("TransarcAFSDaemon"), SERVICE_ALL_ACCESS)) != NULL)
189 case IDC_SERVICE_AUTO:
191 StartType = (IsDlgButtonChecked (hDlg, wCmd)) ? SERVICE_AUTO_START : SERVICE_DEMAND_START;
193 if (ChangeServiceConfig (hService, SERVICE_NO_CHANGE, StartType, SERVICE_NO_CHANGE, 0, 0, 0, 0, 0, 0, 0))
197 case IDC_SERVICE_START:
198 if (StartService (hService, 0, 0))
200 TestAndDoMapShare(SERVICE_START_PENDING);
205 case IDC_SERVICE_STOP:
206 SERVICE_STATUS Status;
207 TestAndDoUnMapShare();
208 ControlService (hService, SERVICE_CONTROL_STOP, &Status);
213 CloseServiceHandle (hService);
216 CloseServiceHandle (hManager);
221 if (wCmd == IDC_SERVICE_STOP)
222 SetWindowLong (hDlg, DWL_USER, TRUE);
223 Advanced_OnServiceTimer (hDlg);
224 Advanced_StartTimer (hDlg);
229 error = GetLastError();
234 case IDC_SERVICE_START:
235 ids = IDS_SERVICE_FAIL_START;
237 case IDC_SERVICE_STOP:
238 ids = IDS_SERVICE_FAIL_STOP;
241 ids = IDS_SERVICE_FAIL_CONFIG;
245 Message (MB_OK | MB_ICONHAND, IDS_SERVICE_ERROR, ids, TEXT("%08lX"), error);
250 void Advanced_OnOpenCPL (HWND hDlg)
252 WinExec ("afs_config.exe", SW_SHOW);
256 void Advanced_OnStartup (HWND hDlg)
258 g.fStartup = IsDlgButtonChecked (hDlg, IDC_STARTUP);
261 if (RegCreateKey (HKEY_LOCAL_MACHINE, TEXT("System\\CurrentControlSet\\Services\\TransarcAFSDaemon\\Parameters"), &hk) == 0)
263 DWORD dwSize = sizeof(g.fStartup);
264 DWORD dwType = REG_DWORD;
265 RegSetValueEx (hk, TEXT("ShowTrayIcon"), NULL, dwType, (PBYTE)&g.fStartup, dwSize);
269 Shortcut_FixStartup (cszSHORTCUT_NAME, g.fStartup);