[RAPPS] CMainWindow: make szSearchPattern a member
[reactos.git] / base / applications / rapps / installed.cpp
1 /*
2 * PROJECT: ReactOS Applications Manager
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * FILE: base/applications/rapps/installed.cpp
5 * PURPOSE: Functions for working with installed applications
6 * COPYRIGHT: Copyright 2009 Dmitry Chapyshev (dmitry@reactos.org)
7 * Copyright 2017 Alexander Shaposhnikov (sanchaez@reactos.org)
8 */
9 #include "rapps.h"
10
11 #include "installed.h"
12
13 #include "gui.h"
14 #include "misc.h"
15
16 BOOL INSTALLED_INFO::GetApplicationString(LPCWSTR lpKeyName, ATL::CStringW& String)
17 {
18 BOOL result = ::GetApplicationString(hSubKey, lpKeyName, String.GetBuffer(MAX_PATH));
19 String.ReleaseBuffer();
20 return result;
21 }
22
23 BOOL GetApplicationString(HKEY hKey, LPCWSTR lpKeyName, LPWSTR szString)
24 {
25 DWORD dwSize = MAX_PATH * sizeof(WCHAR);
26
27 if (RegQueryValueExW(hKey,
28 lpKeyName,
29 NULL,
30 NULL,
31 (LPBYTE) szString,
32 &dwSize) == ERROR_SUCCESS)
33 {
34 return TRUE;
35 }
36
37 StringCchCopyW(szString, MAX_PATH, L"---");
38 return FALSE;
39 }
40
41 BOOL UninstallApplication(INT Index, BOOL bModify)
42 {
43 LPCWSTR szModify = L"ModifyPath";
44 LPCWSTR szUninstall = L"UninstallString";
45 WCHAR szPath[MAX_PATH];
46 WCHAR szAppName[MAX_STR_LEN];
47 DWORD dwType, dwSize;
48 INT ItemIndex;
49 LVITEMW Item;
50 HKEY hKey;
51 PINSTALLED_INFO ItemInfo;
52
53 if (!IsInstalledEnum(SelectedEnumType))
54 return FALSE;
55
56 if (Index == -1)
57 {
58 ItemIndex = (INT) SendMessageW(hListView, LVM_GETNEXTITEM, -1, LVNI_FOCUSED);
59 if (ItemIndex == -1)
60 return FALSE;
61 }
62 else
63 {
64 ItemIndex = Index;
65 }
66
67 ListView_GetItemText(hListView, ItemIndex, 0, szAppName, _countof(szAppName));
68 WriteLogMessage(EVENTLOG_SUCCESS, MSG_SUCCESS_REMOVE, szAppName);
69
70 ZeroMemory(&Item, sizeof(Item));
71
72 Item.mask = LVIF_PARAM;
73 Item.iItem = ItemIndex;
74 if (!ListView_GetItem(hListView, &Item))
75 return FALSE;
76
77 ItemInfo = (PINSTALLED_INFO) Item.lParam;
78 hKey = ItemInfo->hSubKey;
79
80 dwType = REG_SZ;
81 dwSize = MAX_PATH * sizeof(WCHAR);
82 if (RegQueryValueExW(hKey,
83 bModify ? szModify : szUninstall,
84 NULL,
85 &dwType,
86 (LPBYTE) szPath,
87 &dwSize) != ERROR_SUCCESS)
88 {
89 return FALSE;
90 }
91
92 return StartProcess(szPath, TRUE);
93 }
94
95 BOOL EnumInstalledApplications(INT EnumType, BOOL IsUserKey, APPENUMPROC lpEnumProc, PVOID param)
96 {
97 DWORD dwSize = MAX_PATH, dwType, dwValue;
98 BOOL bIsSystemComponent, bIsUpdate;
99 ATL::CStringW szParentKeyName;
100 ATL::CStringW szDisplayName;
101 INSTALLED_INFO Info;
102 HKEY hKey;
103 LONG ItemIndex = 0;
104
105 Info.hRootKey = IsUserKey ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE;
106
107 if (RegOpenKeyW(Info.hRootKey,
108 L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall",
109 &hKey) != ERROR_SUCCESS)
110 {
111 return FALSE;
112 }
113
114 while (RegEnumKeyExW(hKey, ItemIndex, Info.szKeyName.GetBuffer(MAX_PATH), &dwSize, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
115 {
116 Info.szKeyName.ReleaseBuffer();
117 if (RegOpenKeyW(hKey, Info.szKeyName.GetString(), &Info.hSubKey) == ERROR_SUCCESS)
118 {
119 dwType = REG_DWORD;
120 dwSize = sizeof(DWORD);
121
122 if (RegQueryValueExW(Info.hSubKey,
123 L"SystemComponent",
124 NULL,
125 &dwType,
126 (LPBYTE) &dwValue,
127 &dwSize) == ERROR_SUCCESS)
128 {
129 bIsSystemComponent = (dwValue == 0x1);
130 }
131 else
132 {
133 bIsSystemComponent = FALSE;
134 }
135
136 dwType = REG_SZ;
137 dwSize = MAX_PATH * sizeof(WCHAR);
138 bIsUpdate = (RegQueryValueExW(Info.hSubKey,
139 L"ParentKeyName",
140 NULL,
141 &dwType,
142 (LPBYTE) szParentKeyName.GetBuffer(MAX_PATH),
143 &dwSize) == ERROR_SUCCESS);
144 szParentKeyName.ReleaseBuffer();
145
146 dwType = REG_SZ;
147 dwSize = MAX_PATH * sizeof(WCHAR);
148 if (RegQueryValueExW(Info.hSubKey,
149 L"DisplayName",
150 NULL,
151 &dwType,
152 (LPBYTE) szDisplayName.GetBuffer(MAX_PATH),
153 &dwSize) == ERROR_SUCCESS)
154 {
155 szDisplayName.ReleaseBuffer();
156 if (EnumType < ENUM_ALL_INSTALLED || EnumType > ENUM_UPDATES)
157 EnumType = ENUM_ALL_INSTALLED;
158
159 if (!bIsSystemComponent)
160 {
161 if ((EnumType == ENUM_ALL_INSTALLED) || /* All components */
162 ((EnumType == ENUM_INSTALLED_APPLICATIONS) && (!bIsUpdate)) || /* Applications only */
163 ((EnumType == ENUM_UPDATES) && (bIsUpdate))) /* Updates only */
164 {
165 if (!lpEnumProc(ItemIndex, szDisplayName, &Info, param))
166 break;
167 }
168 else
169 {
170 RegCloseKey(Info.hSubKey);
171 }
172 }
173 else
174 {
175 RegCloseKey(Info.hSubKey);
176 }
177 }
178 else
179 {
180 szDisplayName.ReleaseBuffer();
181 RegCloseKey(Info.hSubKey);
182 }
183 }
184
185 dwSize = MAX_PATH;
186 ItemIndex++;
187 }
188
189 Info.szKeyName.ReleaseBuffer();
190 RegCloseKey(hKey);
191
192 return TRUE;
193 }