2 * PROJECT: ReactOS Applications Manager
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/rapps/installed.cpp
5 * PURPOSE: Functions for working with installed applications
6 * PROGRAMMERS: Dmitry Chapyshev (dmitry@reactos.org)
7 * Alexander Shaposhnikov (chaez.san@gmail.com)
13 GetApplicationString(HKEY hKey
, LPCWSTR lpKeyName
, ATL::CStringW
& String
)
15 BOOL result
= GetApplicationString(hKey
, lpKeyName
, String
.GetBuffer(MAX_PATH
));
16 String
.ReleaseBuffer();
21 GetApplicationString(HKEY hKey
, LPCWSTR lpKeyName
, LPWSTR szString
)
23 DWORD dwSize
= MAX_PATH
* sizeof(WCHAR
);
25 if (RegQueryValueExW(hKey
,
30 &dwSize
) == ERROR_SUCCESS
)
40 IsInstalledApplication(const ATL::CStringW
&RegName
, BOOL IsUserKey
, REGSAM keyWow
)
43 BOOL IsInstalled
= FALSE
;
44 ATL::CStringW szPath
= L
"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + RegName
;
46 if (RegOpenKeyExW(IsUserKey
? HKEY_CURRENT_USER
: HKEY_LOCAL_MACHINE
,
47 szPath
, 0, keyWow
| KEY_READ
,
48 &hKey
) == ERROR_SUCCESS
)
57 InstalledVersion(ATL::CStringW
& szVersionResult
, const ATL::CStringW
& RegName
, BOOL IsUserKey
, REGSAM keyWow
)
60 BOOL bHasVersion
= FALSE
;
61 ATL::CStringW szVersion
;
62 ATL::CStringW szPath
= L
"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + RegName
;
64 if (RegOpenKeyExW(IsUserKey
? HKEY_CURRENT_USER
: HKEY_LOCAL_MACHINE
,
65 szPath
.GetString(), 0, keyWow
| KEY_READ
,
66 &hKey
) == ERROR_SUCCESS
)
68 DWORD dwSize
= MAX_PATH
;
69 DWORD dwType
= REG_SZ
;
70 if (RegQueryValueExW(hKey
,
74 (LPBYTE
) szVersion
.GetBuffer(dwSize
),
75 &dwSize
) == ERROR_SUCCESS
)
77 szVersion
.ReleaseBuffer();
78 szVersionResult
= szVersion
;
83 szVersion
.ReleaseBuffer();
93 UninstallApplication(INT Index
, BOOL bModify
)
95 LPCWSTR szModify
= L
"ModifyPath";
96 LPCWSTR szUninstall
= L
"UninstallString";
97 WCHAR szPath
[MAX_PATH
];
98 WCHAR szAppName
[MAX_STR_LEN
];
103 PINSTALLED_INFO ItemInfo
;
105 if (!IS_INSTALLED_ENUM(SelectedEnumType
))
110 ItemIndex
= (INT
) SendMessageW(hListView
, LVM_GETNEXTITEM
, -1, LVNI_FOCUSED
);
119 ListView_GetItemText(hListView
, ItemIndex
, 0, szAppName
, _countof(szAppName
));
120 WriteLogMessage(EVENTLOG_SUCCESS
, MSG_SUCCESS_REMOVE
, szAppName
);
122 ZeroMemory(&Item
, sizeof(Item
));
124 Item
.mask
= LVIF_PARAM
;
125 Item
.iItem
= ItemIndex
;
126 if (!ListView_GetItem(hListView
, &Item
))
129 ItemInfo
= (PINSTALLED_INFO
)Item
.lParam
;
130 hKey
= ItemInfo
->hSubKey
;
133 dwSize
= sizeof(szPath
);
134 if (RegQueryValueExW(hKey
,
135 bModify
? szModify
: szUninstall
,
139 &dwSize
) != ERROR_SUCCESS
)
144 return StartProcess(szPath
, TRUE
);
149 ShowInstalledAppInfo(INT Index
)
151 ATL::CStringW szText
;
152 ATL::CStringW szInfo
;
153 PINSTALLED_INFO Info
= (PINSTALLED_INFO
) ListViewGetlParam(Index
);
155 if (!Info
|| !Info
->hSubKey
) return FALSE
;
157 GetApplicationString(Info
->hSubKey
, L
"DisplayName", szText
);
158 NewRichEditText(szText
, CFE_BOLD
);
159 InsertRichEditText(L
"\n", 0);
161 #define GET_INFO(a, b, c, d) \
162 if (GetApplicationString(Info->hSubKey, a, szInfo)) \
164 szText.LoadStringW(hInst, b); \
165 InsertRichEditText(szText, c); \
166 InsertRichEditText(szInfo, d); \
169 GET_INFO(L"DisplayVersion", IDS_INFO_VERSION, CFE_BOLD, 0);
170 GET_INFO(L
"Publisher", IDS_INFO_PUBLISHER
, CFE_BOLD
, 0);
171 GET_INFO(L
"RegOwner", IDS_INFO_REGOWNER
, CFE_BOLD
, 0);
172 GET_INFO(L
"ProductID", IDS_INFO_PRODUCTID
, CFE_BOLD
, 0);
173 GET_INFO(L
"HelpLink", IDS_INFO_HELPLINK
, CFE_BOLD
, CFM_LINK
);
174 GET_INFO(L
"HelpTelephone", IDS_INFO_HELPPHONE
, CFE_BOLD
, 0);
175 GET_INFO(L
"Readme", IDS_INFO_README
, CFE_BOLD
, 0);
176 GET_INFO(L
"Contact", IDS_INFO_CONTACT
, CFE_BOLD
, 0);
177 GET_INFO(L
"URLUpdateInfo", IDS_INFO_UPDATEINFO
, CFE_BOLD
, CFM_LINK
);
178 GET_INFO(L
"URLInfoAbout", IDS_INFO_INFOABOUT
, CFE_BOLD
, CFM_LINK
);
179 GET_INFO(L
"Comments", IDS_INFO_COMMENTS
, CFE_BOLD
, 0);
180 GET_INFO(L
"InstallDate", IDS_INFO_INSTALLDATE
, CFE_BOLD
, 0);
181 GET_INFO(L
"InstallLocation", IDS_INFO_INSTLOCATION
, CFE_BOLD
, 0);
182 GET_INFO(L
"InstallSource", IDS_INFO_INSTALLSRC
, CFE_BOLD
, 0);
183 GET_INFO(L
"UninstallString", IDS_INFO_UNINSTALLSTR
, CFE_BOLD
, 0);
184 GET_INFO(L
"InstallSource", IDS_INFO_INSTALLSRC
, CFE_BOLD
, 0);
185 GET_INFO(L
"ModifyPath", IDS_INFO_MODIFYPATH
, CFE_BOLD
, 0);
192 RemoveAppFromRegistry(INT Index
)
194 PINSTALLED_INFO Info
;
195 WCHAR szFullName
[MAX_PATH
] = L
"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\";
196 ATL::CStringW szMsgText
, szMsgTitle
;
197 INT ItemIndex
= SendMessage(hListView
, LVM_GETNEXTITEM
, -1, LVNI_FOCUSED
);
199 if (!IS_INSTALLED_ENUM(SelectedEnumType
))
202 Info
= (PINSTALLED_INFO
) ListViewGetlParam(Index
);
203 if (!Info
|| !Info
->hSubKey
|| (ItemIndex
== -1)) return;
205 if (!szMsgText
.LoadStringW(hInst
, IDS_APP_REG_REMOVE
) ||
206 !szMsgTitle
.LoadStringW(hInst
, IDS_INFORMATION
))
209 if (MessageBoxW(hMainWnd
, szMsgText
, szMsgTitle
, MB_YESNO
| MB_ICONQUESTION
) == IDYES
)
211 wcsncat(szFullName
, Info
->szKeyName
.GetString(), MAX_PATH
- wcslen(szFullName
));
213 if (RegDeleteKeyW(Info
->hRootKey
, szFullName
) == ERROR_SUCCESS
)
215 (VOID
) ListView_DeleteItem(hListView
, ItemIndex
);
219 if (!szMsgText
.LoadStringW(hInst
, IDS_UNABLE_TO_REMOVE
))
222 MessageBoxW(hMainWnd
, szMsgText
.GetString(), NULL
, MB_OK
| MB_ICONERROR
);
228 EnumInstalledApplications(INT EnumType
, BOOL IsUserKey
, APPENUMPROC lpEnumProc
)
230 DWORD dwSize
= MAX_PATH
, dwType
, dwValue
;
231 BOOL bIsSystemComponent
, bIsUpdate
;
232 ATL::CStringW szParentKeyName
;
233 ATL::CStringW szDisplayName
;
238 Info
.hRootKey
= IsUserKey
? HKEY_CURRENT_USER
: HKEY_LOCAL_MACHINE
;
240 if (RegOpenKeyW(Info
.hRootKey
,
241 L
"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall",
242 &hKey
) != ERROR_SUCCESS
)
247 while (RegEnumKeyExW(hKey
, ItemIndex
, Info
.szKeyName
.GetBuffer(MAX_PATH
), &dwSize
, NULL
, NULL
, NULL
, NULL
) == ERROR_SUCCESS
)
249 Info
.szKeyName
.ReleaseBuffer();
250 if (RegOpenKeyW(hKey
, Info
.szKeyName
.GetString(), &Info
.hSubKey
) == ERROR_SUCCESS
)
253 dwSize
= sizeof(DWORD
);
255 if (RegQueryValueExW(Info
.hSubKey
,
260 &dwSize
) == ERROR_SUCCESS
)
262 bIsSystemComponent
= (dwValue
== 0x1);
266 bIsSystemComponent
= FALSE
;
271 bIsUpdate
= (RegQueryValueExW(Info
.hSubKey
,
275 (LPBYTE
) szParentKeyName
.GetBuffer(dwSize
),
276 &dwSize
) == ERROR_SUCCESS
);
277 szParentKeyName
.ReleaseBuffer();
279 dwSize
= sizeof(szDisplayName
);
280 if (RegQueryValueExW(Info
.hSubKey
,
284 (LPBYTE
) szDisplayName
.GetBuffer(dwSize
),
285 &dwSize
) == ERROR_SUCCESS
)
287 szDisplayName
.ReleaseBuffer();
288 if (EnumType
< ENUM_ALL_COMPONENTS
|| EnumType
> ENUM_UPDATES
)
289 EnumType
= ENUM_ALL_COMPONENTS
;
291 if (!bIsSystemComponent
)
293 if ((EnumType
== ENUM_ALL_COMPONENTS
) || /* All components */
294 ((EnumType
== ENUM_APPLICATIONS
) && (!bIsUpdate
)) || /* Applications only */
295 ((EnumType
== ENUM_UPDATES
) && (bIsUpdate
))) /* Updates only */
297 if (!lpEnumProc(ItemIndex
, szDisplayName
, &Info
))
302 RegCloseKey(Info
.hSubKey
);
307 RegCloseKey(Info
.hSubKey
);
312 szDisplayName
.ReleaseBuffer();
313 RegCloseKey(Info
.hSubKey
);
321 Info
.szKeyName
.ReleaseBuffer();