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)
12 #include "installed.h"
18 GetApplicationString(HKEY hKey
, LPCWSTR lpKeyName
, ATL::CStringW
& String
)
20 BOOL result
= GetApplicationString(hKey
, lpKeyName
, String
.GetBuffer(MAX_PATH
));
21 String
.ReleaseBuffer();
26 GetApplicationString(HKEY hKey
, LPCWSTR lpKeyName
, LPWSTR szString
)
28 DWORD dwSize
= MAX_PATH
* sizeof(WCHAR
);
30 if (RegQueryValueExW(hKey
,
35 &dwSize
) == ERROR_SUCCESS
)
40 StringCchCopyW(szString
, MAX_PATH
, L
"---");
45 UninstallApplication(INT Index
, BOOL bModify
)
47 LPCWSTR szModify
= L
"ModifyPath";
48 LPCWSTR szUninstall
= L
"UninstallString";
49 WCHAR szPath
[MAX_PATH
];
50 WCHAR szAppName
[MAX_STR_LEN
];
55 PINSTALLED_INFO ItemInfo
;
57 if (!IsInstalledEnum(SelectedEnumType
))
62 ItemIndex
= (INT
) SendMessageW(hListView
, LVM_GETNEXTITEM
, -1, LVNI_FOCUSED
);
71 ListView_GetItemText(hListView
, ItemIndex
, 0, szAppName
, _countof(szAppName
));
72 WriteLogMessage(EVENTLOG_SUCCESS
, MSG_SUCCESS_REMOVE
, szAppName
);
74 ZeroMemory(&Item
, sizeof(Item
));
76 Item
.mask
= LVIF_PARAM
;
77 Item
.iItem
= ItemIndex
;
78 if (!ListView_GetItem(hListView
, &Item
))
81 ItemInfo
= (PINSTALLED_INFO
) Item
.lParam
;
82 hKey
= ItemInfo
->hSubKey
;
85 dwSize
= MAX_PATH
* sizeof(WCHAR
);
86 if (RegQueryValueExW(hKey
,
87 bModify
? szModify
: szUninstall
,
91 &dwSize
) != ERROR_SUCCESS
)
96 return StartProcess(szPath
, TRUE
);
100 ShowInstalledAppInfo(INT Index
)
102 ATL::CStringW szText
;
103 ATL::CStringW szInfo
;
104 PINSTALLED_INFO Info
= (PINSTALLED_INFO
) ListViewGetlParam(Index
);
106 if (!Info
|| !Info
->hSubKey
) return FALSE
;
108 GetApplicationString(Info
->hSubKey
, L
"DisplayName", szText
);
109 NewRichEditText(szText
, CFE_BOLD
);
110 InsertRichEditText(L
"\n", 0);
112 #define GET_INFO(a, b, c, d) \
113 if (GetApplicationString(Info->hSubKey, a, szInfo)) \
115 szText.LoadStringW(b); \
116 InsertRichEditText(szText, c); \
117 InsertRichEditText(szInfo, d); \
120 GET_INFO(L"DisplayVersion", IDS_INFO_VERSION, CFE_BOLD, 0);
121 GET_INFO(L
"Publisher", IDS_INFO_PUBLISHER
, CFE_BOLD
, 0);
122 GET_INFO(L
"RegOwner", IDS_INFO_REGOWNER
, CFE_BOLD
, 0);
123 GET_INFO(L
"ProductID", IDS_INFO_PRODUCTID
, CFE_BOLD
, 0);
124 GET_INFO(L
"HelpLink", IDS_INFO_HELPLINK
, CFE_BOLD
, CFM_LINK
);
125 GET_INFO(L
"HelpTelephone", IDS_INFO_HELPPHONE
, CFE_BOLD
, 0);
126 GET_INFO(L
"Readme", IDS_INFO_README
, CFE_BOLD
, 0);
127 GET_INFO(L
"Contact", IDS_INFO_CONTACT
, CFE_BOLD
, 0);
128 GET_INFO(L
"URLUpdateInfo", IDS_INFO_UPDATEINFO
, CFE_BOLD
, CFM_LINK
);
129 GET_INFO(L
"URLInfoAbout", IDS_INFO_INFOABOUT
, CFE_BOLD
, CFM_LINK
);
130 GET_INFO(L
"Comments", IDS_INFO_COMMENTS
, CFE_BOLD
, 0);
131 GET_INFO(L
"InstallDate", IDS_INFO_INSTALLDATE
, CFE_BOLD
, 0);
132 GET_INFO(L
"InstallLocation", IDS_INFO_INSTLOCATION
, CFE_BOLD
, 0);
133 GET_INFO(L
"InstallSource", IDS_INFO_INSTALLSRC
, CFE_BOLD
, 0);
134 GET_INFO(L
"UninstallString", IDS_INFO_UNINSTALLSTR
, CFE_BOLD
, 0);
135 GET_INFO(L
"InstallSource", IDS_INFO_INSTALLSRC
, CFE_BOLD
, 0);
136 GET_INFO(L
"ModifyPath", IDS_INFO_MODIFYPATH
, CFE_BOLD
, 0);
142 RemoveAppFromRegistry(INT Index
)
144 PINSTALLED_INFO Info
;
145 WCHAR szFullName
[MAX_PATH
] = L
"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\";
146 ATL::CStringW szMsgText
, szMsgTitle
;
147 INT ItemIndex
= SendMessageW(hListView
, LVM_GETNEXTITEM
, -1, LVNI_FOCUSED
);
149 if (!IsInstalledEnum(SelectedEnumType
))
152 Info
= (PINSTALLED_INFO
) ListViewGetlParam(Index
);
153 if (!Info
|| !Info
->hSubKey
|| (ItemIndex
== -1)) return;
155 if (!szMsgText
.LoadStringW(IDS_APP_REG_REMOVE
) ||
156 !szMsgTitle
.LoadStringW(IDS_INFORMATION
))
159 if (MessageBoxW(hMainWnd
, szMsgText
, szMsgTitle
, MB_YESNO
| MB_ICONQUESTION
) == IDYES
)
161 ATL::CStringW::CopyChars(szFullName
,
163 Info
->szKeyName
.GetString(),
164 MAX_PATH
- wcslen(szFullName
));
166 if (RegDeleteKeyW(Info
->hRootKey
, szFullName
) == ERROR_SUCCESS
)
168 ListView_DeleteItem(hListView
, ItemIndex
);
172 if (!szMsgText
.LoadStringW(IDS_UNABLE_TO_REMOVE
))
175 MessageBoxW(hMainWnd
, szMsgText
.GetString(), NULL
, MB_OK
| MB_ICONERROR
);
180 EnumInstalledApplications(INT EnumType
, BOOL IsUserKey
, APPENUMPROC lpEnumProc
)
182 DWORD dwSize
= MAX_PATH
, dwType
, dwValue
;
183 BOOL bIsSystemComponent
, bIsUpdate
;
184 ATL::CStringW szParentKeyName
;
185 ATL::CStringW szDisplayName
;
190 Info
.hRootKey
= IsUserKey
? HKEY_CURRENT_USER
: HKEY_LOCAL_MACHINE
;
192 if (RegOpenKeyW(Info
.hRootKey
,
193 L
"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall",
194 &hKey
) != ERROR_SUCCESS
)
199 while (RegEnumKeyExW(hKey
, ItemIndex
, Info
.szKeyName
.GetBuffer(MAX_PATH
), &dwSize
, NULL
, NULL
, NULL
, NULL
) == ERROR_SUCCESS
)
201 Info
.szKeyName
.ReleaseBuffer();
202 if (RegOpenKeyW(hKey
, Info
.szKeyName
.GetString(), &Info
.hSubKey
) == ERROR_SUCCESS
)
205 dwSize
= sizeof(DWORD
);
207 if (RegQueryValueExW(Info
.hSubKey
,
212 &dwSize
) == ERROR_SUCCESS
)
214 bIsSystemComponent
= (dwValue
== 0x1);
218 bIsSystemComponent
= FALSE
;
222 dwSize
= MAX_PATH
* sizeof(WCHAR
);
223 bIsUpdate
= (RegQueryValueExW(Info
.hSubKey
,
227 (LPBYTE
) szParentKeyName
.GetBuffer(MAX_PATH
),
228 &dwSize
) == ERROR_SUCCESS
);
229 szParentKeyName
.ReleaseBuffer();
232 dwSize
= MAX_PATH
* sizeof(WCHAR
);
233 if (RegQueryValueExW(Info
.hSubKey
,
237 (LPBYTE
) szDisplayName
.GetBuffer(MAX_PATH
),
238 &dwSize
) == ERROR_SUCCESS
)
240 szDisplayName
.ReleaseBuffer();
241 if (EnumType
< ENUM_ALL_INSTALLED
|| EnumType
> ENUM_UPDATES
)
242 EnumType
= ENUM_ALL_INSTALLED
;
244 if (!bIsSystemComponent
)
246 if ((EnumType
== ENUM_ALL_INSTALLED
) || /* All components */
247 ((EnumType
== ENUM_INSTALLED_APPLICATIONS
) && (!bIsUpdate
)) || /* Applications only */
248 ((EnumType
== ENUM_UPDATES
) && (bIsUpdate
))) /* Updates only */
250 if (!lpEnumProc(ItemIndex
, szDisplayName
, &Info
))
255 RegCloseKey(Info
.hSubKey
);
260 RegCloseKey(Info
.hSubKey
);
265 szDisplayName
.ReleaseBuffer();
266 RegCloseKey(Info
.hSubKey
);
274 Info
.szKeyName
.ReleaseBuffer();