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)
|
2017-09-10 21:02:06 +00:00
|
|
|
: m_IsInstalled(FALSE), m_HasLanguageInfo(FALSE), m_HasInstalledVersion(FALSE), m_Parser(sFileNameParam)
|
2017-06-27 23:33:15 +00:00
|
|
|
{
|
2017-09-10 21:02:06 +00:00
|
|
|
m_LicenseType = LICENSE_NONE;
|
2017-08-26 22:43:05 +00:00
|
|
|
|
2017-09-03 20:37:14 +00:00
|
|
|
m_sFileName = sFileNameParam;
|
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-09-03 20:37:14 +00:00
|
|
|
m_Category = m_Parser.GetInt(L"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-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"Size", m_szSize);
|
|
|
|
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
|
|
|
|
|
|
|
RetrieveLicenseType();
|
|
|
|
RetrieveLanguages();
|
|
|
|
RetrieveInstalledStatus();
|
|
|
|
if (m_IsInstalled)
|
|
|
|
{
|
|
|
|
RetrieveInstalledVersion();
|
2017-07-18 22:52:51 +00:00
|
|
|
}
|
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-07-19 10:39:03 +00:00
|
|
|
if (!m_Parser.GetString(L"Languages", szBuffer))
|
|
|
|
{
|
|
|
|
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
|
|
|
{
|
2017-07-19 10:39:03 +00:00
|
|
|
INT IntBuffer = m_Parser.GetInt(L"LicenseType");
|
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
|
|
|
|
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-07-19 10:39:03 +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;
|
|
|
|
}
|
2017-07-19 10:39:03 +00:00
|
|
|
// CAvailableApplicationInfo
|
2017-07-13 22:01:02 +00:00
|
|
|
|
2017-07-18 22:52:51 +00:00
|
|
|
// CAvailableApps
|
2017-08-24 22:04:44 +00:00
|
|
|
ATL::CStringW CAvailableApps::m_szPath;
|
|
|
|
ATL::CStringW CAvailableApps::m_szCabPath;
|
|
|
|
ATL::CStringW CAvailableApps::m_szAppsPath;
|
|
|
|
ATL::CStringW CAvailableApps::m_szSearchPath;
|
|
|
|
|
|
|
|
BOOL CAvailableApps::InitializeStaticStrings()
|
2017-07-18 22:52:51 +00:00
|
|
|
{
|
2017-08-26 08:39:42 +00:00
|
|
|
|
|
|
|
if (!m_szPath.IsEmpty())
|
|
|
|
{
|
|
|
|
// strings are filled
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-08-24 22:04:44 +00:00
|
|
|
//FIXME: maybe provide a fallback?
|
2017-08-26 08:39:42 +00:00
|
|
|
if (GetStorageDirectory(m_szPath))
|
2017-07-13 22:01:02 +00:00
|
|
|
{
|
2017-07-18 22:52:51 +00:00
|
|
|
m_szAppsPath = m_szPath + L"\\rapps\\";
|
|
|
|
m_szCabPath = m_szPath + L"\\rappmgr.cab";
|
|
|
|
m_szSearchPath = m_szAppsPath + L"*.txt";
|
2017-08-24 22:04:44 +00:00
|
|
|
return TRUE;
|
2017-07-13 22:01:02 +00:00
|
|
|
}
|
2017-08-26 08:39:42 +00:00
|
|
|
|
2017-08-24 22:04:44 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
CAvailableApps::CAvailableApps()
|
|
|
|
{
|
|
|
|
//set all paths
|
|
|
|
InitializeStaticStrings();
|
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;
|
|
|
|
|
2017-08-26 08:39:42 +00:00
|
|
|
if (!InitializeStaticStrings())
|
|
|
|
{
|
2017-08-24 18:46:39 +00:00
|
|
|
return;
|
2017-08-26 08:39:42 +00:00
|
|
|
}
|
2015-04-22 16:53:55 +00:00
|
|
|
|
2017-07-18 22:52:51 +00:00
|
|
|
hFind = FindFirstFileW(m_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
|
|
|
|
{
|
2017-08-26 08:39:42 +00:00
|
|
|
szTmp = m_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
|
|
|
|
|
|
|
RemoveDirectoryW(m_szAppsPath);
|
|
|
|
RemoveDirectoryW(m_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
|
|
|
|
2017-08-26 08:39:42 +00:00
|
|
|
if (!InitializeStaticStrings())
|
2017-08-24 22:04:44 +00:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2015-04-22 16:53:55 +00:00
|
|
|
|
2017-08-24 22:04:44 +00:00
|
|
|
if (!CreateDirectoryW(m_szPath.GetString(), NULL) && GetLastError() != ERROR_ALREADY_EXISTS)
|
|
|
|
{
|
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
|
|
|
|
hFind = FindFirstFileW(m_szSearchPath.GetString(), &FindFileData);
|
|
|
|
if (hFind != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
CDownloadManager::DownloadApplicationsDB(APPLICATION_DATABASE_URL);
|
2015-04-22 16:53:55 +00:00
|
|
|
|
2017-07-18 22:52:51 +00:00
|
|
|
if (!ExtractFilesFromCab(m_szCabPath, m_szAppsPath))
|
2015-04-22 16:53:55 +00:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2017-08-24 22:04:44 +00:00
|
|
|
DeleteFileW(m_szCabPath.GetString());
|
|
|
|
|
2015-04-22 16:53:55 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-08-24 22:04:44 +00:00
|
|
|
BOOL CAvailableApps::ForceUpdateAppsDB()
|
|
|
|
{
|
|
|
|
DeleteCurrentAppsDB();
|
|
|
|
return UpdateAppsDB();
|
|
|
|
}
|
|
|
|
|
2017-09-03 20:37:14 +00:00
|
|
|
BOOL CAvailableApps::Enum(INT EnumType, AVAILENUMPROC lpEnumProc)
|
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;
|
|
|
|
|
2017-07-18 22:52:51 +00:00
|
|
|
hFind = FindFirstFileW(m_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:
|
2017-09-03 20:37:14 +00:00
|
|
|
if (Info->m_Category == FALSE)
|
2015-04-22 16:53:55 +00:00
|
|
|
continue;
|
|
|
|
|
2017-09-03 20:37:14 +00:00
|
|
|
if (EnumType != Info->m_Category && EnumType != ENUM_ALL_AVAILABLE)
|
2015-04-22 16:53:55 +00:00
|
|
|
continue;
|
|
|
|
|
2017-07-18 22:52:51 +00:00
|
|
|
Info->RefreshAppInfo();
|
2015-04-22 16:53:55 +00:00
|
|
|
|
2017-08-14 17:00:20 +00:00
|
|
|
if (lpEnumProc)
|
2017-08-26 22:43:05 +00:00
|
|
|
lpEnumProc(static_cast<CAvailableApplicationInfo*>(Info), m_szAppsPath.GetString());
|
2015-04-22 16:53:55 +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);
|
2017-09-03 20:37:14 +00:00
|
|
|
if (info->m_szName == szAppName)
|
2017-08-14 17:00:20 +00:00
|
|
|
{
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-09-03 20:37:14 +00:00
|
|
|
ATL::CSimpleArray<CAvailableApplicationInfo*> CAvailableApps::FindInfoList(const ATL::CSimpleArray<ATL::CStringW> &arrAppsNames) const
|
2017-08-15 19:36:23 +00:00
|
|
|
{
|
2017-08-26 22:43:05 +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)
|
|
|
|
{
|
|
|
|
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
|
|
|
{
|
2017-07-18 22:52:51 +00:00
|
|
|
return m_szPath;
|
|
|
|
}
|
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
|
|
|
{
|
|
|
|
return m_szAppsPath;
|
|
|
|
}
|
|
|
|
|
2017-09-03 20:37:14 +00:00
|
|
|
const ATL::CStringW& CAvailableApps::GetCabPath() const
|
2017-07-18 22:52:51 +00:00
|
|
|
{
|
|
|
|
return m_szCabPath;
|
|
|
|
}
|
|
|
|
|
2017-09-03 20:37:14 +00:00
|
|
|
LPCWSTR CAvailableApps::GetFolderPathString() const
|
2017-07-18 22:52:51 +00:00
|
|
|
{
|
|
|
|
return m_szPath.GetString();
|
|
|
|
}
|
|
|
|
|
2017-09-03 20:37:14 +00:00
|
|
|
LPCWSTR CAvailableApps::GetAppPathString() const
|
2017-07-18 22:52:51 +00:00
|
|
|
{
|
|
|
|
return m_szPath.GetString();
|
|
|
|
}
|
|
|
|
|
2017-09-03 20:37:14 +00:00
|
|
|
LPCWSTR CAvailableApps::GetCabPathString() const
|
2017-07-18 22:52:51 +00:00
|
|
|
{
|
|
|
|
return m_szPath.GetString();
|
|
|
|
}
|
2017-07-19 10:39:03 +00:00
|
|
|
// CAvailableApps
|