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>
16 #include "..\afsreg\afsreg.h" // So we can see if the server's installed
24 * DEFINITIONS ________________________________________________________________
28 const TCHAR cszCLASSNAME[] = TEXT("AfsCreds");
32 * VARIABLES __________________________________________________________________
40 * PROTOTYPES _________________________________________________________________
44 BOOL InitApp (LPSTR pszCmdLineA);
47 void PumpMessage (MSG *pmsg);
48 BOOL IsServerInstalled (void);
52 * ROUTINES ___________________________________________________________________
56 int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR pCmdLine, int nCmdShow)
59 TaLocale_LoadCorrespondingModule (hInst);
61 if (InitApp (pCmdLine))
64 while (GetMessage (&msg, NULL, 0, 0) > 0)
76 #define ISHIGHSECURITY(v) ( ((v) & LOGON_OPTION_HIGHSECURITY)==LOGON_OPTION_HIGHSECURITY)
77 #define REG_CLIENT_PROVIDER_KEY "SYSTEM\\CurrentControlSet\\Services\\TransarcAFSDaemon\\NetworkProvider"
79 BOOL InitApp (LPSTR pszCmdLineA)
84 BOOL fInstall = FALSE;
85 BOOL fUninstall = FALSE;
87 // Parse the command-line
89 while (pszCmdLineA && *pszCmdLineA)
91 if ((*pszCmdLineA != '-') && (*pszCmdLineA != '/'))
94 switch (*(++pszCmdLineA))
121 MapShareName(pszCmdLineA);
126 DWORD LSPtype, LSPsize;
128 LSPsize=sizeof(LogonOption);
129 (void) RegOpenKeyEx(HKEY_LOCAL_MACHINE, REG_CLIENT_PROVIDER_KEY,
130 0, KEY_QUERY_VALUE, &NPKey);
131 RegQueryValueEx(NPKey, "LogonOptions", NULL,
132 &LSPtype, (LPBYTE)&LogonOption, &LSPsize);
134 if (ISHIGHSECURITY(LogonOption))
140 while (*pszCmdLineA && (*pszCmdLineA != ' '))
142 if (*pszCmdLineA==' ') ++pszCmdLineA;
146 Shortcut_FixStartup (cszSHORTCUT_NAME, g.fStartup = TRUE);
148 Shortcut_FixStartup (cszSHORTCUT_NAME, g.fStartup = FALSE);
153 if (RegCreateKey (HKEY_LOCAL_MACHINE, TEXT("System\\CurrentControlSet\\Services\\TransarcAFSDaemon\\Parameters"), &hk) == 0)
155 DWORD dwSize = sizeof(g.fStartup);
156 DWORD dwType = REG_DWORD;
157 RegSetValueEx (hk, TEXT("ShowTrayIcon"), NULL, dwType, (PBYTE)&g.fStartup, dwSize);
162 // Only show up if there's not another version of this app around already.
164 for (HWND hSearch = GetWindow (GetDesktopWindow(), GW_CHILD);
165 hSearch && IsWindow(hSearch);
166 hSearch = GetWindow (hSearch, GW_HWNDNEXT))
168 TCHAR szClassName[ cchRESOURCE ];
169 if (GetClassName (hSearch, szClassName, cchRESOURCE))
171 if (!lstrcmpi (szClassName, cszCLASSNAME))
174 PostMessage (hSearch, WM_COMMAND, M_ACTIVATE, 0);
176 PostMessage (hSearch, WM_COMMAND, M_TERMINATE_NOW, 0);
178 PostMessage (hSearch, WM_COMMAND, M_TERMINATE_NOW, 0);
184 if (fExit || fUninstall || fInstall)
187 // Initialize our global variables and window classes
189 memset (&g, 0x00, sizeof(g));
193 if (RegOpenKey (HKEY_LOCAL_MACHINE, TEXT("System\\CurrentControlSet\\Services\\TransarcAFSDaemon\\Parameters"), &hk) == 0)
195 DWORD dwSize = sizeof(g.fStartup);
196 DWORD dwType = REG_DWORD;
197 RegQueryValueEx (hk, TEXT("ShowTrayIcon"), NULL, &dwType, (PBYTE)&g.fStartup, &dwSize);
201 Shortcut_FixStartup (cszSHORTCUT_NAME, g.fStartup);
203 // Is this Windows NT?
205 OSVERSIONINFO Version;
206 memset (&Version, 0x00, sizeof(Version));
207 Version.dwOSVersionInfoSize = sizeof(Version);
208 if (GetVersionEx (&Version))
209 g.fIsWinNT = (Version.dwPlatformId == VER_PLATFORM_WIN32_NT) ? TRUE : FALSE;
212 lstrcpy (g.szHelpFile, TEXT("afs-light.hlp"));
214 lstrcpy (g.szHelpFile, TEXT("afs-nt.hlp"));
216 // Initialize winsock etc
219 WSAStartup (0x0101, &Data);
221 InitCommonControls();
222 RegisterCheckListClass();
224 // Create a main window. All further initialization will be done during
225 // processing of WM_INITDIALOG.
228 if (!GetClassInfo (NULL, WC_DIALOG, &wc)) // Get dialog class info
230 wc.hInstance = THIS_HINST;
231 wc.hIcon = TaLocale_LoadIcon (IDI_MAIN);
232 wc.lpszClassName = cszCLASSNAME;
233 wc.style |= CS_GLOBALCLASS;
236 g.hMain = ModelessDialog (IDD_MAIN, NULL, (DLGPROC)Main_DlgProc);
240 // If the service isn't started yet, show our startup wizard.
242 if (!IsServiceRunning() && !fQuiet)
245 Message (MB_ICONHAND, IDS_UNCONFIG_TITLE_95, IDS_UNCONFIG_DESC_95);
246 else if (IsServiceConfigured())
248 else if (!IsServerInstalled())
249 Message (MB_ICONHAND, IDS_UNCONFIG_TITLE, IDS_UNCONFIG_DESC);
251 if (IsServiceRunning() && fShow)
266 void PumpMessage (MSG *pmsg)
268 if (!IsMemoryManagerMessage (pmsg))
270 if (!IsDialogMessage (g.hMain, pmsg))
272 TranslateMessage (pmsg);
273 DispatchMessage (pmsg);
281 if (IsWindow (g.hMain))
283 ChangeTrayIcon (NIM_DELETE);
284 DestroyWindow (g.hMain);
290 BOOL IsServerInstalled (void)
292 BOOL fInstalled = FALSE;
294 TCHAR szKey[] = AFSREG_SVR_SVC_KEY;
295 LPCTSTR pch = lstrchr (szKey, TEXT('\\'));
298 if (RegOpenKey (HKEY_LOCAL_MACHINE, &pch[1], &hk) == 0)