win-xp-sp2-20040325
[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
73     switch (uMsg) {
74         case CPL_INIT:      /* first message, sent once  */
75             hinst = GetModuleHandle("afs_cpa.cpl");
76             hinstResources = TaLocale_LoadCorrespondingModule (hinst);
77             return (hinst != 0);
78
79         case CPL_GETCOUNT:  /* second message, sent once */
80             return 1;
81             break;
82
83         case CPL_NEWINQUIRE: /* third message, sent once per app */
84             lpNewCPlInfo = (LPNEWCPLINFO) lParam2;
85
86             lpNewCPlInfo->dwSize = (DWORD) sizeof(NEWCPLINFO);
87             lpNewCPlInfo->dwFlags = 0;
88             lpNewCPlInfo->dwHelpContext = 0;
89             lpNewCPlInfo->lData = 0;
90             if (IsClientInstalled() || !IsWindowsNT())
91                lpNewCPlInfo->hIcon = TaLocale_LoadIcon(IDI_AFSD);
92             else
93                lpNewCPlInfo->hIcon = TaLocale_LoadIcon(IDI_CCENTER);
94             lpNewCPlInfo->szHelpFile[0] = '\0';
95
96             GetString (lpNewCPlInfo->szName, (!IsWindowsNT()) ? IDS_CPL_NAME_95 : (!IsClientInstalled()) ? IDS_CPL_NAME_CCENTER : IDS_CPL_NAME_NT);
97             GetString (lpNewCPlInfo->szInfo, (!IsWindowsNT()) ? IDS_CPL_DESC_95 : (!IsClientInstalled()) ? IDS_CPL_DESC_CCENTER : IDS_CPL_DESC_NT);
98             break;
99
100         case CPL_DBLCLK:                /* applet icon double-clicked */
101             if (IsClientInstalled() || !IsWindowsNT())
102                 WinExec("afs_config.exe", SW_SHOW);
103             else
104                 WinExec("afs_config.exe /c", SW_SHOW);
105             break;
106
107         case CPL_EXIT:
108             if (hinstResources)
109                 FreeLibrary (hinstResources);
110             break;
111     }
112
113     return 0;
114 }
115
116