[RAPPS] CMainWindow: Make EnumInstalledAppProc and EnumAvailableAppProc methods

This commit is contained in:
Giannis Adamopoulos 2019-04-28 06:39:02 +03:00 committed by Mark Jansen
parent d8b773b190
commit 700f54c37b
No known key found for this signature in database
GPG key ID: B39240EE84BEAE8B
6 changed files with 36 additions and 25 deletions

View file

@ -320,7 +320,7 @@ BOOL CAvailableApps::ForceUpdateAppsDB()
return UpdateAppsDB(); return UpdateAppsDB();
} }
BOOL CAvailableApps::Enum(INT EnumType, AVAILENUMPROC lpEnumProc) BOOL CAvailableApps::Enum(INT EnumType, AVAILENUMPROC lpEnumProc, PVOID param)
{ {
HANDLE hFind = INVALID_HANDLE_VALUE; HANDLE hFind = INVALID_HANDLE_VALUE;
@ -381,7 +381,7 @@ skip_if_cached:
Info->RefreshAppInfo(); Info->RefreshAppInfo();
if (lpEnumProc) if (lpEnumProc)
lpEnumProc(Info, m_Strings.szAppsPath.GetString()); lpEnumProc(Info, m_Strings.szAppsPath.GetString(), param);
} }
} while (FindNextFileW(hFind, &FindFileData) != 0); } while (FindNextFileW(hFind, &FindFileData) != 0);

View file

@ -554,14 +554,14 @@ public:
return (InsertColumn(Index, &Column) == -1) ? FALSE : TRUE; return (InsertColumn(Index, &Column) == -1) ? FALSE : TRUE;
} }
INT AddItem(INT ItemIndex, INT IconIndex, LPWSTR lpText, LPARAM lParam) INT AddItem(INT ItemIndex, INT IconIndex, LPCWSTR lpText, LPARAM lParam)
{ {
LVITEMW Item; LVITEMW Item;
ZeroMemory(&Item, sizeof(Item)); ZeroMemory(&Item, sizeof(Item));
Item.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE | LVIF_IMAGE; Item.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE | LVIF_IMAGE;
Item.pszText = lpText; Item.pszText = const_cast<LPWSTR>(lpText);
Item.lParam = lParam; Item.lParam = lParam;
Item.iItem = ItemIndex; Item.iItem = ItemIndex;
Item.iImage = IconIndex; Item.iImage = IconIndex;
@ -1614,7 +1614,7 @@ private:
return StrStrIW(szHaystack, szNeedle) != NULL; return StrStrIW(szHaystack, szNeedle) != NULL;
} }
static BOOL CALLBACK s_EnumInstalledAppProc(INT ItemIndex, ATL::CStringW &m_szName, PINSTALLED_INFO Info) BOOL CALLBACK EnumInstalledAppProc(INT ItemIndex, ATL::CStringW &m_szName, PINSTALLED_INFO Info)
{ {
PINSTALLED_INFO ItemInfo; PINSTALLED_INFO ItemInfo;
ATL::CStringW szText; ATL::CStringW szText;
@ -1633,20 +1633,20 @@ private:
return FALSE; return FALSE;
} }
Index = ListViewAddItem(ItemIndex, 0, m_szName, (LPARAM) ItemInfo); Index = m_ListView->AddItem(ItemIndex, 0, m_szName.GetString(), (LPARAM) ItemInfo);
/* Get version info */ /* Get version info */
ItemInfo->GetApplicationString(L"DisplayVersion", szText); ItemInfo->GetApplicationString(L"DisplayVersion", szText);
ListView_SetItemText(hListView, Index, 1, const_cast<LPWSTR>(szText.GetString())); m_ListView->SetItemText(Index, 1, szText.GetString());
/* Get comments */ /* Get comments */
ItemInfo->GetApplicationString(L"Comments", szText); ItemInfo->GetApplicationString(L"Comments", szText);
ListView_SetItemText(hListView, Index, 2, const_cast<LPWSTR>(szText.GetString())); m_ListView->SetItemText(Index, 2, szText.GetString());
return TRUE; return TRUE;
} }
static BOOL CALLBACK s_EnumAvailableAppProc(CAvailableApplicationInfo* Info, LPCWSTR szFolderPath) BOOL EnumAvailableAppProc(CAvailableApplicationInfo* Info, LPCWSTR szFolderPath)
{ {
INT Index; INT Index;
HICON hIcon = NULL; HICON hIcon = NULL;
@ -1678,16 +1678,27 @@ private:
Index = ImageList_AddIcon(hImageListView, hIcon); Index = ImageList_AddIcon(hImageListView, hIcon);
DestroyIcon(hIcon); DestroyIcon(hIcon);
Index = ListViewAddItem(Info->m_Category, Index, Info->m_szName.GetString(), (LPARAM) Info); Index = m_ListView->AddItem(Info->m_Category, Index, Info->m_szName.GetString(), (LPARAM) Info);
ListView_SetImageList(hListView, hImageListView, LVSIL_SMALL); m_ListView->SetImageList(hImageListView, LVSIL_SMALL);
m_ListView->SetItemText(Index, 1, Info->m_szVersion.GetString());
ListView_SetItemText(hListView, Index, 1, const_cast<LPWSTR>(Info->m_szVersion.GetString())); m_ListView->SetItemText(Index, 2, Info->m_szDesc.GetString());
ListView_SetItemText(hListView, Index, 2, const_cast<LPWSTR>(Info->m_szDesc.GetString())); m_ListView->SetCheckState(Index, Info->m_IsSelected);
ListView_SetCheckState(hListView, Index, Info->m_IsSelected);
return TRUE; return TRUE;
} }
static BOOL CALLBACK s_EnumInstalledAppProc(INT ItemIndex, ATL::CStringW &m_szName, PINSTALLED_INFO Info, PVOID param)
{
CMainWindow* pThis = (CMainWindow*)param;
return pThis->EnumInstalledAppProc(ItemIndex, m_szName, Info);
}
static BOOL CALLBACK s_EnumAvailableAppProc(CAvailableApplicationInfo* Info, LPCWSTR szFolderPath, PVOID param)
{
CMainWindow* pThis = (CMainWindow*)param;
return pThis->EnumAvailableAppProc(Info, szFolderPath);
}
VOID UpdateStatusBarText() VOID UpdateStatusBarText()
{ {
if (m_StatusBar) if (m_StatusBar)
@ -1745,8 +1756,8 @@ private:
DestroyIcon(hIcon); DestroyIcon(hIcon);
// Enum installed applications and updates // Enum installed applications and updates
EnumInstalledApplications(EnumType, TRUE, s_EnumInstalledAppProc); EnumInstalledApplications(EnumType, TRUE, s_EnumInstalledAppProc, this);
EnumInstalledApplications(EnumType, FALSE, s_EnumInstalledAppProc); EnumInstalledApplications(EnumType, FALSE, s_EnumInstalledAppProc, this);
} }
else if (IsAvailableEnum(EnumType)) else if (IsAvailableEnum(EnumType))
{ {
@ -1756,7 +1767,7 @@ private:
} }
// Enum available applications // Enum available applications
m_AvailableApps.Enum(EnumType, s_EnumAvailableAppProc); m_AvailableApps.Enum(EnumType, s_EnumAvailableAppProc, this);
} }
SelectedEnumType = EnumType; SelectedEnumType = EnumType;

View file

@ -79,7 +79,7 @@ private:
inline BOOL FindInLanguages(LCID what) const; inline BOOL FindInLanguages(LCID what) const;
}; };
typedef BOOL(CALLBACK *AVAILENUMPROC)(CAvailableApplicationInfo *Info, LPCWSTR szFolderPath); typedef BOOL(CALLBACK *AVAILENUMPROC)(CAvailableApplicationInfo *Info, LPCWSTR szFolderPath, PVOID param);
struct AvailableStrings struct AvailableStrings
{ {
@ -106,7 +106,7 @@ public:
static VOID DeleteCurrentAppsDB(); static VOID DeleteCurrentAppsDB();
VOID FreeCachedEntries(); VOID FreeCachedEntries();
BOOL Enum(INT EnumType, AVAILENUMPROC lpEnumProc); BOOL Enum(INT EnumType, AVAILENUMPROC lpEnumProc, PVOID param);
CAvailableApplicationInfo* FindInfo(const ATL::CStringW& szAppName) const; CAvailableApplicationInfo* FindInfo(const ATL::CStringW& szAppName) const;
ATL::CSimpleArray<CAvailableApplicationInfo> FindInfoList(const ATL::CSimpleArray<ATL::CStringW> &arrAppsNames) const; ATL::CSimpleArray<CAvailableApplicationInfo> FindInfoList(const ATL::CSimpleArray<ATL::CStringW> &arrAppsNames) const;

View file

@ -13,9 +13,9 @@ struct INSTALLED_INFO
}; };
typedef INSTALLED_INFO *PINSTALLED_INFO; typedef INSTALLED_INFO *PINSTALLED_INFO;
typedef BOOL(CALLBACK *APPENUMPROC)(INT ItemIndex, ATL::CStringW &Name, PINSTALLED_INFO Info); typedef BOOL(CALLBACK *APPENUMPROC)(INT ItemIndex, ATL::CStringW &Name, PINSTALLED_INFO Info, PVOID param);
BOOL EnumInstalledApplications(INT EnumType, BOOL IsUserKey, APPENUMPROC lpEnumProc); BOOL EnumInstalledApplications(INT EnumType, BOOL IsUserKey, APPENUMPROC lpEnumProc, PVOID param);
BOOL GetApplicationString(HKEY hKey, LPCWSTR lpKeyName, LPWSTR szString); BOOL GetApplicationString(HKEY hKey, LPCWSTR lpKeyName, LPWSTR szString);
BOOL UninstallApplication(INT Index, BOOL bModify); BOOL UninstallApplication(INT Index, BOOL bModify);

View file

@ -129,7 +129,7 @@ VOID RemoveAppFromRegistry(INT Index)
} }
} }
BOOL EnumInstalledApplications(INT EnumType, BOOL IsUserKey, APPENUMPROC lpEnumProc) BOOL EnumInstalledApplications(INT EnumType, BOOL IsUserKey, APPENUMPROC lpEnumProc, PVOID param)
{ {
DWORD dwSize = MAX_PATH, dwType, dwValue; DWORD dwSize = MAX_PATH, dwType, dwValue;
BOOL bIsSystemComponent, bIsUpdate; BOOL bIsSystemComponent, bIsUpdate;
@ -199,7 +199,7 @@ BOOL EnumInstalledApplications(INT EnumType, BOOL IsUserKey, APPENUMPROC lpEnumP
((EnumType == ENUM_INSTALLED_APPLICATIONS) && (!bIsUpdate)) || /* Applications only */ ((EnumType == ENUM_INSTALLED_APPLICATIONS) && (!bIsUpdate)) || /* Applications only */
((EnumType == ENUM_UPDATES) && (bIsUpdate))) /* Updates only */ ((EnumType == ENUM_UPDATES) && (bIsUpdate))) /* Updates only */
{ {
if (!lpEnumProc(ItemIndex, szDisplayName, &Info)) if (!lpEnumProc(ItemIndex, szDisplayName, &Info, param))
break; break;
} }
else else

View file

@ -62,7 +62,7 @@ BOOL UseCmdParameters(LPWSTR lpCmdLine)
CAvailableApps apps; CAvailableApps apps;
apps.UpdateAppsDB(); apps.UpdateAppsDB();
apps.Enum(ENUM_ALL_AVAILABLE, NULL); apps.Enum(ENUM_ALL_AVAILABLE, NULL, NULL);
ATL::CSimpleArray<CAvailableApplicationInfo> arrAppInfo = apps.FindInfoList(arrNames); ATL::CSimpleArray<CAvailableApplicationInfo> arrAppInfo = apps.FindInfoList(arrNames);
if (arrAppInfo.GetSize() > 0) if (arrAppInfo.GetSize() > 0)