ReactOS 0.4.15-dev-8127-g6338913
CAppDB Class Reference

#include <appdb.h>

Collaboration diagram for CAppDB:

Public Member Functions

 CAppDB (const CStringW &path)
 
VOID GetApps (CAtlList< CAppInfo * > &List, AppsCategories Type) const
 
CAvailableApplicationInfoFindAvailableByPackageName (const CStringW &name)
 
CAppInfoFindByPackageName (const CStringW &name)
 
VOID UpdateAvailable ()
 
VOID UpdateInstalled ()
 
VOID RemoveCached ()
 
size_t GetAvailableCount () const
 

Static Public Member Functions

static DWORD RemoveInstalledAppFromRegistry (const CAppInfo *Info)
 
static CInstalledApplicationInfoCreateInstalledAppByRegistryKey (LPCWSTR Name)
 
static CInstalledApplicationInfoCreateInstalledAppInstance (LPCWSTR KeyName, BOOL User, REGSAM WowSam)
 
static HKEY EnumInstalledRootKey (UINT Index, REGSAM &RegSam)
 

Private Member Functions

BOOL EnumerateFiles ()
 

Static Private Member Functions

static CInstalledApplicationInfoEnumerateRegistry (CAtlList< CAppInfo * > *List, LPCWSTR Name)
 
static CInstalledApplicationInfoCreateInstalledAppByRegistryKey (LPCWSTR KeyName, HKEY hKeyParent, UINT KeyIndex)
 

Private Attributes

CPathW m_BasePath
 
CAtlList< CAppInfo * > m_Available
 
CAtlList< CAppInfo * > m_Installed
 

Detailed Description

Definition at line 8 of file appdb.h.

Constructor & Destructor Documentation

◆ CAppDB()

CAppDB::CAppDB ( const CStringW path)

Definition at line 32 of file appdb.cpp.

33{
35}
void Canonicalize()
Definition: atlpath.h:149
CPathW m_BasePath
Definition: appdb.h:11

Member Function Documentation

◆ CreateInstalledAppByRegistryKey() [1/2]

CInstalledApplicationInfo * CAppDB::CreateInstalledAppByRegistryKey ( LPCWSTR  KeyName,
HKEY  hKeyParent,
UINT  KeyIndex 
)
staticprivate

Definition at line 169 of file appdb.cpp.

170{
171 CRegKey hSubKey;
172 if (hSubKey.Open(hKeyParent, KeyName, KEY_READ) != ERROR_SUCCESS)
173 return NULL;
175
176 size = sizeof(DWORD);
177 if (!RegQueryValueExW(hSubKey, L"SystemComponent", NULL, NULL, (LPBYTE)&value, &size) && value == 1)
178 {
179 // Ignore system components
180 return NULL;
181 }
182
183 size = 0;
184 BOOL bIsUpdate = !RegQueryValueExW(hSubKey, L"ParentKeyName", NULL, NULL, NULL, &size);
185
188 pInfo = new CInstalledApplicationInfo(hSubKey.Detach(), KeyName, cat, KeyIndex);
189 if (pInfo && pInfo->Valid())
190 {
191 return pInfo;
192 }
193 delete pInfo;
194 return NULL;
195}
AppsCategories
Definition: appinfo.h:25
@ ENUM_UPDATES
Definition: appinfo.h:46
@ ENUM_INSTALLED_APPLICATIONS
Definition: appinfo.h:45
LONG Open(HKEY hKeyParent, LPCTSTR lpszKeyName, REGSAM samDesired=KEY_READ|KEY_WRITE) noexcept
Definition: atlbase.h:1173
HKEY Detach() noexcept
Definition: atlbase.h:1166
virtual BOOL Valid() const override
Definition: appinfo.cpp:536
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizeiptr size
Definition: glext.h:5919
#define KEY_READ
Definition: nt_native.h:1023
#define DWORD
Definition: nt_native.h:44
#define L(x)
Definition: ntvdm.h:50
unsigned char * LPBYTE
Definition: typedefs.h:53
Definition: pdh_main.c:94
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2699

Referenced by CreateInstalledAppInstance(), EnumerateRegistry(), and HandleUninstallCommand().

◆ CreateInstalledAppByRegistryKey() [2/2]

CInstalledApplicationInfo * CAppDB::CreateInstalledAppByRegistryKey ( LPCWSTR  Name)
static

Definition at line 245 of file appdb.cpp.

246{
247 return EnumerateRegistry(NULL, Name);
248}
static CInstalledApplicationInfo * EnumerateRegistry(CAtlList< CAppInfo * > *List, LPCWSTR Name)
Definition: appdb.cpp:198

◆ CreateInstalledAppInstance()

CInstalledApplicationInfo * CAppDB::CreateInstalledAppInstance ( LPCWSTR  KeyName,
BOOL  User,
REGSAM  WowSam 
)
static

Definition at line 251 of file appdb.cpp.

252{
253 HKEY hRootKey = User ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE;
254 UINT KeyIndex = User ? (0) : ((WowSam & KEY_WOW64_64KEY) ? 2 : 1);
256 if (hKey.Open(hRootKey, UNINSTALL_SUBKEY, KEY_READ | WowSam) == ERROR_SUCCESS)
257 {
259 }
260 return NULL;
261}
#define UNINSTALL_SUBKEY
Definition: appdb.cpp:18
static CInstalledApplicationInfo * CreateInstalledAppByRegistryKey(LPCWSTR KeyName, HKEY hKeyParent, UINT KeyIndex)
Definition: appdb.cpp:169
FxAutoRegKey hKey
unsigned int UINT
Definition: ndis.h:50
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define KEY_WOW64_64KEY
Definition: cmtypes.h:46

Referenced by HandleUninstallCommand().

◆ EnumerateFiles()

BOOL CAppDB::EnumerateFiles ( )
private

Definition at line 72 of file appdb.cpp.

73{
75
76 CPathW AppsPath = m_BasePath;
77 AppsPath += RAPPS_DATABASE_SUBDIR;
78 CPathW WildcardPath = AppsPath;
79 WildcardPath += L"*.txt";
80
81 WIN32_FIND_DATAW FindFileData;
82 HANDLE hFind = FindFirstFileW(WildcardPath, &FindFileData);
83 if (hFind == INVALID_HANDLE_VALUE)
84 {
85 return FALSE;
86 }
87
88 do
89 {
90 CStringW szPkgName = FindFileData.cFileName;
92 szPkgName.ReleaseBuffer();
93
94 CAppInfo *Info = FindByPackageName(szPkgName);
96 if (!Info)
97 {
98 CConfigParser *Parser = new CConfigParser(CPathW(AppsPath) += FindFileData.cFileName);
99 int Cat;
100 if (!Parser->GetInt(DB_CATEGORY, Cat))
101 Cat = ENUM_INVALID;
102
103 Info = new CAvailableApplicationInfo(Parser, szPkgName, static_cast<AppsCategories>(Cat), AppsPath);
104 if (Info->Valid())
105 {
107 }
108 else
109 {
110 delete Info;
111 }
112 }
113
114 } while (FindNextFileW(hFind, &FindFileData));
115
116 FindClose(hFind);
117 return TRUE;
118}
#define ATLASSERT(x)
Definition: CComVariant.cpp:10
static VOID ClearList(CAtlList< CAppInfo * > &list)
Definition: appdb.cpp:21
#define DB_CATEGORY
Definition: appinfo.h:80
@ ENUM_INVALID
Definition: appinfo.h:47
#define RAPPS_DATABASE_SUBDIR
Definition: defines.h:37
POSITION AddTail(INARGTYPE element)
Definition: atlcoll.h:626
void ReleaseBuffer(_In_ int nNewLength=-1)
Definition: atlsimpstr.h:387
CAppInfo * FindByPackageName(const CStringW &name)
Definition: appdb.h:31
CAtlList< CAppInfo * > m_Available
Definition: appdb.h:12
BOOL GetInt(const CStringW &KeyName, INT &iResult)
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define MAX_PATH
Definition: compat.h:34
HANDLE WINAPI FindFirstFileW(IN LPCWSTR lpFileName, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:320
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502
BOOL WINAPI FindNextFileW(IN HANDLE hFindFile, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:382
void WINAPI PathRemoveExtensionW(LPWSTR lpszPath)
Definition: path.c:823
CPathT< CStringW > CPathW
Definition: atlpath.h:395
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:690

Referenced by UpdateAvailable().

◆ EnumerateRegistry()

CInstalledApplicationInfo * CAppDB::EnumerateRegistry ( CAtlList< CAppInfo * > *  List,
LPCWSTR  Name 
)
staticprivate

Definition at line 198 of file appdb.cpp.

199{
200 ATLASSERT(List || SearchOnly);
201 REGSAM wowsam;
202 HKEY hRootKey;
203 for (UINT rki = 0; (hRootKey = EnumInstalledRootKey(rki, wowsam)); ++rki)
204 {
206 if (hKey.Open(hRootKey, UNINSTALL_SUBKEY, KEY_READ | wowsam) != ERROR_SUCCESS)
207 {
208 continue;
209 }
210 for (DWORD Index = 0;; ++Index)
211 {
212 WCHAR szKeyName[MAX_PATH];
213 DWORD dwSize = _countof(szKeyName);
214 if (hKey.EnumKey(Index, szKeyName, &dwSize) != ERROR_SUCCESS)
215 {
216 break;
217 }
218 if (List || !StrCmpIW(SearchOnly, szKeyName))
219 {
221 Info = CreateInstalledAppByRegistryKey(szKeyName, hKey, rki);
222 if (Info)
223 {
224 if (List)
225 List->AddTail(Info);
226 else
227 return Info;
228 }
229 }
230 }
231 }
232 return NULL;
233}
static HKEY EnumInstalledRootKey(UINT Index, REGSAM &RegSam)
Definition: appdb.cpp:157
int WINAPI StrCmpIW(LPCWSTR lpszStr, LPCWSTR lpszComp)
Definition: string.c:353
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
#define _countof(array)
Definition: sndvol32.h:70
_In_ WDFCOLLECTION _In_ ULONG Index
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
ACCESS_MASK REGSAM
Definition: winreg.h:69
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by CreateInstalledAppByRegistryKey(), and UpdateInstalled().

◆ EnumInstalledRootKey()

HKEY CAppDB::EnumInstalledRootKey ( UINT  Index,
REGSAM RegSam 
)
static

Definition at line 157 of file appdb.cpp.

158{
159 // Loop for through all combinations.
160 // Note that HKEY_CURRENT_USER\Software does not have a redirect
161 // https://docs.microsoft.com/en-us/windows/win32/winprog64/shared-registry-keys#redirected-shared-and-reflected-keys-under-wow64
162 if (Index < (IsSystem64Bit() ? 3 : 2))
163 return GetRootKeyInfo(Index, RegSam);
164 else
165 return NULL;
166}
static HKEY GetRootKeyInfo(UINT Index, REGSAM &RegSam)
Definition: appdb.cpp:145
BOOL IsSystem64Bit()
Definition: misc.cpp:287

Referenced by EnumerateRegistry().

◆ FindAvailableByPackageName()

CAvailableApplicationInfo * CAppDB::FindAvailableByPackageName ( const CStringW name)

Definition at line 38 of file appdb.cpp.

39{
40 POSITION CurrentListPosition = m_Available.GetHeadPosition();
41 while (CurrentListPosition)
42 {
43 CAppInfo *Info = m_Available.GetNext(CurrentListPosition);
44 if (Info->szIdentifier == name)
45 {
46 return static_cast<CAvailableApplicationInfo *>(Info);
47 }
48 }
49 return NULL;
50}
POSITION GetHeadPosition() const
Definition: atlcoll.h:551
E & GetNext(_Inout_ POSITION &pos)
Definition: atlcoll.h:563
Definition: name.c:39

Referenced by FindByPackageName(), HandleGenerateInstallerCommand(), and HandleUninstallCommand().

◆ FindByPackageName()

CAppInfo * CAppDB::FindByPackageName ( const CStringW name)
inline

Definition at line 31 of file appdb.h.

CAvailableApplicationInfo * FindAvailableByPackageName(const CStringW &name)
Definition: appdb.cpp:38

Referenced by EnumerateFiles(), HandleInfoCommand(), HandleInstallCommand(), and HandleSetupCommand().

◆ GetApps()

void CAppDB::GetApps ( CAtlList< CAppInfo * > &  List,
AppsCategories  Type 
) const

Definition at line 53 of file appdb.cpp.

54{
55 const BOOL UseInstalled = IsInstalledEnum(Type);
56 const CAtlList<CAppInfo *> &list = UseInstalled ? m_Installed : m_Available;
57 const BOOL IncludeAll = UseInstalled ? (Type == ENUM_ALL_INSTALLED) : (Type == ENUM_ALL_AVAILABLE);
58
59 POSITION CurrentListPosition = list.GetHeadPosition();
60 while (CurrentListPosition)
61 {
62 CAppInfo *Info = list.GetNext(CurrentListPosition);
63
64 if (IncludeAll || Type == Info->iCategory)
65 {
66 List.AddTail(Info);
67 }
68 }
69}
Type
Definition: Type.h:7
BOOL IsInstalledEnum(INT x)
Definition: appinfo.h:61
@ ENUM_ALL_AVAILABLE
Definition: appinfo.h:26
@ ENUM_ALL_INSTALLED
Definition: appinfo.h:44
CAtlList< CAppInfo * > m_Installed
Definition: appdb.h:13
Definition: list.h:37

Referenced by HandleFindCommand(), SearchForAppWithDisplayName(), and CMainWindow::UpdateApplicationsList().

◆ GetAvailableCount()

size_t CAppDB::GetAvailableCount ( ) const
inline

Definition at line 50 of file appdb.h.

51 {
52 return m_Available.GetCount();
53 }
size_t GetCount() const
Definition: atlcoll.h:539

Referenced by CMainWindow::CheckAvailable().

◆ RemoveCached()

VOID CAppDB::RemoveCached ( )

Definition at line 291 of file appdb.cpp.

292{
293 // Delete icons
294 CPathW AppsPath = m_BasePath;
295 AppsPath += RAPPS_DATABASE_SUBDIR;
296 CPathW IconPath = AppsPath;
297 IconPath += L"icons";
299
300 // Delete leftover screenshots
301 CPathW ScrnshotFolder = AppsPath;
302 ScrnshotFolder += L"screenshots";
303 DeleteWithWildcard(ScrnshotFolder, L"*.tmp");
304
305 // Delete data base files (*.txt)
306 DeleteWithWildcard(AppsPath, L"*.txt");
307
309 RemoveDirectoryW(ScrnshotFolder);
310 RemoveDirectoryW(AppsPath);
312}
static void DeleteWithWildcard(const CPathW &Dir, const CStringW &Filter)
Definition: appdb.cpp:264
BOOL WINAPI RemoveDirectoryW(IN LPCWSTR lpPathName)
Definition: dir.c:732
static const WCHAR IconPath[]
Definition: install.c:51

Referenced by CMainWindow::CheckAvailable(), CMainWindow::OnCommand(), and ParseCmdAndExecute().

◆ RemoveInstalledAppFromRegistry()

DWORD CAppDB::RemoveInstalledAppFromRegistry ( const CAppInfo Info)
static

Definition at line 315 of file appdb.cpp.

316{
317 // Validate that this is actually an installed app / update
318 ATLASSERT(Info->iCategory == ENUM_INSTALLED_APPLICATIONS || Info->iCategory == ENUM_UPDATES);
319 if (Info->iCategory != ENUM_INSTALLED_APPLICATIONS && Info->iCategory != ENUM_UPDATES)
321
322 const CInstalledApplicationInfo *InstalledInfo = static_cast<const CInstalledApplicationInfo *>(Info);
323
324 CStringW Name = InstalledInfo->szIdentifier;
325 REGSAM wowsam;
326 HKEY hRoot = GetRootKeyInfo(InstalledInfo->m_KeyInfo, wowsam);
328 if (!hRoot)
329 return ERROR_OPEN_FAILED;
330
331 CRegKey Uninstall;
332 LSTATUS err = Uninstall.Open(hRoot, UNINSTALL_SUBKEY, KEY_READ | KEY_WRITE | wowsam);
333 if (err == ERROR_SUCCESS)
334 {
335 err = Uninstall.RecurseDeleteKey(Name);
336 }
337 return err;
338}
LONG RecurseDeleteKey(LPCTSTR lpszKey) noexcept
Definition: atlbase.h:1414
const CStringW szIdentifier
Definition: appinfo.h:98
static LSTATUS(WINAPI *pRegDeleteTreeW)(HKEY
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
static HTREEITEM hRoot
Definition: treeview.c:381
#define KEY_WRITE
Definition: nt_native.h:1031
#define err(...)
#define ERROR_OPEN_FAILED
Definition: winerror.h:184

Referenced by CMainWindow::RemoveSelectedAppFromRegistry(), and UninstallThread().

◆ UpdateAvailable()

VOID CAppDB::UpdateAvailable ( )

Definition at line 121 of file appdb.cpp.

122{
124 return;
125
126 if (EnumerateFiles())
127 return;
128
131
132 CPathW AppsPath = m_BasePath;
133 AppsPath += RAPPS_DATABASE_SUBDIR;
135 return;
136
137 CPathW CabFile = m_BasePath;
138 CabFile += APPLICATION_DATABASE_NAME;
139 DeleteFileW(CabFile);
140
142}
#define APPLICATION_DATABASE_URL
Definition: defines.h:40
#define APPLICATION_DATABASE_NAME
Definition: defines.h:41
SETTINGS_INFO SettingsInfo
Definition: winmain.cpp:20
BOOL ExtractFilesFromCab(const CStringW &szCabName, const CStringW &szCabDir, const CStringW &szOutputDir, EXTRACTCALLBACK Callback, void *Cookie)
Definition: cabinet.cpp:249
BOOL EnumerateFiles()
Definition: appdb.cpp:72
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
BOOL WINAPI CreateDirectoryW(IN LPCWSTR lpPathName, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: dir.c:90
#define ERROR_ALREADY_EXISTS
Definition: disk.h:80
VOID DownloadApplicationsDB(LPCWSTR lpUrl, BOOL IsOfficial)
Definition: loaddlg.cpp:1138
BOOL bUseSource
Definition: settings.h:23
WCHAR szSourceURL[INTERNET_MAX_URL_LENGTH]
Definition: settings.h:24
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

Referenced by CMainWindow::CheckAvailable(), ParseCmdAndExecute(), and CMainWindow::UpdateApplicationsList().

◆ UpdateInstalled()

VOID CAppDB::UpdateInstalled ( )

Definition at line 236 of file appdb.cpp.

237{
238 // Remove all old entries
240
242}

Referenced by ParseCmdAndExecute(), and CMainWindow::UpdateApplicationsList().

Member Data Documentation

◆ m_Available

CAtlList<CAppInfo *> CAppDB::m_Available
private

Definition at line 12 of file appdb.h.

Referenced by EnumerateFiles(), FindAvailableByPackageName(), GetApps(), and GetAvailableCount().

◆ m_BasePath

CPathW CAppDB::m_BasePath
private

Definition at line 11 of file appdb.h.

Referenced by CAppDB(), EnumerateFiles(), RemoveCached(), and UpdateAvailable().

◆ m_Installed

CAtlList<CAppInfo *> CAppDB::m_Installed
private

Definition at line 13 of file appdb.h.

Referenced by GetApps(), and UpdateInstalled().


The documentation for this class was generated from the following files: