afslogon-wix-cleanup-20040715
[openafs.git] / src / WINNT / client_cpa / cpl_interface.cpp
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
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  */
9
10 #include <windows.h>
11 #include <cpl.h>
12 #include <WINNT/TaLocale.h>
13 #include "cpl_interface.h"
14 #include "resource.h"
15
16
17 static HINSTANCE hinst = 0;
18 static HINSTANCE hinstResources = 0;
19
20
21 static BOOL IsWindowsNT (void)
22 {
23    static BOOL fChecked = FALSE;
24    static BOOL fIsWinNT = FALSE;
25
26    if (!fChecked)
27       {
28       OSVERSIONINFO Version;
29       memset (&Version, 0x00, sizeof(Version));
30       Version.dwOSVersionInfoSize = sizeof(Version);
31
32       if (GetVersionEx (&Version))
33          {
34          if (Version.dwPlatformId == VER_PLATFORM_WIN32_NT)
35             fIsWinNT = TRUE;
36          }
37
38       fChecked = TRUE;
39       }
40
41    return fIsWinNT;
42 }
43
44
45 static BOOL IsClientInstalled (void)
46 {
47    static BOOL fChecked = FALSE;
48    static BOOL fIsInstalled = FALSE;
49
50    if (!fChecked)
51       {
52       HKEY hk;
53       if (RegOpenKey (HKEY_LOCAL_MACHINE, TEXT("Software\\TransarcCorporation\\AFS Client\\CurrentVersion"), &hk) == 0)
54          {
55          TCHAR szPath[ MAX_PATH ];
56          DWORD dwSize = sizeof(szPath);
57          DWORD dwType = REG_SZ;
58          if (RegQueryValueEx (hk, TEXT("PathName"), NULL, &dwType, (PBYTE)szPath, &dwSize) == 0)
59             fIsInstalled = TRUE;
60          RegCloseKey (hk);
61          }
62       fChecked = TRUE;
63       }
64
65    return fIsInstalled;
66 }
67
68
69 extern "C" LONG APIENTRY CPlApplet(HWND hwndCPl, UINT uMsg, LONG lParam1, LONG lParam2)
70 {
71     LPNEWCPLINFO lpNewCPlInfo;
72     LPCPLINFO lpCPlInfo;
73
74     switch (uMsg) {
75         case CPL_INIT:      /* first message, sent once  */
76             hinst = GetModuleHandle("afs_cpa.cpl");
77             hinstResources = TaLocale_LoadCorrespondingModule (hinst);
78             return (hinst != 0);
79
80         case CPL_GETCOUNT:  /* second message, sent once */
81             return 1;
82             break;
83
84         case CPL_INQUIRE:  /* in case we receive this we should indicate that we like NEWINQUIRE better. */
85                         lpCPlInfo = (CPLINFO *) lParam2;
86                         lpCPlInfo->idIcon = ((IsClientInstalled() || !IsWindowsNT())? IDI_AFSD : IDI_CCENTER);
87                         lpCPlInfo->idName = CPL_DYNAMIC_RES;
88                         lpCPlInfo->idInfo = CPL_DYNAMIC_RES;
89                         lpCPlInfo->lData = 0;
90                         break;
91
92         case CPL_NEWINQUIRE: /* third message, sent once per app */
93             lpNewCPlInfo = (LPNEWCPLINFO) lParam2;
94
95             lpNewCPlInfo->dwSize = (DWORD) sizeof(NEWCPLINFO);
96             lpNewCPlInfo->dwFlags = 0;
97             lpNewCPlInfo->dwHelpContext = 0;
98             lpNewCPlInfo->lData = 0;
99             if (IsClientInstalled() || !IsWindowsNT())
100                lpNewCPlInfo->hIcon = TaLocale_LoadIcon(IDI_AFSD);
101             else
102                lpNewCPlInfo->hIcon = TaLocale_LoadIcon(IDI_CCENTER);
103             lpNewCPlInfo->szHelpFile[0] = '\0';
104
105             GetString (lpNewCPlInfo->szName, (!IsWindowsNT()) ? IDS_CPL_NAME_95 : (!IsClientInstalled()) ? IDS_CPL_NAME_CCENTER : IDS_CPL_NAME_NT);
106             GetString (lpNewCPlInfo->szInfo, (!IsWindowsNT()) ? IDS_CPL_DESC_95 : (!IsClientInstalled()) ? IDS_CPL_DESC_CCENTER : IDS_CPL_DESC_NT);
107             break;
108
109         case CPL_DBLCLK:                /* applet icon double-clicked */
110             if (IsClientInstalled() || !IsWindowsNT())
111                 WinExec("afs_config.exe", SW_SHOW);
112             else
113                 WinExec("afs_config.exe /c", SW_SHOW);
114             break;
115
116         case CPL_EXIT:
117             if (hinstResources)
118                 FreeLibrary (hinstResources);
119             break;
120     }
121
122     return 0;
123 }
124
125