Remove "Properties for" from caption.
[reactos.git] / reactos / dll / cpl / appwiz / appwiz.c
1 /*
2 * ReactOS
3 * Copyright (C) 2004 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /* $Id$
20 *
21 * PROJECT: ReactOS Software Control Panel
22 * FILE: lib/cpl/system/appwiz.c
23 * PURPOSE: ReactOS Software Control Panel
24 * PROGRAMMER: Gero Kuehn (reactos.filter@gkware.com)
25 * UPDATE HISTORY:
26 * 06-17-2004 Created
27 */
28
29 #include <windows.h>
30 #include <commctrl.h>
31 #include <cpl.h>
32
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <stdarg.h>
36 #include <tchar.h>
37 #include <process.h>
38
39 #include "resource.h"
40 #include "appwiz.h"
41
42 #define NUM_APPLETS (1)
43
44 LONG CALLBACK SystemApplet(VOID);
45 INT_PTR CALLBACK GeneralPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
46 INT_PTR CALLBACK ComputerPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
47 HINSTANCE hApplet = 0;
48
49 /* Applets */
50 APPLET Applets[NUM_APPLETS] =
51 {
52 {IDI_CPLSYSTEM, IDS_CPLSYSTEMNAME, IDS_CPLSYSTEMDESCRIPTION, SystemApplet}
53 };
54
55
56 static VOID
57 CallUninstall(HWND hwndDlg)
58 {
59 STARTUPINFO si;
60 PROCESS_INFORMATION pi;
61 int nIndex;
62 HKEY hKey;
63 DWORD dwType;
64 TCHAR pszUninstallString[MAX_PATH];
65 DWORD dwSize;
66
67 nIndex = (int) SendDlgItemMessage(hwndDlg, IDC_SOFTWARELIST, LB_GETCURSEL, 0, 0);
68 if (nIndex == -1)
69 {
70 MessageBox(hwndDlg,
71 _TEXT("No item selected"),
72 _TEXT("Error"),
73 MB_ICONSTOP);
74 }
75 else
76 {
77 hKey = (HKEY)SendDlgItemMessage(hwndDlg, IDC_SOFTWARELIST, LB_GETITEMDATA, (WPARAM)nIndex, 0);
78
79 dwType = REG_SZ;
80 dwSize = MAX_PATH;
81 if (RegQueryValueEx(hKey,
82 _TEXT("UninstallString"),
83 NULL,
84 &dwType,
85 (LPBYTE)pszUninstallString,
86 &dwSize) == ERROR_SUCCESS)
87 {
88 ZeroMemory(&si, sizeof(si));
89 si.cb = sizeof(si);
90 si.wShowWindow = SW_SHOW;
91 if (CreateProcess(NULL,pszUninstallString,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi))
92 {
93 CloseHandle(pi.hProcess);
94 CloseHandle(pi.hThread);
95 }
96 }
97 else
98 {
99 MessageBox(hwndDlg,
100 _TEXT("Unable to read UninstallString. This entry is invalid or has been created by an MSI installer."),
101 _TEXT("Error"),
102 MB_ICONSTOP);
103 }
104 }
105 }
106
107
108 static void FillSoftwareList(HWND hwndDlg)
109 {
110 TCHAR pszName[MAX_PATH];
111 TCHAR pszDisplayName[MAX_PATH];
112 TCHAR pszParentKeyName[MAX_PATH];
113 FILETIME FileTime;
114 HKEY hKey;
115 HKEY hSubKey;
116 DWORD dwType;
117 DWORD dwSize;
118 DWORD dwValue = 0;
119 BOOL bIsUpdate = FALSE;
120 BOOL bIsSystemComponent = FALSE;
121 BOOL bShowUpdates = FALSE;
122 int i;
123 ULONG index;
124
125 bShowUpdates = (SendMessage(GetDlgItem(hwndDlg, IDC_SHOWUPDATES), BM_GETCHECK, 0, 0) == BST_CHECKED);
126
127 if (RegOpenKey(HKEY_LOCAL_MACHINE,
128 _TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall"),
129 &hKey) != ERROR_SUCCESS)
130 {
131 MessageBox(hwndDlg,
132 _TEXT("Unable to open Uninstall Key"),
133 _TEXT("Error"),
134 MB_ICONSTOP);
135 return;
136 }
137
138 i = 0;
139 dwSize = MAX_PATH;
140 while (RegEnumKeyEx (hKey, i, pszName, &dwSize, NULL, NULL, NULL, &FileTime) == ERROR_SUCCESS)
141 {
142 if (RegOpenKey(hKey,pszName,&hSubKey)==ERROR_SUCCESS)
143 {
144 dwType = REG_DWORD;
145 dwSize = sizeof(DWORD);
146 if (RegQueryValueEx(hSubKey,
147 _TEXT("SystemComponent"),
148 NULL,
149 &dwType,
150 (LPBYTE)&dwValue,
151 &dwSize) == ERROR_SUCCESS)
152 {
153 bIsSystemComponent = (dwValue == 0x1);
154 }
155 else {
156 bIsSystemComponent = FALSE;
157 }
158 dwType = REG_SZ;
159 dwSize = MAX_PATH;
160 bIsUpdate = (RegQueryValueEx(hSubKey,
161 _TEXT("ParentKeyName"),
162 NULL,
163 &dwType,
164 (LPBYTE)pszParentKeyName,
165 &dwSize) == ERROR_SUCCESS);
166 dwSize = MAX_PATH;
167 if (RegQueryValueEx(hSubKey,
168 _TEXT("DisplayName"),
169 NULL,
170 &dwType,
171 (LPBYTE)pszDisplayName,
172 &dwSize) == ERROR_SUCCESS)
173 {
174 if ((!bIsUpdate) && (!bIsSystemComponent))
175 {
176 index = (ULONG) SendDlgItemMessage(hwndDlg,IDC_SOFTWARELIST,LB_ADDSTRING,0,(LPARAM)pszDisplayName);
177 SendDlgItemMessage(hwndDlg,IDC_SOFTWARELIST,LB_SETITEMDATA,index,(LPARAM)hSubKey);
178 }
179 else if (bIsUpdate && bShowUpdates)
180 {
181 index = (ULONG) SendDlgItemMessage(hwndDlg,IDC_SOFTWARELIST,LB_ADDSTRING,0,(LPARAM)pszDisplayName);
182 SendDlgItemMessage(hwndDlg,IDC_SOFTWARELIST,LB_SETITEMDATA,index,(LPARAM)hSubKey);
183 }
184 }
185 }
186
187 dwSize = MAX_PATH;
188 i++;
189 }
190
191 RegCloseKey(hKey);
192 }
193
194 /* Property page dialog callback */
195 static INT_PTR CALLBACK
196 InstallPageProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
197 {
198 UNREFERENCED_PARAMETER(lParam);
199 switch (uMsg)
200 {
201 case WM_INITDIALOG:
202 EnableWindow(GetDlgItem(hwndDlg,IDC_INSTALL), FALSE);
203 FillSoftwareList(hwndDlg);
204 break;
205
206 case WM_COMMAND:
207 switch (LOWORD(wParam))
208 {
209 case IDC_SHOWUPDATES:
210 if (HIWORD(wParam) == BN_CLICKED)
211 {
212 SendDlgItemMessage(hwndDlg, IDC_SOFTWARELIST, LB_RESETCONTENT, 0, 0);
213 FillSoftwareList(hwndDlg);
214 }
215 break;
216 case IDC_SOFTWARELIST:
217 if (HIWORD(wParam) == LBN_DBLCLK)
218 {
219 CallUninstall(hwndDlg);
220 }
221 break;
222
223 case IDC_ADDREMOVE:
224 CallUninstall(hwndDlg);
225 break;
226 }
227 break;
228 }
229
230 return FALSE;
231 }
232
233
234 /* Property page dialog callback */
235 static INT_PTR CALLBACK
236 RosPageProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
237 {
238 UNREFERENCED_PARAMETER(lParam);
239 UNREFERENCED_PARAMETER(wParam);
240 UNREFERENCED_PARAMETER(hwndDlg);
241 switch(uMsg)
242 {
243 case WM_INITDIALOG:
244 break;
245 }
246
247 return FALSE;
248 }
249
250
251 static VOID
252 InitPropSheetPage(PROPSHEETPAGE *psp, WORD idDlg, DLGPROC DlgProc)
253 {
254 ZeroMemory(psp, sizeof(PROPSHEETPAGE));
255 psp->dwSize = sizeof(PROPSHEETPAGE);
256 psp->dwFlags = PSP_DEFAULT;
257 psp->hInstance = hApplet;
258 psp->pszTemplate = MAKEINTRESOURCE(idDlg);
259 psp->pfnDlgProc = DlgProc;
260 }
261
262
263 /* First Applet */
264
265 LONG CALLBACK
266 SystemApplet(VOID)
267 {
268 PROPSHEETPAGE psp[2];
269 PROPSHEETHEADER psh;
270 TCHAR Caption[1024];
271
272 LoadString(hApplet, IDS_CPLSYSTEMNAME, Caption, sizeof(Caption) / sizeof(TCHAR));
273
274 ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
275 psh.dwSize = sizeof(PROPSHEETHEADER);
276 psh.dwFlags = PSH_PROPSHEETPAGE;
277 psh.hwndParent = NULL;
278 psh.hInstance = hApplet;
279 psh.hIcon = LoadIcon(hApplet, MAKEINTRESOURCE(IDI_CPLSYSTEM));
280 psh.pszCaption = Caption;
281 psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
282 psh.nStartPage = 0;
283 psh.ppsp = psp;
284 psh.pfnCallback = NULL;
285
286 InitPropSheetPage(&psp[0], IDD_PROPPAGEINSTALL, (DLGPROC) InstallPageProc);
287 InitPropSheetPage(&psp[1], IDD_PROPPAGEROSSETUP, (DLGPROC) RosPageProc);
288
289 return (LONG)(PropertySheet(&psh) != -1);
290 }
291
292
293 /* Control Panel Callback */
294 LONG CALLBACK
295 CPlApplet(HWND hwndCPl, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
296 {
297 CPLINFO *CPlInfo;
298 DWORD i;
299
300 UNREFERENCED_PARAMETER(hwndCPl);
301
302 i = (DWORD)lParam1;
303 switch(uMsg)
304 {
305 case CPL_INIT:
306 return TRUE;
307
308 case CPL_GETCOUNT:
309 return NUM_APPLETS;
310
311 case CPL_INQUIRE:
312 CPlInfo = (CPLINFO*)lParam2;
313 CPlInfo->lData = 0;
314 CPlInfo->idIcon = Applets[i].idIcon;
315 CPlInfo->idName = Applets[i].idName;
316 CPlInfo->idInfo = Applets[i].idDescription;
317 break;
318
319 case CPL_DBLCLK:
320 Applets[i].AppletProc();
321 break;
322 }
323
324 return FALSE;
325 }
326
327
328 BOOL WINAPI
329 DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpvReserved)
330 {
331 UNREFERENCED_PARAMETER(lpvReserved);
332 switch(dwReason)
333 {
334 case DLL_PROCESS_ATTACH:
335 case DLL_THREAD_ATTACH:
336 hApplet = hinstDLL;
337 break;
338 }
339 return TRUE;
340 }