2 * PROJECT: ReactOS Applications Manager
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/rapps/available.cpp
5 * PURPOSE: Functions for working with available applications
6 * PROGRAMMERS: Dmitry Chapyshev (dmitry@reactos.org)
7 * Ismael Ferreras Morezuelas (swyterzone+ros@gmail.com)
8 * Alexander Shaposhnikov (chaez.san@gmail.com)
13 ATL::CAtlList
<PAPPLICATION_INFO
> InfoList
;
16 InsertTextAfterLoaded_RichEdit(UINT uStringID
, const ATL::CStringW
& szText
, DWORD StringFlags
, DWORD TextFlags
)
18 ATL::CStringW szLoadedText
;
19 if (!szText
.IsEmpty() && szLoadedText
.LoadStringW(hInst
, uStringID
))
21 InsertRichEditText(szLoadedText
, StringFlags
);
22 InsertRichEditText(szText
, TextFlags
);
27 InsertLoadedTextNewl_RichEdit(UINT uStringID
, DWORD StringFlags
)
29 ATL::CStringW szLoadedText
;
30 if (szLoadedText
.LoadStringW(hInst
, uStringID
))
32 InsertRichEditText(L
"\n", 0);
33 InsertRichEditText(szLoadedText
, StringFlags
);
34 InsertRichEditText(L
"\n", 0);
39 GetString(LPCWSTR lpKeyName
, ATL::CStringW
& ReturnedString
, const ATL::CStringW
& cFileName
)
41 if (!ParserGetString(lpKeyName
, cFileName
, ReturnedString
))
43 ReturnedString
.Empty();
49 //Check both registry keys in 64bit system
50 //TODO: check system type beforehand to avoid double checks?
52 GetInstalledVersionEx(PAPPLICATION_INFO Info
, ATL::CStringW
* szVersion
, REGSAM key
)
54 return (!Info
->szRegName
.IsEmpty()
55 && (GetInstalledVersion_WowUser(szVersion
, Info
->szRegName
, TRUE
, key
)
56 || GetInstalledVersion_WowUser(szVersion
, Info
->szRegName
, FALSE
, key
)))
57 || (!Info
->szName
.IsEmpty()
58 && (GetInstalledVersion_WowUser(szVersion
, Info
->szName
, TRUE
, key
)
59 || GetInstalledVersion_WowUser(szVersion
, Info
->szName
, FALSE
, key
)));
63 GetInstalledVersion(PAPPLICATION_INFO Info
, ATL::CStringW
* szVersion
)
65 return GetInstalledVersionEx(Info
, szVersion
, KEY_WOW64_32KEY
)
66 || GetInstalledVersionEx(Info
, szVersion
, KEY_WOW64_64KEY
);
70 IsAppInstalled(PAPPLICATION_INFO Info
)
72 return GetInstalledVersion(Info
, NULL
);
75 ATL::CSimpleArray
<ATL::CStringW
>
76 ParserGetAppLanguages(const ATL::CStringW
& szFileName
)
78 const WCHAR cDelimiter
= L
'|';
79 ATL::CStringW szBuffer
;
81 if (!ParserGetString(L
"Languages", szFileName
, szBuffer
))
82 return CSimpleArray
<ATL::CStringW
>();
84 ATL::CStringW szLocale
;
85 ATL::CSimpleArray
<ATL::CStringW
> arrLocalesResult
;
86 for (INT i
= 0; szBuffer
[i
] != UNICODE_NULL
; ++i
)
88 if (szBuffer
[i
] != cDelimiter
)
90 szLocale
+= szBuffer
[i
];
92 arrLocalesResult
.Add(szLocale
);
96 // For the text after delimiter
97 if (!szLocale
.IsEmpty())
99 arrLocalesResult
.Add(szLocale
);
101 return arrLocalesResult
;
105 HasNativeLanguage(PAPPLICATION_INFO Info
)
111 //TODO: make the actual check
116 ParserGetLicenseType(const ATL::CStringW
& szFileName
)
118 INT IntBuffer
= ParserGetInt(L
"LicenseType", szFileName
);
119 if (IntBuffer
< 0 || IntBuffer
> LICENSE_TYPE::Max
)
121 return LICENSE_TYPE::None
;
123 return (LICENSE_TYPE
) IntBuffer
;
126 LIST_ENTRY CachedEntriesHead
= {&CachedEntriesHead
, &CachedEntriesHead
};
127 PLIST_ENTRY pCachedEntry
= &CachedEntriesHead
;
130 InsertVersionInfo_RichEdit(PAPPLICATION_INFO Info
)
132 ATL::CStringW szVersion
;
133 BOOL bIsInstalled
= IsAppInstalled(Info
),
134 bHasVersion
= GetInstalledVersion(Info
, &szVersion
);
140 if (Info
->szVersion
.Compare(szVersion
) > 0)
141 InsertLoadedTextNewl_RichEdit(IDS_STATUS_UPDATE_AVAILABLE
, CFE_ITALIC
);
143 InsertLoadedTextNewl_RichEdit(IDS_STATUS_INSTALLED
, CFE_ITALIC
);
145 InsertTextAfterLoaded_RichEdit(IDS_AINFO_VERSION
, szVersion
, CFE_BOLD
, 0);
148 InsertLoadedTextNewl_RichEdit(IDS_STATUS_INSTALLED
, CFE_ITALIC
);
152 InsertLoadedTextNewl_RichEdit(IDS_STATUS_NOTINSTALLED
, CFE_ITALIC
);
154 InsertTextAfterLoaded_RichEdit(IDS_AINFO_AVAILABLEVERSION
, Info
->szVersion
, CFE_BOLD
, 0);
158 InsertLicenseInfo_RichEdit(PAPPLICATION_INFO Info
)
160 ATL::CStringW szLicense
;
161 switch (Info
->LicenseType
)
163 case LICENSE_TYPE::OpenSource
:
164 szLicense
.LoadStringW(hInst
, IDS_LICENSE_OPENSOURCE
);
166 case LICENSE_TYPE::Freeware
:
167 szLicense
.LoadStringW(hInst
, IDS_LICENSE_FREEWARE
);
169 case LICENSE_TYPE::Trial
:
170 szLicense
.LoadStringW(hInst
, IDS_LICENSE_TRIAL
);
176 if (szLicense
.IsEmpty())
178 InsertTextAfterLoaded_RichEdit(IDS_AINFO_LICENSE
, Info
->szLicense
, CFE_BOLD
, 0);
182 szLicense
.Format(L
"(%ls)", Info
->szLicense
);
183 InsertTextAfterLoaded_RichEdit(IDS_AINFO_LICENSE
, szLicense
, CFE_BOLD
, 0);
189 ShowAvailableAppInfo(INT Index
)
191 PAPPLICATION_INFO Info
= (PAPPLICATION_INFO
) ListViewGetlParam(Index
);
192 if (!Info
) return FALSE
;
194 NewRichEditText(Info
->szName
, CFE_BOLD
);
195 InsertVersionInfo_RichEdit(Info
);
196 InsertLicenseInfo_RichEdit(Info
);
198 InsertTextAfterLoaded_RichEdit(IDS_AINFO_SIZE
, Info
->szSize
, CFE_BOLD
, 0);
199 InsertTextAfterLoaded_RichEdit(IDS_AINFO_URLSITE
, Info
->szUrlSite
, CFE_BOLD
, CFE_LINK
);
200 InsertTextAfterLoaded_RichEdit(IDS_AINFO_DESCRIPTION
, Info
->szDesc
, CFE_BOLD
, 0);
201 InsertTextAfterLoaded_RichEdit(IDS_AINFO_URLDOWNLOAD
, Info
->szUrlDownload
, CFE_BOLD
, CFE_LINK
);
207 DeleteCurrentAppsDB(VOID
)
209 HANDLE hFind
= INVALID_HANDLE_VALUE
;
210 WIN32_FIND_DATAW FindFileData
;
211 ATL::CStringW szCabPath
;
212 ATL::CStringW szSearchPath
;
213 ATL::CStringW szPath
;
216 if (!GetStorageDirectory(szPath
))
219 szCabPath
= szPath
+ L
"\\rappmgr.cab";
220 result
= result
&& DeleteFileW(szCabPath
.GetString());
222 szPath
+= L
"\\rapps\\";
223 szSearchPath
= szPath
+ L
"*.txt";
225 hFind
= FindFirstFileW(szSearchPath
.GetString(), &FindFileData
);
227 if (hFind
== INVALID_HANDLE_VALUE
)
233 szTmp
= szPath
+ FindFileData
.cFileName
;
234 result
= result
&& DeleteFileW(szTmp
.GetString());
235 } while (FindNextFileW(hFind
, &FindFileData
) != 0);
245 ATL::CStringW szPath
;
246 ATL::CStringW szAppsPath
;
247 ATL::CStringW szCabPath
;
249 if (!DeleteCurrentAppsDB())
252 DownloadApplicationsDB(APPLICATION_DATABASE_URL
);
254 if (!GetStorageDirectory(szPath
))
257 szCabPath
= szPath
+ L
"\\rappmgr.cab";
258 szAppsPath
= szPath
+ L
"\\rapps\\";
260 if (!ExtractFilesFromCab(szCabPath
, szAppsPath
))
270 EnumAvailableApplications(INT EnumType
, AVAILENUMPROC lpEnumProc
)
272 HANDLE hFind
= INVALID_HANDLE_VALUE
;
273 WIN32_FIND_DATAW FindFileData
;
274 ATL::CStringW szPath
;
275 ATL::CStringW szAppsPath
;
276 ATL::CStringW szCabPath
;
277 PAPPLICATION_INFO Info
;
279 if (!GetStorageDirectory(szPath
))
282 szCabPath
= szPath
+ L
"\\rappmgr.cab";
283 szPath
+= L
"\\rapps\\";
286 if (!CreateDirectoryW(szPath
.GetString(), NULL
) &&
287 GetLastError() != ERROR_ALREADY_EXISTS
)
293 hFind
= FindFirstFileW(szPath
.GetString(), &FindFileData
);
295 if (hFind
== INVALID_HANDLE_VALUE
)
297 if (GetFileAttributesW(szCabPath
) == INVALID_FILE_ATTRIBUTES
)
298 DownloadApplicationsDB(APPLICATION_DATABASE_URL
);
300 ExtractFilesFromCab(szCabPath
, szAppsPath
);
301 hFind
= FindFirstFileW(szPath
, &FindFileData
);
303 if (hFind
== INVALID_HANDLE_VALUE
)
309 /* loop for all the cached entries */
310 POSITION CurrentListPosition
= InfoList
.GetHeadPosition();
312 while (CurrentListPosition
!= NULL
)
314 POSITION LastListPosition
= CurrentListPosition
;
315 Info
= InfoList
.GetNext(CurrentListPosition
);
317 /* do we already have this entry in cache? */
318 if (!Info
->cFileName
.Compare(FindFileData
.cFileName
))
320 /* is it current enough, or the file has been modified since our last time here? */
321 if (CompareFileTime(&FindFileData
.ftLastWriteTime
, &Info
->ftCacheStamp
) == 1)
323 /* recreate our cache, this is the slow path */
324 InfoList
.RemoveAt(LastListPosition
);
330 /* speedy path, compare directly, we already have the data */
336 /* create a new entry */
337 Info
= new APPLICATION_INFO();
342 Info
->Category
= ParserGetInt(L
"Category", FindFileData
.cFileName
);
343 Info
->LicenseType
= ParserGetLicenseType(FindFileData
.cFileName
);
344 Info
->Languages
= ParserGetAppLanguages(FindFileData
.cFileName
);
346 /* copy the cache-related fields for the next time */
347 Info
->cFileName
= FindFileData
.cFileName
;
348 RtlCopyMemory(&Info
->ftCacheStamp
, &FindFileData
.ftLastWriteTime
, sizeof(FILETIME
));
350 /* add our cached entry to the cached list */
351 InfoList
.AddTail(Info
);
354 if (Info
->Category
== FALSE
)
357 if (EnumType
!= Info
->Category
&& EnumType
!= ENUM_ALL_AVAILABLE
)
360 /* if our cache hit was only partial, we need to parse
361 and lazily fill the rest of fields only when needed */
363 if (Info
->szUrlDownload
.IsEmpty())
365 if (!GetString(L
"Name", Info
->szName
, FindFileData
.cFileName
)
366 || !GetString(L
"URLDownload", Info
->szUrlDownload
, FindFileData
.cFileName
))
371 GetString(L
"RegName", Info
->szRegName
, FindFileData
.cFileName
);
372 GetString(L
"Version", Info
->szVersion
, FindFileData
.cFileName
);
373 GetString(L
"License", Info
->szLicense
, FindFileData
.cFileName
);
374 GetString(L
"Description", Info
->szDesc
, FindFileData
.cFileName
);
375 GetString(L
"Size", Info
->szSize
, FindFileData
.cFileName
);
376 GetString(L
"URLSite", Info
->szUrlSite
, FindFileData
.cFileName
);
377 GetString(L
"CDPath", Info
->szCDPath
, FindFileData
.cFileName
);
378 GetString(L
"Language", Info
->szRegName
, FindFileData
.cFileName
);
379 GetString(L
"SHA1", Info
->szSHA1
, FindFileData
.cFileName
);
382 if (!lpEnumProc(Info
))
385 } while (FindNextFileW(hFind
, &FindFileData
) != 0);
392 VOID
FreeCachedAvailableEntries(VOID
)
394 PAPPLICATION_INFO Info
;
395 POSITION InfoListPosition
= InfoList
.GetHeadPosition();
397 /* loop and deallocate all the cached app infos in the list */
398 while (InfoListPosition
)
400 Info
= InfoList
.GetAt(InfoListPosition
);
401 InfoList
.RemoveHead();
402 InfoListPosition
= InfoList
.GetHeadPosition();