winnt-dont-display-ibm-legal-message-20040326
[openafs.git] / src / WINNT / afssvrcpa / 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 /*
11  * INCLUDES _________________________________________________________________
12  *
13  */
14 #include <windows.h>
15 #include <cpl.h>
16 #include <stdio.h>
17 #include "cpl_interface.h"
18 #include "resource.h"
19 #include <WINNT/afsreg.h>
20 #include <WINNT/TaLocale.h>
21
22
23
24 /*
25  * DEFINITIONS _______________________________________________________________
26  *
27  */
28 #define APP_INSTALL_DIR_REG_KEY         AFSREG_SVR_SW_VERSION_KEY
29 #define APP_INSTALL_DIR_REG_VALUE       AFSREG_SVR_SW_VERSION_DIR_VALUE
30 #define APP_EXE_PATH                            "\\usr\\afs\\bin\\afssvrcfg.exe"
31
32
33
34 /*
35  * VARIABLES _________________________________________________________________
36  *
37  */
38 static HINSTANCE hinst = 0;
39 static HINSTANCE hinstResources = 0;
40
41
42
43 /*
44  * STATIC FUNCTIONS ___________________________________________________________
45  *
46  */
47 static char *LoadResString(UINT uID)
48 {
49         static char str[256];
50         GetString (str, uID);
51         return str;
52 }
53
54 static char *GetInstallDir()
55 {
56         HKEY hKey;
57         LONG nResult;
58         DWORD dwType;
59         static char szInstallDir[256];
60         DWORD dwSize;
61
62         dwSize = sizeof(szInstallDir);
63
64         nResult = RegOpenKeyAlt(AFSREG_NULL_KEY, APP_INSTALL_DIR_REG_KEY, KEY_READ, FALSE, &hKey, 0);
65         if (nResult == ERROR_SUCCESS) {
66                 nResult = RegQueryValueEx(hKey, APP_INSTALL_DIR_REG_VALUE, 0, &dwType, (PBYTE)szInstallDir, &dwSize);
67                 RegCloseKey(hKey);
68         }
69
70         if (nResult != ERROR_SUCCESS)
71                 szInstallDir[0] = 0;
72
73         return szInstallDir;
74 }
75
76
77
78 /*
79  * EXPORTED FUNCTIONS _________________________________________________________
80  *
81  */
82 extern "C" LONG APIENTRY CPlApplet(HWND hwndCPl, UINT uMsg, LONG lParam1, LONG lParam2)
83 {
84     int i;
85     LPNEWCPLINFO lpNewCPlInfo;
86         HICON hIcon;
87         static char szAppName[64];
88         static char szAppPath[MAX_PATH];
89
90
91     i = (int)lParam1;
92
93     switch (uMsg) {
94         case CPL_INIT:      /* first message, sent once  */
95             hinst = GetModuleHandle("afsserver.cpl");
96             hinstResources = TaLocale_LoadCorrespondingModule (hinst);
97                         strcpy(szAppName, LoadResString(IDS_APP_NAME));
98                         sprintf(szAppPath, "%s%s", GetInstallDir(), APP_EXE_PATH);
99                         return (hinst != 0);
100
101         case CPL_GETCOUNT:  /* second message, sent once */
102             return 1;
103             break;
104
105         case CPL_NEWINQUIRE: /* third message, sent once per app */
106             lpNewCPlInfo = (LPNEWCPLINFO) lParam2;
107
108             lpNewCPlInfo->dwSize = (DWORD) sizeof(NEWCPLINFO);
109             lpNewCPlInfo->dwFlags = 0;
110             lpNewCPlInfo->dwHelpContext = 0;
111             lpNewCPlInfo->lData = 0;
112             hIcon = TaLocale_LoadIcon(IDI_AFSD);
113                         if (hIcon == 0)
114                                 MessageBox(0, LoadResString(IDS_ERROR_LOADING_ICON), szAppName, MB_ICONEXCLAMATION);
115                         lpNewCPlInfo->hIcon = hIcon;
116             lpNewCPlInfo->szHelpFile[0] = '\0';
117                         strcpy(lpNewCPlInfo->szName, szAppName);
118                         strcpy(lpNewCPlInfo->szInfo, LoadResString(IDS_CPA_TITLE));
119             break;
120
121         case CPL_SELECT:                /* applet icon selected */
122             break;
123
124         case CPL_DBLCLK:                /* applet icon double-clicked */
125                         if (WinExec(szAppPath, SW_SHOW) < 32)
126                                 MessageBox(0, LoadResString(IDS_EXECUTION_ERROR), szAppName, MB_ICONSTOP);
127             break;
128
129         case CPL_STOP:      /* sent once per app. before CPL_EXIT */
130             break;
131
132         case CPL_EXIT:    /* sent once before FreeLibrary called */
133             if (hinstResources)
134                 FreeLibrary (hinstResources);
135             break;
136
137         default:
138             break;
139     }
140
141     return 0;
142 }
143