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
21 * DEFINITIONS ________________________________________________________________
25 const TCHAR cszCLASSNAME[] = TEXT("AfsCreds");
29 * VARIABLES __________________________________________________________________
37 * PROTOTYPES _________________________________________________________________
41 BOOL InitApp (LPSTR pszCmdLineA);
44 void PumpMessage (MSG *pmsg);
45 BOOL IsServerInstalled (void);
49 * ROUTINES ___________________________________________________________________
53 int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR pCmdLine, int nCmdShow)
56 TaLocale_LoadCorrespondingModule (hInst);
58 if (InitApp (pCmdLine))
61 while (GetMessage (&msg, NULL, 0, 0) > 0)
74 BOOL InitApp (LPSTR pszCmdLineA)
79 BOOL fInstall = FALSE;
80 BOOL fUninstall = FALSE;
82 // Parse the command-line
84 while (pszCmdLineA && *pszCmdLineA)
86 if ((*pszCmdLineA != '-') && (*pszCmdLineA != '/'))
89 switch (*(++pszCmdLineA))
116 MapShareName(pszCmdLineA);
124 while (*pszCmdLineA && (*pszCmdLineA != ' '))
126 if (*pszCmdLineA==' ') ++pszCmdLineA;
130 Shortcut_FixStartup (cszSHORTCUT_NAME, g.fStartup = TRUE);
132 Shortcut_FixStartup (cszSHORTCUT_NAME, g.fStartup = FALSE);
137 if (RegCreateKey (HKEY_LOCAL_MACHINE, TEXT("System\\CurrentControlSet\\Services\\TransarcAFSDaemon\\Parameters"), &hk) == 0)
139 DWORD dwSize = sizeof(g.fStartup);
140 DWORD dwType = REG_DWORD;
141 RegSetValueEx (hk, TEXT("ShowTrayIcon"), NULL, dwType, (PBYTE)&g.fStartup, dwSize);
146 // Only show up if there's not another version of this app around already.
148 for (HWND hSearch = GetWindow (GetDesktopWindow(), GW_CHILD);
149 hSearch && IsWindow(hSearch);
150 hSearch = GetWindow (hSearch, GW_HWNDNEXT))
152 TCHAR szClassName[ cchRESOURCE ];
153 if (GetClassName (hSearch, szClassName, cchRESOURCE))
155 if (!lstrcmpi (szClassName, cszCLASSNAME))
158 PostMessage (hSearch, WM_COMMAND, M_ACTIVATE, 0);
160 PostMessage (hSearch, WM_COMMAND, M_TERMINATE_NOW, 0);
162 PostMessage (hSearch, WM_COMMAND, M_TERMINATE_NOW, 0);
168 if (fExit || fUninstall || fInstall)
171 // Initialize our global variables and window classes
173 memset (&g, 0x00, sizeof(g));
177 if (RegOpenKey (HKEY_LOCAL_MACHINE, TEXT("System\\CurrentControlSet\\Services\\TransarcAFSDaemon\\Parameters"), &hk) == 0)
179 DWORD dwSize = sizeof(g.fStartup);
180 DWORD dwType = REG_DWORD;
181 RegQueryValueEx (hk, TEXT("ShowTrayIcon"), NULL, &dwType, (PBYTE)&g.fStartup, &dwSize);
185 Shortcut_FixStartup (cszSHORTCUT_NAME, g.fStartup);
187 // Is this Windows NT?
189 OSVERSIONINFO Version;
190 memset (&Version, 0x00, sizeof(Version));
191 Version.dwOSVersionInfoSize = sizeof(Version);
192 if (GetVersionEx (&Version))
193 g.fIsWinNT = (Version.dwPlatformId == VER_PLATFORM_WIN32_NT) ? TRUE : FALSE;
196 lstrcpy (g.szHelpFile, TEXT("afs-light.hlp"));
198 lstrcpy (g.szHelpFile, TEXT("afs-nt.hlp"));
200 // Initialize winsock etc
203 WSAStartup (0x0101, &Data);
205 InitCommonControls();
206 RegisterCheckListClass();
208 // Create a main window. All further initialization will be done during
209 // processing of WM_INITDIALOG.
212 if (!GetClassInfo (NULL, WC_DIALOG, &wc)) // Get dialog class info
214 wc.hInstance = THIS_HINST;
215 wc.hIcon = TaLocale_LoadIcon (IDI_MAIN);
216 wc.lpszClassName = cszCLASSNAME;
217 wc.style |= CS_GLOBALCLASS;
220 g.hMain = ModelessDialog (IDD_MAIN, NULL, (DLGPROC)Main_DlgProc);
224 // If the service isn't started yet, show our startup wizard.
226 if (!IsServiceRunning() && !fQuiet)
229 Message (MB_ICONHAND, IDS_UNCONFIG_TITLE_95, IDS_UNCONFIG_DESC_95);
230 else if (IsServiceConfigured())
232 else if (!IsServerInstalled())
233 Message (MB_ICONHAND, IDS_UNCONFIG_TITLE, IDS_UNCONFIG_DESC);
235 if (IsServiceRunning() && fShow)
250 void PumpMessage (MSG *pmsg)
252 if (!IsMemoryManagerMessage (pmsg))
254 if (!IsDialogMessage (g.hMain, pmsg))
256 TranslateMessage (pmsg);
257 DispatchMessage (pmsg);
265 if (IsWindow (g.hMain))
267 ChangeTrayIcon (NIM_DELETE);
268 DestroyWindow (g.hMain);
274 BOOL IsServerInstalled (void)
276 BOOL fInstalled = FALSE;
278 TCHAR szKey[] = AFSREG_SVR_SVC_KEY;
279 LPCTSTR pch = lstrchr (szKey, TEXT('\\'));
282 if (RegOpenKey (HKEY_LOCAL_MACHINE, &pch[1], &hk) == 0)