ReactOS  0.4.15-dev-449-g64abd9f
available.cpp
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Applications Manager
3  * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4  * FILE: base/applications/rapps/available.cpp
5  * PURPOSE: Classes for working with available applications
6  * COPYRIGHT: Copyright 2009 Dmitry Chapyshev (dmitry@reactos.org)
7  * Copyright 2015 Ismael Ferreras Morezuelas (swyterzone+ros@gmail.com)
8  * Copyright 2017 Alexander Shaposhnikov (sanchaez@reactos.org)
9  */
10 #include "rapps.h"
11 
12 #include "available.h"
13 #include "misc.h"
14 #include "dialogs.h"
15 
16 #include <atlcoll.h>
17 #include <atlsimpcoll.h>
18 #include <atlstr.h>
19 
20  // CAvailableApplicationInfo
22  : m_IsSelected(FALSE), m_LicenseType(LICENSE_NONE), m_SizeBytes(0), m_sFileName(sFileNameParam),
23  m_IsInstalled(FALSE), m_HasLanguageInfo(FALSE), m_HasInstalledVersion(FALSE)
24 {
26 }
27 
29 {
31  {
33  }
34 }
35 
36 // Lazily load general info from the file
38 {
40 
41  m_Parser->GetInt(L"Category", m_Category);
42 
43  if (!GetString(L"Name", m_szName)
44  || !GetString(L"URLDownload", m_szUrlDownload))
45  {
46  delete m_Parser;
47  return;
48  }
49 
50  GetString(L"RegName", m_szRegName);
51  GetString(L"Version", m_szVersion);
52  GetString(L"License", m_szLicense);
53  GetString(L"Description", m_szDesc);
54  GetString(L"URLSite", m_szUrlSite);
55  GetString(L"CDPath", m_szCDPath);
56  GetString(L"Language", m_szRegName);
57  GetString(L"SHA1", m_szSHA1);
58 
59  RetrieveSize();
63 
64  if (m_IsInstalled)
65  {
67  }
68 
69  delete m_Parser;
70 }
71 
73 {
76 }
77 
79 {
80  ATL::CStringW szNameVersion;
81  szNameVersion = m_szName + L" " + m_szVersion;
84  || ::GetInstalledVersion(&m_szInstalledVersion, szNameVersion);
85 }
86 
88 {
89  const WCHAR cDelimiter = L'|';
90  ATL::CStringW szBuffer;
91 
92  // TODO: Get multiline parameter
93  if (!m_Parser->GetString(L"Languages", szBuffer))
94  {
96  return;
97  }
98 
99  // Parse parameter string
100  ATL::CStringW m_szLocale;
101  INT iLCID;
102  for (INT i = 0; szBuffer[i] != UNICODE_NULL; ++i)
103  {
104  if (szBuffer[i] != cDelimiter && szBuffer[i] != L'\n')
105  {
106  m_szLocale += szBuffer[i];
107  }
108  else
109  {
110  if (StrToIntExW(m_szLocale.GetString(), STIF_DEFAULT, &iLCID))
111  {
112  m_LanguageLCIDs.Add(static_cast<LCID>(iLCID));
113  m_szLocale.Empty();
114  }
115  }
116  }
117 
118  // For the text after delimiter
119  if (!m_szLocale.IsEmpty())
120  {
121  if (StrToIntExW(m_szLocale.GetString(), STIF_DEFAULT, &iLCID))
122  {
123  m_LanguageLCIDs.Add(static_cast<LCID>(iLCID));
124  }
125  }
126 
128 }
129 
131 {
132  INT IntBuffer;
133 
134  m_Parser->GetInt(L"LicenseType", IntBuffer);
135 
136  if (IsLicenseType(IntBuffer))
137  {
138  m_LicenseType = static_cast<LicenseType>(IntBuffer);
139  }
140  else
141  {
143  }
144 }
145 
147 {
148  INT iSizeBytes;
149 
150  if (!m_Parser->GetInt(L"SizeBytes", iSizeBytes))
151  {
152  // fall back to "Size" string
153  GetString(L"Size", m_szSize);
154  return;
155  }
156 
157  m_SizeBytes = iSizeBytes;
160 }
161 
163 {
164  if (!m_HasLanguageInfo)
165  {
166  return FALSE;
167  }
168 
169  //Find locale code in the list
170  const INT nLanguagesSize = m_LanguageLCIDs.GetSize();
171  for (INT i = 0; i < nLanguagesSize; ++i)
172  {
173  if (m_LanguageLCIDs[i] == what)
174  {
175  return TRUE;
176  }
177  }
178 
179  return FALSE;
180 }
181 
183 {
184  return m_HasLanguageInfo;
185 }
186 
188 {
190 }
191 
193 {
195 }
196 
198 {
199  return m_IsInstalled;
200 }
201 
203 {
204  return m_HasInstalledVersion;
205 }
206 
208 {
210 }
211 
213 {
214  RtlCopyMemory(&m_ftCacheStamp, ftTime, sizeof(FILETIME));
215 }
216 
218 {
219  if (!m_Parser->GetString(lpKeyName, ReturnedString))
220  {
221  ReturnedString.Empty();
222  return FALSE;
223  }
224  return TRUE;
225 }
226 // CAvailableApplicationInfo
227 
228 // AvailableStrings
230 {
231  //FIXME: maybe provide a fallback?
233  {
234  szAppsPath = szPath + L"\\rapps\\";
235  szCabName = L"rappmgr.cab";
236  szCabDir = szPath;
237  szCabPath = (szCabDir + L"\\") + szCabName;
238  szSearchPath = szAppsPath + L"*.txt";
239  }
240 }
241 // AvailableStrings
242 
243 // CAvailableApps
245 
247 {
248 }
249 
251 {
252  POSITION InfoListPosition = m_InfoList.GetHeadPosition();
253 
254  /* loop and deallocate all the cached app infos in the list */
255  while (InfoListPosition)
256  {
257  CAvailableApplicationInfo* Info = m_InfoList.GetNext(InfoListPosition);
258  delete Info;
259  }
260 
262 }
263 
265 {
267  WIN32_FIND_DATAW FindFileData;
268 
269  hFind = FindFirstFileW(m_Strings.szSearchPath.GetString(), &FindFileData);
270 
271  if (hFind != INVALID_HANDLE_VALUE)
272  {
274  do
275  {
276  szTmp = m_Strings.szAppsPath + FindFileData.cFileName;
277  DeleteFileW(szTmp.GetString());
278  } while (FindNextFileW(hFind, &FindFileData) != 0);
279  FindClose(hFind);
280  }
281 
284 }
285 
287 {
289  WIN32_FIND_DATAW FindFileData;
290 
292  {
293  return FALSE;
294  }
295 
296  //if there are some files in the db folder - we're good
297  hFind = FindFirstFileW(m_Strings.szSearchPath, &FindFileData);
298  if (hFind != INVALID_HANDLE_VALUE)
299  {
300  FindClose(hFind);
301  return TRUE;
302  }
303 
306 
310  {
311  return FALSE;
312  }
313 
315 
316  return TRUE;
317 }
318 
320 {
322  return UpdateAppsDB();
323 }
324 
326 {
327 
329  WIN32_FIND_DATAW FindFileData;
330 
331  hFind = FindFirstFileW(m_Strings.szSearchPath.GetString(), &FindFileData);
332 
333  if (hFind == INVALID_HANDLE_VALUE)
334  {
335  //no db yet
336  return FALSE;
337  }
338 
339  do
340  {
341  // loop for all the cached entries
342  POSITION CurrentListPosition = m_InfoList.GetHeadPosition();
344 
345  while (CurrentListPosition != NULL)
346  {
347  POSITION LastListPosition = CurrentListPosition;
348  Info = m_InfoList.GetNext(CurrentListPosition);
349 
350  // do we already have this entry in cache?
351  if (Info->m_sFileName == FindFileData.cFileName)
352  {
353  // is it current enough, or the file has been modified since our last time here?
354  if (CompareFileTime(&FindFileData.ftLastWriteTime, &Info->m_ftCacheStamp) == 1)
355  {
356  // recreate our cache, this is the slow path
357  m_InfoList.RemoveAt(LastListPosition);
358 
359  delete Info;
360  Info = NULL;
361  break;
362  }
363  else
364  {
365  // speedy path, compare directly, we already have the data
366  goto skip_if_cached;
367  }
368  }
369  }
370 
371  // create a new entry
372  Info = new CAvailableApplicationInfo(FindFileData.cFileName);
373 
374  // set a timestamp for the next time
375  Info->SetLastWriteTime(&FindFileData.ftLastWriteTime);
377 
378 skip_if_cached:
379  if (EnumType == Info->m_Category
380  || EnumType == ENUM_ALL_AVAILABLE
381  || (EnumType == ENUM_CAT_SELECTED && Info->m_IsSelected))
382  {
383  Info->RefreshAppInfo();
384 
385  if (lpEnumProc)
386  lpEnumProc(Info, m_Strings.szAppsPath.GetString(), param);
387  }
388  } while (FindNextFileW(hFind, &FindFileData) != 0);
389 
390  FindClose(hFind);
391  return TRUE;
392 }
393 
395 {
396  if (m_InfoList.IsEmpty())
397  {
398  return NULL;
399  }
400 
401  // linear search
402  POSITION CurrentListPosition = m_InfoList.GetHeadPosition();
404  while (CurrentListPosition != NULL)
405  {
406  info = m_InfoList.GetNext(CurrentListPosition);
407  if (info->m_szName.CompareNoCase(szAppName) == 0)
408  {
409  return info;
410  }
411  }
412  return NULL;
413 }
414 
416 {
418  for (INT i = 0; i < arrAppsNames.GetSize(); ++i)
419  {
420  CAvailableApplicationInfo* Info = FindInfo(arrAppsNames[i]);
421  if (Info)
422  {
423  result.Add(*Info);
424  }
425  }
426  return result;
427 }
428 
430 {
432  POSITION CurrentListPosition = m_InfoList.GetHeadPosition();
434 
435  while (CurrentListPosition != NULL)
436  {
437  Info = m_InfoList.GetNext(CurrentListPosition);
438  if (Info->m_IsSelected)
439  {
440  result.Add(*Info);
441  }
442  }
443  return result;
444 }
445 
447 {
448  return m_Strings.szPath;
449 }
450 
452 {
453  return m_Strings.szAppsPath;
454 }
455 
457 {
458  return m_Strings.szCabPath;
459 }
460 // CAvailableApps
BOOL WINAPI CreateDirectoryW(IN LPCWSTR lpPathName, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: dir.c:90
ATL::CStringW m_szRegName
Definition: available.h:31
BOOL WINAPI FindNextFileW(IN HANDLE hFindFile, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:382
LPWSTR WINAPI StrFormatByteSizeW(LONGLONG llBytes, LPWSTR lpszDest, UINT cchMax)
Definition: string.c:2376
POSITION GetHeadPosition() const
Definition: atlcoll.h:549
BOOL(CALLBACK * AVAILENUMPROC)(CAvailableApplicationInfo *Info, LPCWSTR szFolderPath, PVOID param)
Definition: available.h:83
#define MAKELCID(lgid, srtid)
const ATL::CStringW & GetAppPath() const
Definition: available.cpp:451
BOOL ExtractFilesFromCab(const ATL::CStringW &szCabName, const ATL::CStringW &szCabDir, const ATL::CStringW &szOutputDir)
Definition: cabinet.cpp:257
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define APPLICATION_DATABASE_URL
Definition: defines.h:33
BOOL Add(const T &t)
Definition: atlsimpcoll.h:58
#define STIF_DEFAULT
Definition: shlwapi.h:1451
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
BOOL GetInstalledVersion(ATL::CStringW *pszVersion, const ATL::CStringW &szRegName)
Definition: misc.cpp:301
BOOL HasNativeLanguage() const
Definition: available.cpp:187
ATL::CStringW m_szName
Definition: available.h:30
#define SUBLANG_DEFAULT
Definition: nls.h:168
VOID DownloadApplicationsDB(LPCWSTR lpUrl, BOOL IsOfficial)
Definition: loaddlg.cpp:978
#define INVALID_HANDLE_VALUE
Definition: compat.h:400
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
ATL::CStringW m_szVersion
Definition: available.h:32
DWORD LCID
Definition: nls.h:13
LCID WINAPI GetUserDefaultLCID(void)
Definition: lang.c:768
BOOL GetInt(const ATL::CStringW &KeyName, INT &iResult)
Definition: misc.cpp:383
LicenseType m_LicenseType
Definition: available.h:29
BOOL IsLicenseType(INT x)
Definition: available.h:20
char szTmp[518]
static BOOL UpdateAppsDB()
Definition: available.cpp:286
int GetSize() const
Definition: atlsimpcoll.h:104
int32_t INT
Definition: typedefs.h:57
struct TraceInfo Info
WCHAR szSourceURL[INTERNET_MAX_URL_LENGTH]
Definition: winmain.h:25
struct _test_info info[]
Definition: SetCursorPos.c:19
ATL::CSimpleArray< CAvailableApplicationInfo > GetSelected() const
Definition: available.cpp:429
CAvailableApplicationInfo * FindInfo(const ATL::CStringW &szAppName) const
Definition: available.cpp:394
ATL::CStringW m_szLicense
Definition: available.h:33
BOOL bUseSource
Definition: winmain.h:24
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
ATL::CStringW szCabPath
Definition: available.h:88
void ReleaseBuffer(_In_ int nNewLength=-1)
Definition: atlsimpstr.h:372
#define UNICODE_NULL
unsigned int BOOL
Definition: ntddk_ex.h:94
ATL::CSimpleArray< CAvailableApplicationInfo > FindInfoList(const ATL::CSimpleArray< ATL::CStringW > &arrAppsNames) const
Definition: available.cpp:415
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
ATL::CStringW m_szDesc
Definition: available.h:34
VOID FreeCachedEntries()
Definition: available.cpp:250
smooth NULL
Definition: ftsmooth.c:416
SETTINGS_INFO SettingsInfo
Definition: winmain.cpp:18
BOOL WINAPI RemoveDirectoryW(IN LPCWSTR lpPathName)
Definition: dir.c:732
const ATL::CStringW & GetFolderPath() const
Definition: available.cpp:446
E & GetNext(_Inout_ POSITION &pos)
Definition: atlcoll.h:561
LONG WINAPI CompareFileTime(IN CONST FILETIME *lpFileTime1, IN CONST FILETIME *lpFileTime2)
Definition: time.c:106
BOOL Enum(INT EnumType, AVAILENUMPROC lpEnumProc, PVOID param)
Definition: available.cpp:325
static AvailableStrings m_Strings
Definition: available.h:99
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define SORT_DEFAULT
GLfloat param
Definition: glext.h:5796
#define MAX_PATH
Definition: compat.h:26
PCXSTR GetString() const
Definition: atlsimpstr.h:361
static VOID DeleteCurrentAppsDB()
Definition: available.cpp:264
BOOL GetStorageDirectory(ATL::CStringW &lpDirectory)
Definition: misc.cpp:172
void RemoveAll()
Definition: atlcoll.h:725
BOOL WINAPI StrToIntExW(LPCWSTR lpszStr, DWORD dwFlags, LPINT lpiRet)
Definition: string.c:970
#define LANG_ENGLISH
Definition: nls.h:52
static const WCHAR L[]
Definition: oid.c:1250
ATL::CStringW m_sFileName
Definition: available.h:43
ATL::CStringW m_szUrlDownload
Definition: available.h:37
ATL::CStringW m_szSHA1
Definition: available.h:47
static BOOL ForceUpdateAppsDB()
Definition: available.cpp:319
ATL::CStringW szCabDir
Definition: available.h:92
TCHAR szAppName[128]
Definition: solitaire.cpp:16
ATL::CAtlList< CAvailableApplicationInfo * > m_InfoList
Definition: available.h:100
bool IsEmpty() const
Definition: atlsimpstr.h:379
POSITION AddTail(INARGTYPE element)
Definition: atlcoll.h:624
VOID SetLastWriteTime(FILETIME *ftTime)
Definition: available.cpp:212
ATL::CStringW szPath
Definition: available.h:87
BOOL GetString(const ATL::CStringW &KeyName, ATL::CStringW &ResultString)
Definition: misc.cpp:345
BOOL HasLanguageInfo() const
Definition: available.cpp:182
BOOL HasInstalledVersion() const
Definition: available.cpp:202
ATL::CStringW m_szUrlSite
Definition: available.h:36
ATL::CStringW szAppsPath
Definition: available.h:89
ATL::CStringW m_szCDPath
Definition: available.h:38
CAvailableApplicationInfo(const ATL::CStringW &sFileNameParam)
Definition: available.cpp:21
BOOL FindInLanguages(LCID what) const
Definition: available.cpp:162
BOOL HasEnglishLanguage() const
Definition: available.cpp:192
ATL::CSimpleArray< LCID > m_LanguageLCIDs
Definition: available.h:39
#define MAKELANGID(p, s)
Definition: nls.h:15
void RemoveAt(_In_ POSITION pos)
Definition: atlcoll.h:746
const ATL::CStringW & GetCabPath() const
Definition: available.cpp:456
#define ERROR_ALREADY_EXISTS
Definition: disk.h:80
int Compare(_In_z_ PCXSTR psz) const
Definition: cstringt.h:625
ATL::CStringW m_szSize
Definition: available.h:35
BOOL GetString(LPCWSTR lpKeyName, ATL::CStringW &ReturnedString)
Definition: available.cpp:217
CConfigParser * m_Parser
Definition: available.h:69
GLuint64EXT * result
Definition: glext.h:11304
ATL::CStringW szSearchPath
Definition: available.h:90
ATL::CStringW szCabName
Definition: available.h:91
ATL::CStringW m_szInstalledVersion
Definition: available.h:48
bool IsEmpty() const
Definition: atlcoll.h:543
HANDLE WINAPI FindFirstFileW(IN LPCWSTR lpFileName, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:320
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502