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
20 * DEFINITIONS ________________________________________________________________
24 const TCHAR cszCLASSNAME[] = TEXT("AfsCreds");
28 * VARIABLES __________________________________________________________________
36 * PROTOTYPES _________________________________________________________________
40 BOOL InitApp (LPSTR pszCmdLineA);
43 void PumpMessage (MSG *pmsg);
44 BOOL IsServerInstalled (void);
48 * ROUTINES ___________________________________________________________________
52 int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR pCmdLine, int nCmdShow)
55 TaLocale_LoadCorrespondingModule (hInst);
57 if (InitApp (pCmdLine))
60 while (GetMessage (&msg, NULL, 0, 0) > 0)
73 BOOL InitApp (LPSTR pszCmdLineA)
78 BOOL fInstall = FALSE;
79 BOOL fUninstall = FALSE;
81 // Parse the command-line
83 while (pszCmdLineA && *pszCmdLineA)
85 if ((*pszCmdLineA != '-') && (*pszCmdLineA != '/'))
88 switch (*(++pszCmdLineA))
116 while (*pszCmdLineA && (*pszCmdLineA != ' '))
121 Shortcut_FixStartup (cszSHORTCUT_NAME, g.fStartup = TRUE);
123 Shortcut_FixStartup (cszSHORTCUT_NAME, g.fStartup = FALSE);
128 if (RegCreateKey (HKEY_LOCAL_MACHINE, TEXT("System\\CurrentControlSet\\Services\\TransarcAFSDaemon\\Parameters"), &hk) == 0)
130 DWORD dwSize = sizeof(g.fStartup);
131 DWORD dwType = REG_DWORD;
132 RegSetValueEx (hk, TEXT("ShowTrayIcon"), NULL, dwType, (PBYTE)&g.fStartup, dwSize);
137 // Only show up if there's not another version of this app around already.
139 for (HWND hSearch = GetWindow (GetDesktopWindow(), GW_CHILD);
140 hSearch && IsWindow(hSearch);
141 hSearch = GetWindow (hSearch, GW_HWNDNEXT))
143 TCHAR szClassName[ cchRESOURCE ];
144 if (GetClassName (hSearch, szClassName, cchRESOURCE))
146 if (!lstrcmpi (szClassName, cszCLASSNAME))
149 PostMessage (hSearch, WM_COMMAND, M_ACTIVATE, 0);
151 PostMessage (hSearch, WM_COMMAND, M_TERMINATE_NOW, 0);
153 PostMessage (hSearch, WM_COMMAND, M_TERMINATE_NOW, 0);
159 if (fExit || fUninstall || fInstall)
162 // Initialize our global variables and window classes
164 memset (&g, 0x00, sizeof(g));
168 if (RegOpenKey (HKEY_LOCAL_MACHINE, TEXT("System\\CurrentControlSet\\Services\\TransarcAFSDaemon\\Parameters"), &hk) == 0)
170 DWORD dwSize = sizeof(g.fStartup);
171 DWORD dwType = REG_DWORD;
172 RegQueryValueEx (hk, TEXT("ShowTrayIcon"), NULL, &dwType, (PBYTE)&g.fStartup, &dwSize);
176 Shortcut_FixStartup (cszSHORTCUT_NAME, g.fStartup);
178 // Is this Windows NT?
180 OSVERSIONINFO Version;
181 memset (&Version, 0x00, sizeof(Version));
182 Version.dwOSVersionInfoSize = sizeof(Version);
183 if (GetVersionEx (&Version))
184 g.fIsWinNT = (Version.dwPlatformId == VER_PLATFORM_WIN32_NT) ? TRUE : FALSE;
187 lstrcpy (g.szHelpFile, TEXT("afs-light.hlp"));
189 lstrcpy (g.szHelpFile, TEXT("afs-nt.hlp"));
191 // Initialize winsock etc
194 WSAStartup (0x0101, &Data);
196 InitCommonControls();
197 RegisterCheckListClass();
199 // Create a main window. All further initialization will be done during
200 // processing of WM_INITDIALOG.
203 if (!GetClassInfo (NULL, WC_DIALOG, &wc)) // Get dialog class info
205 wc.hInstance = THIS_HINST;
206 wc.hIcon = TaLocale_LoadIcon (IDI_MAIN);
207 wc.lpszClassName = cszCLASSNAME;
208 wc.style |= CS_GLOBALCLASS;
211 g.hMain = ModelessDialog (IDD_MAIN, NULL, (DLGPROC)Main_DlgProc);
215 // If the service isn't started yet, show our startup wizard.
217 if (!IsServiceRunning() && !fQuiet)
220 Message (MB_ICONHAND, IDS_UNCONFIG_TITLE_95, IDS_UNCONFIG_DESC_95);
221 else if (IsServiceConfigured())
223 else if (!IsServerInstalled())
224 Message (MB_ICONHAND, IDS_UNCONFIG_TITLE, IDS_UNCONFIG_DESC);
226 if (IsServiceRunning() && fShow)
241 void PumpMessage (MSG *pmsg)
243 if (!IsMemoryManagerMessage (pmsg))
245 if (!IsDialogMessage (g.hMain, pmsg))
247 TranslateMessage (pmsg);
248 DispatchMessage (pmsg);
256 if (IsWindow (g.hMain))
258 ChangeTrayIcon (NIM_DELETE);
259 DestroyWindow (g.hMain);
265 BOOL IsServerInstalled (void)
267 BOOL fInstalled = FALSE;
269 TCHAR szKey[] = AFSREG_SVR_SVC_KEY;
270 LPCTSTR pch = lstrchr (szKey, TEXT('\\'));
273 if (RegOpenKey (HKEY_LOCAL_MACHINE, &pch[1], &hk) == 0)