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