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