winsta: fix spec file
[reactos.git] / reactos / base / applications / rapps / installed.c
1 /*
2 * PROJECT: ReactOS Applications Manager
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/rapps/installed.c
5 * PURPOSE: Functions for working with installed applications
6 * PROGRAMMERS: Dmitry Chapyshev (dmitry@reactos.org)
7 */
8
9 #include "rapps.h"
10
11
12 BOOL
13 GetApplicationString(HKEY hKey, LPWSTR lpKeyName, LPWSTR lpString)
14 {
15 DWORD dwSize = MAX_PATH;
16
17 if (RegQueryValueExW(hKey,
18 lpKeyName,
19 NULL,
20 NULL,
21 (LPBYTE)lpString,
22 &dwSize) == ERROR_SUCCESS)
23 {
24 return TRUE;
25 }
26
27 wcscpy(lpString, L"---");
28
29 return FALSE;
30 }
31
32
33 BOOL
34 IsInstalledApplication(LPWSTR lpRegName, BOOL IsUserKey)
35 {
36 DWORD dwSize = MAX_PATH, dwType;
37 WCHAR szName[MAX_PATH];
38 WCHAR szDisplayName[MAX_PATH];
39 HKEY hKey, hSubKey;
40 INT ItemIndex = 0;
41
42 if (RegOpenKeyW(IsUserKey ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE,
43 L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall",
44 &hKey) != ERROR_SUCCESS)
45 {
46 return FALSE;
47 }
48
49 while (RegEnumKeyExW(hKey, ItemIndex, szName, &dwSize, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
50 {
51 if (RegOpenKeyW(hKey, szName, &hSubKey) == ERROR_SUCCESS)
52 {
53 dwType = REG_SZ;
54 dwSize = MAX_PATH;
55 if (RegQueryValueExW(hSubKey,
56 L"DisplayName",
57 NULL,
58 &dwType,
59 (LPBYTE)szDisplayName,
60 &dwSize) == ERROR_SUCCESS)
61 {
62 if (wcscmp(szDisplayName, lpRegName) == 0)
63 {
64 RegCloseKey(hSubKey);
65 RegCloseKey(hKey);
66 return TRUE;
67 }
68 }
69 }
70
71 RegCloseKey(hSubKey);
72 dwSize = MAX_PATH;
73 ItemIndex++;
74 }
75
76 RegCloseKey(hKey);
77 return FALSE;
78 }
79
80
81 BOOL
82 UninstallApplication(INT Index, BOOL bModify)
83 {
84 WCHAR szModify[] = L"ModifyPath";
85 WCHAR szUninstall[] = L"UninstallString";
86 WCHAR szPath[MAX_PATH];
87 DWORD dwType, dwSize;
88 INT ItemIndex;
89 LVITEM Item;
90 HKEY hKey;
91
92 if (!IS_INSTALLED_ENUM(SelectedEnumType))
93 return FALSE;
94
95 if (Index == -1)
96 {
97 ItemIndex = (INT) SendMessageW(hListView, LVM_GETNEXTITEM, -1, LVNI_FOCUSED);
98 if (ItemIndex == -1)
99 return FALSE;
100 }
101 else
102 {
103 ItemIndex = Index;
104 }
105
106 ZeroMemory(&Item, sizeof(LVITEM));
107
108 Item.mask = LVIF_PARAM;
109 Item.iItem = ItemIndex;
110 if (!ListView_GetItem(hListView, &Item))
111 return FALSE;
112
113 hKey = (HKEY)Item.lParam;
114
115 dwType = REG_SZ;
116 dwSize = MAX_PATH;
117 if (RegQueryValueExW(hKey,
118 bModify ? szModify : szUninstall,
119 NULL,
120 &dwType,
121 (LPBYTE)szPath,
122 &dwSize) != ERROR_SUCCESS)
123 {
124 return FALSE;
125 }
126
127 return StartProcess(szPath, TRUE);
128 }
129
130
131 BOOL
132 ShowInstalledAppInfo(INT Index)
133 {
134 WCHAR szText[MAX_PATH], szInfo[MAX_PATH];
135 HKEY hKey = (HKEY) ListViewGetlParam(Index);
136
137 if (!hKey) return FALSE;
138
139 GetApplicationString(hKey, L"DisplayName", szText);
140 NewRichEditText(szText, CFE_BOLD);
141
142 InsertRichEditText(L"\n", 0);
143
144 #define GET_INFO(a, b, c, d) \
145 if (GetApplicationString(hKey, a, szInfo)) \
146 { \
147 LoadStringW(hInst, b, szText, sizeof(szText) / sizeof(WCHAR)); \
148 InsertRichEditText(szText, c); \
149 InsertRichEditText(szInfo, d); \
150 } \
151
152 GET_INFO(L"DisplayVersion", IDS_INFO_VERSION, CFE_BOLD, 0);
153 GET_INFO(L"Publisher", IDS_INFO_PUBLISHER, CFE_BOLD, 0);
154 GET_INFO(L"RegOwner", IDS_INFO_REGOWNER, CFE_BOLD, 0);
155 GET_INFO(L"ProductID", IDS_INFO_PRODUCTID, CFE_BOLD, 0);
156 GET_INFO(L"HelpLink", IDS_INFO_HELPLINK, CFE_BOLD, CFM_LINK);
157 GET_INFO(L"HelpTelephone", IDS_INFO_HELPPHONE, CFE_BOLD, 0);
158 GET_INFO(L"Readme", IDS_INFO_README, CFE_BOLD, 0);
159 GET_INFO(L"Contact", IDS_INFO_CONTACT, CFE_BOLD, 0);
160 GET_INFO(L"URLUpdateInfo", IDS_INFO_UPDATEINFO, CFE_BOLD, CFM_LINK);
161 GET_INFO(L"URLInfoAbout", IDS_INFO_INFOABOUT, CFE_BOLD, CFM_LINK);
162 GET_INFO(L"Comments", IDS_INFO_COMMENTS, CFE_BOLD, 0);
163 GET_INFO(L"InstallDate", IDS_INFO_INSTALLDATE, CFE_BOLD, 0);
164 GET_INFO(L"InstallLocation", IDS_INFO_INSTLOCATION, CFE_BOLD, 0);
165 GET_INFO(L"InstallSource", IDS_INFO_INSTALLSRC, CFE_BOLD, 0);
166 GET_INFO(L"UninstallString", IDS_INFO_UNINSTALLSTR, CFE_BOLD, 0);
167 GET_INFO(L"InstallSource", IDS_INFO_INSTALLSRC, CFE_BOLD, 0);
168 GET_INFO(L"ModifyPath", IDS_INFO_MODIFYPATH, CFE_BOLD, 0);
169
170 return TRUE;
171 }
172
173
174 BOOL
175 EnumInstalledApplications(INT EnumType, BOOL IsUserKey, APPENUMPROC lpEnumProc)
176 {
177 DWORD dwSize = MAX_PATH, dwType, dwValue;
178 BOOL bIsSystemComponent, bIsUpdate;
179 WCHAR pszName[MAX_PATH];
180 WCHAR pszParentKeyName[MAX_PATH];
181 WCHAR pszDisplayName[MAX_PATH];
182 HKEY hKey, hSubKey;
183 LONG ItemIndex = 0;
184
185 if (RegOpenKeyW(IsUserKey ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE,
186 L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall",
187 &hKey) != ERROR_SUCCESS)
188 {
189 return FALSE;
190 }
191
192 while (RegEnumKeyExW(hKey, ItemIndex, pszName, &dwSize, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
193 {
194 if (RegOpenKeyW(hKey, pszName, &hSubKey) == ERROR_SUCCESS)
195 {
196 dwType = REG_DWORD;
197 dwSize = sizeof(DWORD);
198
199 if (RegQueryValueExW(hSubKey,
200 L"SystemComponent",
201 NULL,
202 &dwType,
203 (LPBYTE)&dwValue,
204 &dwSize) == ERROR_SUCCESS)
205 {
206 bIsSystemComponent = (dwValue == 0x1);
207 }
208 else
209 {
210 bIsSystemComponent = FALSE;
211 }
212
213 dwType = REG_SZ;
214 dwSize = MAX_PATH;
215 bIsUpdate = (RegQueryValueExW(hSubKey,
216 L"ParentKeyName",
217 NULL,
218 &dwType,
219 (LPBYTE)pszParentKeyName,
220 &dwSize) == ERROR_SUCCESS);
221
222 dwSize = MAX_PATH;
223 if (RegQueryValueExW(hSubKey,
224 L"DisplayName",
225 NULL,
226 &dwType,
227 (LPBYTE)pszDisplayName,
228 &dwSize) == ERROR_SUCCESS)
229 {
230 if (EnumType < ENUM_ALL_COMPONENTS || EnumType > ENUM_UPDATES)
231 EnumType = ENUM_ALL_COMPONENTS;
232
233 if (!bIsSystemComponent)
234 {
235 if ((EnumType == ENUM_ALL_COMPONENTS) || /* All components */
236 ((EnumType == ENUM_APPLICATIONS) && (!bIsUpdate)) || /* Applications only */
237 ((EnumType == ENUM_UPDATES) && (bIsUpdate))) /* Updates only */
238 {
239 if (!lpEnumProc(ItemIndex, pszDisplayName, pszName, (LPARAM)hSubKey))
240 break;
241 }
242 }
243 }
244 }
245
246 dwSize = MAX_PATH;
247 ItemIndex++;
248 }
249
250 RegCloseKey(hKey);
251
252 return TRUE;
253 }