dda0bbfdcff8cced03dd8b9449fa2d607f661ac0
[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(PINSTALLED_INFO ItemInfo, BOOL bModify)
42 {
43 LPCWSTR szModify = L"ModifyPath";
44 LPCWSTR szUninstall = L"UninstallString";
45 DWORD dwType, dwSize;
46 WCHAR szPath[MAX_PATH];
47
48 dwType = REG_SZ;
49 dwSize = MAX_PATH * sizeof(WCHAR);
50 if (RegQueryValueExW(ItemInfo->hSubKey,
51 bModify ? szModify : szUninstall,
52 NULL,
53 &dwType,
54 (LPBYTE) szPath,
55 &dwSize) != ERROR_SUCCESS)
56 {
57 return FALSE;
58 }
59
60 return StartProcess(szPath, TRUE);
61 }
62
63 BOOL EnumInstalledApplications(INT EnumType, BOOL IsUserKey, APPENUMPROC lpEnumProc, PVOID param)
64 {
65 DWORD dwSize = MAX_PATH, dwType, dwValue;
66 BOOL bIsSystemComponent, bIsUpdate;
67 ATL::CStringW szParentKeyName;
68 ATL::CStringW szDisplayName;
69 INSTALLED_INFO Info;
70 HKEY hKey;
71 LONG ItemIndex = 0;
72
73 Info.hRootKey = IsUserKey ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE;
74
75 if (RegOpenKeyW(Info.hRootKey,
76 L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall",
77 &hKey) != ERROR_SUCCESS)
78 {
79 return FALSE;
80 }
81
82 while (RegEnumKeyExW(hKey, ItemIndex, Info.szKeyName.GetBuffer(MAX_PATH), &dwSize, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
83 {
84 Info.szKeyName.ReleaseBuffer();
85 if (RegOpenKeyW(hKey, Info.szKeyName.GetString(), &Info.hSubKey) == ERROR_SUCCESS)
86 {
87 dwType = REG_DWORD;
88 dwSize = sizeof(DWORD);
89
90 if (RegQueryValueExW(Info.hSubKey,
91 L"SystemComponent",
92 NULL,
93 &dwType,
94 (LPBYTE) &dwValue,
95 &dwSize) == ERROR_SUCCESS)
96 {
97 bIsSystemComponent = (dwValue == 0x1);
98 }
99 else
100 {
101 bIsSystemComponent = FALSE;
102 }
103
104 dwType = REG_SZ;
105 dwSize = MAX_PATH * sizeof(WCHAR);
106 bIsUpdate = (RegQueryValueExW(Info.hSubKey,
107 L"ParentKeyName",
108 NULL,
109 &dwType,
110 (LPBYTE) szParentKeyName.GetBuffer(MAX_PATH),
111 &dwSize) == ERROR_SUCCESS);
112 szParentKeyName.ReleaseBuffer();
113
114 dwType = REG_SZ;
115 dwSize = MAX_PATH * sizeof(WCHAR);
116 if (RegQueryValueExW(Info.hSubKey,
117 L"DisplayName",
118 NULL,
119 &dwType,
120 (LPBYTE) szDisplayName.GetBuffer(MAX_PATH),
121 &dwSize) == ERROR_SUCCESS)
122 {
123 szDisplayName.ReleaseBuffer();
124 if (EnumType < ENUM_ALL_INSTALLED || EnumType > ENUM_UPDATES)
125 EnumType = ENUM_ALL_INSTALLED;
126
127 if (!bIsSystemComponent)
128 {
129 if ((EnumType == ENUM_ALL_INSTALLED) || /* All components */
130 ((EnumType == ENUM_INSTALLED_APPLICATIONS) && (!bIsUpdate)) || /* Applications only */
131 ((EnumType == ENUM_UPDATES) && (bIsUpdate))) /* Updates only */
132 {
133 if (!lpEnumProc(ItemIndex, szDisplayName, &Info, param))
134 break;
135 }
136 else
137 {
138 RegCloseKey(Info.hSubKey);
139 }
140 }
141 else
142 {
143 RegCloseKey(Info.hSubKey);
144 }
145 }
146 else
147 {
148 szDisplayName.ReleaseBuffer();
149 RegCloseKey(Info.hSubKey);
150 }
151 }
152
153 dwSize = MAX_PATH;
154 ItemIndex++;
155 }
156
157 Info.szKeyName.ReleaseBuffer();
158 RegCloseKey(hKey);
159
160 return TRUE;
161 }