2015-04-22 16:53:55 +00:00
|
|
|
/*
|
2017-09-09 20:38:06 +00:00
|
|
|
* PROJECT: ReactOS Applications Manager
|
|
|
|
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
|
|
|
|
* FILE: base/applications/rapps/available.cpp
|
|
|
|
* PURPOSE: Classes for working with available applications
|
|
|
|
* COPYRIGHT: Copyright 2009 Dmitry Chapyshev (dmitry@reactos.org)
|
|
|
|
* Copyright 2015 Ismael Ferreras Morezuelas (swyterzone+ros@gmail.com)
|
2017-09-09 20:44:43 +00:00
|
|
|
* Copyright 2017 Alexander Shaposhnikov (sanchaez@reactos.org)
|
2015-04-22 16:53:55 +00:00
|
|
|
*/
|
2017-09-10 23:44:22 +00:00
|
|
|
#include "rapps.h"
|
2015-04-22 16:53:55 +00:00
|
|
|
|
2017-08-02 12:50:53 +00:00
|
|
|
#include "available.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "dialogs.h"
|
|
|
|
|
|
|
|
#include <atlcoll.h>
|
|
|
|
#include <atlsimpcoll.h>
|
|
|
|
#include <atlstr.h>
|
2015-04-22 16:53:55 +00:00
|
|
|
|
2017-07-18 22:52:51 +00:00
|
|
|
// CAvailableApplicationInfo
|
|
|
|
CAvailableApplicationInfo::CAvailableApplicationInfo(const ATL::CStringW& sFileNameParam)
|
2018-01-02 20:45:59 +00:00
|
|
|
: m_IsSelected(FALSE), m_LicenseType(LICENSE_NONE), m_sFileName(sFileNameParam),
|
|
|
|
m_IsInstalled(FALSE), m_HasLanguageInfo(FALSE), m_HasInstalledVersion(FALSE)
|
2017-06-27 23:33:15 +00:00
|
|
|
{
|
2017-07-19 10:39:03 +00:00
|
|
|
RetrieveGeneralInfo();
|
2017-06-25 01:09:00 +00:00
|
|
|
}
|
|
|
|
|
2017-07-18 22:52:51 +00:00
|
|
|
VOID CAvailableApplicationInfo::RefreshAppInfo()
|
2017-06-27 23:33:15 +00:00
|
|
|
{
|
2017-09-03 20:37:14 +00:00
|
|
|
if (m_szUrlDownload.IsEmpty())
|
2017-07-10 21:02:24 +00:00
|
|
|
{
|
2017-07-19 10:39:03 +00:00
|
|
|
RetrieveGeneralInfo();
|
2017-07-10 21:02:24 +00:00
|
|
|
}
|
2017-06-25 01:09:00 +00:00
|
|
|
}
|
|
|
|
|
2017-08-02 12:50:53 +00:00
|
|
|
// Lazily load general info from the file
|
2017-07-19 10:39:03 +00:00
|
|
|
VOID CAvailableApplicationInfo::RetrieveGeneralInfo()
|
2017-06-27 23:33:15 +00:00
|
|
|
{
|
2017-10-21 21:52:49 +00:00
|
|
|
m_Parser = new CConfigParser(m_sFileName);
|
|
|
|
|
2018-04-07 16:17:22 +00:00
|
|
|
m_Parser->GetInt(L"Category", m_Category);
|
2017-07-19 10:39:03 +00:00
|
|
|
|
2017-09-03 20:37:14 +00:00
|
|
|
if (!GetString(L"Name", m_szName)
|
|
|
|
|| !GetString(L"URLDownload", m_szUrlDownload))
|
2017-06-27 23:33:15 +00:00
|
|
|
{
|
2017-10-21 21:52:49 +00:00
|
|
|
delete m_Parser;
|
2017-07-19 10:39:03 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-07-13 15:29:53 +00:00
|
|
|
|
2017-09-03 20:37:14 +00:00
|
|
|
GetString(L"RegName", m_szRegName);
|
|
|
|
GetString(L"Version", m_szVersion);
|
|
|
|
GetString(L"License", m_szLicense);
|
|
|
|
GetString(L"Description", m_szDesc);
|
|
|
|
GetString(L"URLSite", m_szUrlSite);
|
|
|
|
GetString(L"CDPath", m_szCDPath);
|
|
|
|
GetString(L"Language", m_szRegName);
|
|
|
|
GetString(L"SHA1", m_szSHA1);
|
2017-07-19 10:39:03 +00:00
|
|
|
|
2018-04-07 16:17:22 +00:00
|
|
|
RetrieveSize();
|
2017-07-19 10:39:03 +00:00
|
|
|
RetrieveLicenseType();
|
|
|
|
RetrieveLanguages();
|
|
|
|
RetrieveInstalledStatus();
|
2018-04-07 16:17:22 +00:00
|
|
|
|
2017-07-19 10:39:03 +00:00
|
|
|
if (m_IsInstalled)
|
|
|
|
{
|
|
|
|
RetrieveInstalledVersion();
|
2017-07-18 22:52:51 +00:00
|
|
|
}
|
2017-10-21 21:52:49 +00:00
|
|
|
|
|
|
|
delete m_Parser;
|
2017-06-25 01:09:00 +00:00
|
|
|
}
|
|
|
|
|
2017-07-18 22:52:51 +00:00
|
|
|
VOID CAvailableApplicationInfo::RetrieveInstalledStatus()
|
2017-06-27 23:33:15 +00:00
|
|
|
{
|
2017-09-03 20:37:14 +00:00
|
|
|
m_IsInstalled = ::GetInstalledVersion(NULL, m_szRegName)
|
|
|
|
|| ::GetInstalledVersion(NULL, m_szName);
|
2017-06-27 23:21:58 +00:00
|
|
|
}
|
|
|
|
|
2017-07-18 22:52:51 +00:00
|
|
|
VOID CAvailableApplicationInfo::RetrieveInstalledVersion()
|
2017-06-27 23:21:58 +00:00
|
|
|
{
|
2017-09-10 21:02:06 +00:00
|
|
|
ATL::CStringW szNameVersion;
|
|
|
|
szNameVersion = m_szName + L" " + m_szVersion;
|
2017-09-03 20:37:14 +00:00
|
|
|
m_HasInstalledVersion = ::GetInstalledVersion(&m_szInstalledVersion, m_szRegName)
|
|
|
|
|| ::GetInstalledVersion(&m_szInstalledVersion, m_szName)
|
|
|
|
|| ::GetInstalledVersion(&m_szInstalledVersion, szNameVersion);
|
2017-06-25 01:09:00 +00:00
|
|
|
}
|
|
|
|
|
2017-07-19 10:39:03 +00:00
|
|
|
VOID CAvailableApplicationInfo::RetrieveLanguages()
|
2017-07-13 15:29:53 +00:00
|
|
|
{
|
|
|
|
const WCHAR cDelimiter = L'|';
|
|
|
|
ATL::CStringW szBuffer;
|
|
|
|
|
2017-07-18 22:52:51 +00:00
|
|
|
// TODO: Get multiline parameter
|
2017-10-21 21:52:49 +00:00
|
|
|
if (!m_Parser->GetString(L"Languages", szBuffer))
|
2017-07-19 10:39:03 +00:00
|
|
|
{
|
|
|
|
m_HasLanguageInfo = FALSE;
|
|
|
|
return;
|
|
|
|
}
|
2017-07-13 15:29:53 +00:00
|
|
|
|
2017-07-18 22:52:51 +00:00
|
|
|
// Parse parameter string
|
2017-07-19 10:39:03 +00:00
|
|
|
ATL::CStringW m_szLocale;
|
2017-08-15 22:35:45 +00:00
|
|
|
INT iLCID;
|
2017-07-13 15:29:53 +00:00
|
|
|
for (INT i = 0; szBuffer[i] != UNICODE_NULL; ++i)
|
|
|
|
{
|
2017-07-20 22:57:48 +00:00
|
|
|
if (szBuffer[i] != cDelimiter && szBuffer[i] != L'\n')
|
2017-07-13 15:29:53 +00:00
|
|
|
{
|
2017-07-19 10:39:03 +00:00
|
|
|
m_szLocale += szBuffer[i];
|
2017-07-18 22:52:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-07-20 22:57:48 +00:00
|
|
|
if (StrToIntExW(m_szLocale.GetString(), STIF_DEFAULT, &iLCID))
|
|
|
|
{
|
2017-09-03 20:37:14 +00:00
|
|
|
m_LanguageLCIDs.Add(static_cast<LCID>(iLCID));
|
2017-07-20 22:57:48 +00:00
|
|
|
m_szLocale.Empty();
|
|
|
|
}
|
2017-07-13 15:29:53 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-18 22:52:51 +00:00
|
|
|
|
2017-07-13 15:29:53 +00:00
|
|
|
// For the text after delimiter
|
2017-07-19 10:39:03 +00:00
|
|
|
if (!m_szLocale.IsEmpty())
|
2017-07-13 15:29:53 +00:00
|
|
|
{
|
2017-07-20 22:57:48 +00:00
|
|
|
if (StrToIntExW(m_szLocale.GetString(), STIF_DEFAULT, &iLCID))
|
|
|
|
{
|
2017-09-03 20:37:14 +00:00
|
|
|
m_LanguageLCIDs.Add(static_cast<LCID>(iLCID));
|
2017-07-20 22:57:48 +00:00
|
|
|
}
|
2017-07-13 15:29:53 +00:00
|
|
|
}
|
2017-07-18 22:52:51 +00:00
|
|
|
|
2017-07-19 10:39:03 +00:00
|
|
|
m_HasLanguageInfo = TRUE;
|
2017-07-13 15:29:53 +00:00
|
|
|
}
|
|
|
|
|
2017-07-18 22:52:51 +00:00
|
|
|
VOID CAvailableApplicationInfo::RetrieveLicenseType()
|
2017-07-13 15:29:53 +00:00
|
|
|
{
|
2018-04-07 16:17:22 +00:00
|
|
|
INT IntBuffer;
|
|
|
|
|
|
|
|
m_Parser->GetInt(L"LicenseType", IntBuffer);
|
2017-07-18 22:52:51 +00:00
|
|
|
|
2017-09-03 20:37:14 +00:00
|
|
|
if (IsLicenseType(IntBuffer))
|
2017-07-13 15:29:53 +00:00
|
|
|
{
|
2017-09-03 20:37:14 +00:00
|
|
|
m_LicenseType = static_cast<LicenseType>(IntBuffer);
|
2017-07-18 22:52:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-09-10 21:02:06 +00:00
|
|
|
m_LicenseType = LICENSE_NONE;
|
2017-07-13 15:29:53 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-18 22:52:51 +00:00
|
|
|
|
2018-04-07 16:17:22 +00:00
|
|
|
VOID CAvailableApplicationInfo::RetrieveSize()
|
|
|
|
{
|
|
|
|
INT iSizeBytes;
|
|
|
|
|
|
|
|
if (!m_Parser->GetInt(L"SizeBytes", iSizeBytes))
|
|
|
|
{
|
|
|
|
// fall back to "Size" string
|
|
|
|
GetString(L"Size", m_szSize);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
StrFormatByteSizeW(iSizeBytes, m_szSize.GetBuffer(MAX_PATH), MAX_PATH);
|
|
|
|
m_szSize.ReleaseBuffer();
|
|
|
|
}
|
|
|
|
|
2017-07-20 22:57:48 +00:00
|
|
|
BOOL CAvailableApplicationInfo::FindInLanguages(LCID what) const
|
2017-07-18 22:52:51 +00:00
|
|
|
{
|
|
|
|
if (!m_HasLanguageInfo)
|
2017-07-13 22:01:02 +00:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2017-07-18 22:52:51 +00:00
|
|
|
|
2017-07-19 10:39:03 +00:00
|
|
|
//Find locale code in the list
|
2017-09-03 20:37:14 +00:00
|
|
|
const INT nLanguagesSize = m_LanguageLCIDs.GetSize();
|
2017-07-19 10:39:03 +00:00
|
|
|
for (INT i = 0; i < nLanguagesSize; ++i)
|
|
|
|
{
|
2017-09-03 20:37:14 +00:00
|
|
|
if (m_LanguageLCIDs[i] == what)
|
2017-07-19 10:39:03 +00:00
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
2017-07-13 22:01:02 +00:00
|
|
|
}
|
2017-07-13 15:29:53 +00:00
|
|
|
|
2017-07-20 22:57:48 +00:00
|
|
|
BOOL CAvailableApplicationInfo::HasLanguageInfo() const
|
2017-07-13 15:29:53 +00:00
|
|
|
{
|
2017-07-20 22:57:48 +00:00
|
|
|
return m_HasLanguageInfo;
|
|
|
|
}
|
2017-07-19 10:39:03 +00:00
|
|
|
|
2017-07-20 22:57:48 +00:00
|
|
|
BOOL CAvailableApplicationInfo::HasNativeLanguage() const
|
|
|
|
{
|
|
|
|
return FindInLanguages(GetUserDefaultLCID());
|
|
|
|
}
|
2017-07-19 10:39:03 +00:00
|
|
|
|
2017-07-20 22:57:48 +00:00
|
|
|
BOOL CAvailableApplicationInfo::HasEnglishLanguage() const
|
|
|
|
{
|
|
|
|
return FindInLanguages(MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), SORT_DEFAULT));
|
2017-07-18 22:52:51 +00:00
|
|
|
}
|
2015-04-22 16:53:55 +00:00
|
|
|
|
2017-07-18 22:52:51 +00:00
|
|
|
BOOL CAvailableApplicationInfo::IsInstalled() const
|
2015-04-22 16:53:55 +00:00
|
|
|
{
|
2017-07-18 22:52:51 +00:00
|
|
|
return m_IsInstalled;
|
2017-07-13 15:29:53 +00:00
|
|
|
}
|
|
|
|
|
2017-07-18 22:52:51 +00:00
|
|
|
BOOL CAvailableApplicationInfo::HasInstalledVersion() const
|
2017-07-13 15:29:53 +00:00
|
|
|
{
|
2017-07-18 22:52:51 +00:00
|
|
|
return m_HasInstalledVersion;
|
|
|
|
}
|
2017-07-10 21:02:24 +00:00
|
|
|
|
2017-07-18 22:52:51 +00:00
|
|
|
BOOL CAvailableApplicationInfo::HasUpdate() const
|
|
|
|
{
|
2017-09-03 20:37:14 +00:00
|
|
|
return (m_szInstalledVersion.Compare(m_szVersion) < 0) ? TRUE : FALSE;
|
2017-07-13 15:29:53 +00:00
|
|
|
}
|
|
|
|
|
2017-07-18 22:52:51 +00:00
|
|
|
VOID CAvailableApplicationInfo::SetLastWriteTime(FILETIME* ftTime)
|
2017-07-13 22:01:02 +00:00
|
|
|
{
|
2017-09-03 20:37:14 +00:00
|
|
|
RtlCopyMemory(&m_ftCacheStamp, ftTime, sizeof(FILETIME));
|
2017-07-18 22:52:51 +00:00
|
|
|
}
|
2017-07-13 22:01:02 +00:00
|
|
|
|
2017-07-18 22:52:51 +00:00
|
|
|
inline BOOL CAvailableApplicationInfo::GetString(LPCWSTR lpKeyName, ATL::CStringW& ReturnedString)
|
|
|
|
{
|
2017-10-21 21:52:49 +00:00
|
|
|
if (!m_Parser->GetString(lpKeyName, ReturnedString))
|
2017-07-13 22:01:02 +00:00
|
|
|
{
|
2017-07-18 22:52:51 +00:00
|
|
|
ReturnedString.Empty();
|
|
|
|
return FALSE;
|
2017-07-13 22:01:02 +00:00
|
|
|
}
|
2017-07-18 22:52:51 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2018-02-03 22:42:46 +00:00
|
|
|
// CAvailableApplicationInfo
|
2017-07-13 22:01:02 +00:00
|
|
|
|
2018-01-02 00:07:12 +00:00
|
|
|
// AvailableStrings
|
|
|
|
AvailableStrings::AvailableStrings()
|
2017-07-18 22:52:51 +00:00
|
|
|
{
|
2017-08-24 22:04:44 +00:00
|
|
|
//FIXME: maybe provide a fallback?
|
2018-01-02 00:07:12 +00:00
|
|
|
if (GetStorageDirectory(szPath))
|
2017-07-13 22:01:02 +00:00
|
|
|
{
|
2018-01-02 00:07:12 +00:00
|
|
|
szAppsPath = szPath + L"\\rapps\\";
|
2018-02-25 13:20:00 +00:00
|
|
|
szCabName = L"rappmgr.cab";
|
|
|
|
szCabDir = szPath;
|
|
|
|
szCabPath = (szCabDir + L"\\") + szCabName;
|
2018-01-02 00:07:12 +00:00
|
|
|
szSearchPath = szAppsPath + L"*.txt";
|
2017-07-13 22:01:02 +00:00
|
|
|
}
|
2017-08-24 22:04:44 +00:00
|
|
|
}
|
2018-01-02 00:07:12 +00:00
|
|
|
// AvailableStrings
|
|
|
|
|
|
|
|
// CAvailableApps
|
|
|
|
AvailableStrings CAvailableApps::m_Strings;
|
2017-08-24 22:04:44 +00:00
|
|
|
|
|
|
|
CAvailableApps::CAvailableApps()
|
|
|
|
{
|
2017-07-13 22:01:02 +00:00
|
|
|
}
|
|
|
|
|
2017-07-18 22:52:51 +00:00
|
|
|
VOID CAvailableApps::FreeCachedEntries()
|
2017-07-13 15:29:53 +00:00
|
|
|
{
|
2017-07-18 22:52:51 +00:00
|
|
|
POSITION InfoListPosition = m_InfoList.GetHeadPosition();
|
2017-07-13 15:29:53 +00:00
|
|
|
|
2017-07-18 22:52:51 +00:00
|
|
|
/* loop and deallocate all the cached app infos in the list */
|
|
|
|
while (InfoListPosition)
|
|
|
|
{
|
2017-08-26 19:41:09 +00:00
|
|
|
CAvailableApplicationInfo* Info = m_InfoList.GetNext(InfoListPosition);
|
2017-07-18 22:52:51 +00:00
|
|
|
delete Info;
|
|
|
|
}
|
2017-08-26 19:41:09 +00:00
|
|
|
|
|
|
|
m_InfoList.RemoveAll();
|
2015-04-22 16:53:55 +00:00
|
|
|
}
|
|
|
|
|
2017-08-24 18:46:39 +00:00
|
|
|
VOID CAvailableApps::DeleteCurrentAppsDB()
|
2015-04-22 16:53:55 +00:00
|
|
|
{
|
|
|
|
HANDLE hFind = INVALID_HANDLE_VALUE;
|
|
|
|
WIN32_FIND_DATAW FindFileData;
|
|
|
|
|
2018-01-02 00:07:12 +00:00
|
|
|
hFind = FindFirstFileW(m_Strings.szSearchPath.GetString(), &FindFileData);
|
2015-04-22 16:53:55 +00:00
|
|
|
|
2017-08-24 18:46:39 +00:00
|
|
|
if (hFind != INVALID_HANDLE_VALUE)
|
2015-04-22 16:53:55 +00:00
|
|
|
{
|
2017-08-24 18:46:39 +00:00
|
|
|
ATL::CStringW szTmp;
|
|
|
|
do
|
|
|
|
{
|
2018-01-02 00:07:12 +00:00
|
|
|
szTmp = m_Strings.szAppsPath + FindFileData.cFileName;
|
2017-08-24 18:46:39 +00:00
|
|
|
DeleteFileW(szTmp.GetString());
|
|
|
|
} while (FindNextFileW(hFind, &FindFileData) != 0);
|
|
|
|
FindClose(hFind);
|
|
|
|
}
|
2017-08-24 22:04:44 +00:00
|
|
|
|
2018-01-02 00:07:12 +00:00
|
|
|
RemoveDirectoryW(m_Strings.szAppsPath);
|
|
|
|
RemoveDirectoryW(m_Strings.szPath);
|
2015-04-22 16:53:55 +00:00
|
|
|
}
|
|
|
|
|
2017-07-18 22:52:51 +00:00
|
|
|
BOOL CAvailableApps::UpdateAppsDB()
|
2015-04-22 16:53:55 +00:00
|
|
|
{
|
2017-08-24 22:04:44 +00:00
|
|
|
HANDLE hFind = INVALID_HANDLE_VALUE;
|
|
|
|
WIN32_FIND_DATAW FindFileData;
|
2015-04-22 16:53:55 +00:00
|
|
|
|
2018-01-02 00:07:12 +00:00
|
|
|
if (!CreateDirectoryW(m_Strings.szPath, NULL) && GetLastError() != ERROR_ALREADY_EXISTS)
|
2017-08-24 22:04:44 +00:00
|
|
|
{
|
2015-04-22 16:53:55 +00:00
|
|
|
return FALSE;
|
2017-08-24 22:04:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//if there are some files in the db folder - we're good
|
2018-01-02 00:07:12 +00:00
|
|
|
hFind = FindFirstFileW(m_Strings.szSearchPath, &FindFileData);
|
2017-08-24 22:04:44 +00:00
|
|
|
if (hFind != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
2017-10-21 08:49:02 +00:00
|
|
|
FindClose(hFind);
|
2017-08-24 22:04:44 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-04-28 03:19:43 +00:00
|
|
|
DownloadApplicationsDB(APPLICATION_DATABASE_URL);
|
2015-04-22 16:53:55 +00:00
|
|
|
|
2018-02-25 13:20:00 +00:00
|
|
|
if (!ExtractFilesFromCab(m_Strings.szCabName,
|
|
|
|
m_Strings.szCabDir,
|
|
|
|
m_Strings.szAppsPath))
|
2015-04-22 16:53:55 +00:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-01-02 00:07:12 +00:00
|
|
|
DeleteFileW(m_Strings.szCabPath);
|
2017-08-24 22:04:44 +00:00
|
|
|
|
2015-04-22 16:53:55 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-08-24 22:04:44 +00:00
|
|
|
BOOL CAvailableApps::ForceUpdateAppsDB()
|
|
|
|
{
|
|
|
|
DeleteCurrentAppsDB();
|
|
|
|
return UpdateAppsDB();
|
|
|
|
}
|
|
|
|
|
2019-04-28 03:39:02 +00:00
|
|
|
BOOL CAvailableApps::Enum(INT EnumType, AVAILENUMPROC lpEnumProc, PVOID param)
|
2015-04-22 16:53:55 +00:00
|
|
|
{
|
2017-08-26 19:41:09 +00:00
|
|
|
|
2015-04-22 16:53:55 +00:00
|
|
|
HANDLE hFind = INVALID_HANDLE_VALUE;
|
|
|
|
WIN32_FIND_DATAW FindFileData;
|
|
|
|
|
2018-01-02 00:07:12 +00:00
|
|
|
hFind = FindFirstFileW(m_Strings.szSearchPath.GetString(), &FindFileData);
|
2015-04-22 16:53:55 +00:00
|
|
|
|
|
|
|
if (hFind == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
2017-08-24 22:04:44 +00:00
|
|
|
//no db yet
|
|
|
|
return FALSE;
|
2015-04-22 16:53:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2017-07-19 10:39:03 +00:00
|
|
|
// loop for all the cached entries
|
2017-07-18 22:52:51 +00:00
|
|
|
POSITION CurrentListPosition = m_InfoList.GetHeadPosition();
|
|
|
|
CAvailableApplicationInfo* Info = NULL;
|
2017-07-10 21:02:24 +00:00
|
|
|
|
|
|
|
while (CurrentListPosition != NULL)
|
2015-04-22 16:53:55 +00:00
|
|
|
{
|
2017-07-10 21:02:24 +00:00
|
|
|
POSITION LastListPosition = CurrentListPosition;
|
2017-07-18 22:52:51 +00:00
|
|
|
Info = m_InfoList.GetNext(CurrentListPosition);
|
2015-04-22 16:53:55 +00:00
|
|
|
|
2017-07-19 10:39:03 +00:00
|
|
|
// do we already have this entry in cache?
|
2017-09-03 20:37:14 +00:00
|
|
|
if (Info->m_sFileName == FindFileData.cFileName)
|
2015-04-22 16:53:55 +00:00
|
|
|
{
|
2017-07-19 10:39:03 +00:00
|
|
|
// is it current enough, or the file has been modified since our last time here?
|
2017-09-03 20:37:14 +00:00
|
|
|
if (CompareFileTime(&FindFileData.ftLastWriteTime, &Info->m_ftCacheStamp) == 1)
|
2015-04-22 16:53:55 +00:00
|
|
|
{
|
2017-07-19 10:39:03 +00:00
|
|
|
// recreate our cache, this is the slow path
|
2017-07-18 22:52:51 +00:00
|
|
|
m_InfoList.RemoveAt(LastListPosition);
|
|
|
|
|
2017-07-10 21:02:24 +00:00
|
|
|
delete Info;
|
2017-07-26 13:30:46 +00:00
|
|
|
Info = NULL;
|
2017-07-10 21:02:24 +00:00
|
|
|
break;
|
2015-04-22 16:53:55 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-07-19 10:39:03 +00:00
|
|
|
// speedy path, compare directly, we already have the data
|
2015-04-22 16:53:55 +00:00
|
|
|
goto skip_if_cached;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-19 10:39:03 +00:00
|
|
|
// create a new entry
|
2017-07-18 22:52:51 +00:00
|
|
|
Info = new CAvailableApplicationInfo(FindFileData.cFileName);
|
2015-04-22 16:53:55 +00:00
|
|
|
|
2017-07-19 10:39:03 +00:00
|
|
|
// set a timestamp for the next time
|
2017-07-18 22:52:51 +00:00
|
|
|
Info->SetLastWriteTime(&FindFileData.ftLastWriteTime);
|
|
|
|
m_InfoList.AddTail(Info);
|
2015-04-22 16:53:55 +00:00
|
|
|
|
2017-07-10 21:02:24 +00:00
|
|
|
skip_if_cached:
|
2018-02-03 22:42:46 +00:00
|
|
|
if (EnumType == Info->m_Category
|
|
|
|
|| EnumType == ENUM_ALL_AVAILABLE
|
2018-01-02 20:45:59 +00:00
|
|
|
|| (EnumType == ENUM_CAT_SELECTED && Info->m_IsSelected))
|
|
|
|
{
|
|
|
|
Info->RefreshAppInfo();
|
2015-04-22 16:53:55 +00:00
|
|
|
|
2018-01-02 20:45:59 +00:00
|
|
|
if (lpEnumProc)
|
2019-04-28 03:39:02 +00:00
|
|
|
lpEnumProc(Info, m_Strings.szAppsPath.GetString(), param);
|
2018-01-02 20:45:59 +00:00
|
|
|
}
|
2017-07-10 21:02:24 +00:00
|
|
|
} while (FindNextFileW(hFind, &FindFileData) != 0);
|
2015-04-22 16:53:55 +00:00
|
|
|
|
|
|
|
FindClose(hFind);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-09-03 20:37:14 +00:00
|
|
|
CAvailableApplicationInfo* CAvailableApps::FindInfo(const ATL::CStringW& szAppName) const
|
2017-08-14 17:00:20 +00:00
|
|
|
{
|
|
|
|
if (m_InfoList.IsEmpty())
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// linear search
|
|
|
|
POSITION CurrentListPosition = m_InfoList.GetHeadPosition();
|
2017-08-26 22:43:05 +00:00
|
|
|
CAvailableApplicationInfo* info;
|
2017-08-14 17:00:20 +00:00
|
|
|
while (CurrentListPosition != NULL)
|
|
|
|
{
|
|
|
|
info = m_InfoList.GetNext(CurrentListPosition);
|
2018-06-05 20:08:18 +00:00
|
|
|
if (info->m_szName.CompareNoCase(szAppName) == 0)
|
2017-08-14 17:00:20 +00:00
|
|
|
{
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-10-21 21:00:50 +00:00
|
|
|
ATL::CSimpleArray<CAvailableApplicationInfo> CAvailableApps::FindInfoList(const ATL::CSimpleArray<ATL::CStringW> &arrAppsNames) const
|
2017-08-15 19:36:23 +00:00
|
|
|
{
|
2017-10-21 21:00:50 +00:00
|
|
|
ATL::CSimpleArray<CAvailableApplicationInfo> result;
|
2017-08-15 22:35:45 +00:00
|
|
|
for (INT i = 0; i < arrAppsNames.GetSize(); ++i)
|
2017-08-15 19:36:23 +00:00
|
|
|
{
|
2017-08-26 22:43:05 +00:00
|
|
|
CAvailableApplicationInfo* Info = FindInfo(arrAppsNames[i]);
|
2017-08-15 19:36:23 +00:00
|
|
|
if (Info)
|
|
|
|
{
|
2017-10-21 21:00:50 +00:00
|
|
|
result.Add(*Info);
|
2017-08-15 19:36:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-01-02 20:45:59 +00:00
|
|
|
ATL::CSimpleArray<CAvailableApplicationInfo> CAvailableApps::GetSelected() const
|
|
|
|
{
|
|
|
|
ATL::CSimpleArray<CAvailableApplicationInfo> result;
|
|
|
|
POSITION CurrentListPosition = m_InfoList.GetHeadPosition();
|
|
|
|
CAvailableApplicationInfo* Info;
|
|
|
|
|
|
|
|
while (CurrentListPosition != NULL)
|
|
|
|
{
|
|
|
|
Info = m_InfoList.GetNext(CurrentListPosition);
|
|
|
|
if (Info->m_IsSelected)
|
|
|
|
{
|
|
|
|
result.Add(*Info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-09-03 20:37:14 +00:00
|
|
|
const ATL::CStringW& CAvailableApps::GetFolderPath() const
|
2015-04-22 16:53:55 +00:00
|
|
|
{
|
2018-01-02 00:07:12 +00:00
|
|
|
return m_Strings.szPath;
|
2017-07-18 22:52:51 +00:00
|
|
|
}
|
2017-07-13 15:29:53 +00:00
|
|
|
|
2017-09-03 20:37:14 +00:00
|
|
|
const ATL::CStringW& CAvailableApps::GetAppPath() const
|
2017-07-18 22:52:51 +00:00
|
|
|
{
|
2018-01-02 00:07:12 +00:00
|
|
|
return m_Strings.szAppsPath;
|
2017-07-18 22:52:51 +00:00
|
|
|
}
|
|
|
|
|
2017-09-03 20:37:14 +00:00
|
|
|
const ATL::CStringW& CAvailableApps::GetCabPath() const
|
2017-07-18 22:52:51 +00:00
|
|
|
{
|
2018-01-02 00:07:12 +00:00
|
|
|
return m_Strings.szCabPath;
|
2017-07-18 22:52:51 +00:00
|
|
|
}
|
2017-07-19 10:39:03 +00:00
|
|
|
// CAvailableApps
|