Windows: remove trailing whitespace
[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 <objbase.h>
12 #include <shellapi.h>
13 #include <cpl.h>
14 #include <WINNT/TaLocale.h>
15 #include <WINNT/afsreg.h>
16 #include "cpl_interface.h"
17 #include "resource.h"
18
19
20 static HINSTANCE hinst = 0;
21 static HINSTANCE hinstResources = 0;
22
23
24 static BOOL IsWindowsNT (void)
25 {
26    static BOOL fChecked = FALSE;
27    static BOOL fIsWinNT = FALSE;
28
29    if (!fChecked)
30       {
31       OSVERSIONINFO Version;
32       memset (&Version, 0x00, sizeof(Version));
33       Version.dwOSVersionInfoSize = sizeof(Version);
34
35       if (GetVersionEx (&Version))
36          {
37          if (Version.dwPlatformId == VER_PLATFORM_WIN32_NT)
38             fIsWinNT = TRUE;
39          }
40
41       fChecked = TRUE;
42       }
43
44    return fIsWinNT;
45 }
46
47
48 static BOOL IsClientInstalled (void)
49 {
50    static BOOL fChecked = FALSE;
51    static BOOL fIsInstalled = FALSE;
52
53    if (!fChecked)
54       {
55       HKEY hk;
56       if (RegOpenKey (HKEY_LOCAL_MACHINE, TEXT(AFSREG_CLT_SW_VERSION_SUBKEY), &hk) == 0)
57          {
58          TCHAR szPath[ MAX_PATH ];
59          DWORD dwSize = sizeof(szPath);
60          DWORD dwType = REG_SZ;
61          if (RegQueryValueEx (hk, TEXT(AFSREG_CLT_SW_VERSION_DIR_VALUE),
62                               NULL, &dwType, (PBYTE)szPath, &dwSize) == 0)
63             fIsInstalled = TRUE;
64          RegCloseKey (hk);
65          }
66       fChecked = TRUE;
67       }
68
69    return fIsInstalled;
70 }
71
72
73 extern "C" LONG APIENTRY CPlApplet(HWND hwndCPl, UINT uMsg, LONG lParam1, LONG lParam2)
74 {
75     LPNEWCPLINFO lpNewCPlInfo;
76     LPCPLINFO lpCPlInfo;
77     SHELLEXECUTEINFO shellExecInfo;
78
79     switch (uMsg) {
80         case CPL_INIT:      /* first message, sent once  */
81             hinst = GetModuleHandle("afs_cpa.cpl");
82             hinstResources = TaLocale_LoadCorrespondingModule (hinst);
83             CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
84             return (hinst != 0);
85
86         case CPL_GETCOUNT:  /* second message, sent once */
87             return 1;
88
89         case CPL_INQUIRE:  /* in case we receive this we should indicate that we like NEWINQUIRE better. */
90             lpCPlInfo = (CPLINFO *) lParam2;
91             lpCPlInfo->idIcon = ((IsClientInstalled() || !IsWindowsNT())? IDI_AFSD : IDI_CCENTER);
92             lpCPlInfo->idName = CPL_DYNAMIC_RES;
93             lpCPlInfo->idInfo = CPL_DYNAMIC_RES;
94             lpCPlInfo->lData = 0;
95             break;
96
97         case CPL_NEWINQUIRE: /* third message, sent once per app */
98             lpNewCPlInfo = (LPNEWCPLINFO) lParam2;
99
100             lpNewCPlInfo->dwSize = (DWORD) sizeof(NEWCPLINFO);
101             lpNewCPlInfo->dwFlags = 0;
102             lpNewCPlInfo->dwHelpContext = 0;
103             lpNewCPlInfo->lData = 0;
104             if (IsClientInstalled() || !IsWindowsNT())
105                lpNewCPlInfo->hIcon = TaLocale_LoadIcon(IDI_AFSD);
106             else
107                lpNewCPlInfo->hIcon = TaLocale_LoadIcon(IDI_CCENTER);
108             lpNewCPlInfo->szHelpFile[0] = '\0';
109
110             GetString (lpNewCPlInfo->szName, (!IsWindowsNT()) ? IDS_CPL_NAME_95 : (!IsClientInstalled()) ? IDS_CPL_NAME_CCENTER : IDS_CPL_NAME_NT);
111             GetString (lpNewCPlInfo->szInfo, (!IsWindowsNT()) ? IDS_CPL_DESC_95 : (!IsClientInstalled()) ? IDS_CPL_DESC_CCENTER : IDS_CPL_DESC_NT);
112             break;
113
114     case CPL_DBLCLK:            /* applet icon double-clicked */
115             memset(&shellExecInfo, 0, sizeof(shellExecInfo));
116             shellExecInfo.cbSize = sizeof(shellExecInfo);
117             shellExecInfo.nShow = SW_SHOWNORMAL;
118             shellExecInfo.hwnd = hwndCPl;
119             shellExecInfo.lpFile = "afs_config.exe";
120             if (!IsClientInstalled() && IsWindowsNT())
121                 shellExecInfo.lpParameters = "/c";
122
123             ShellExecuteEx(&shellExecInfo);
124             break;
125
126     case CPL_EXIT:
127             CoUninitialize();
128             if (hinstResources)
129                 FreeLibrary (hinstResources);
130             break;
131     }
132
133     return 0;
134 }
135
136