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)
12 #define ADD_TEXT(a, b, c, d) \
15 LoadStringW(hInst, a, szText, _countof(szText)); \
16 InsertRichEditText(szText, c); \
17 InsertRichEditText(b, d); \
20 #define GET_STRING1(a, b) \
21 if (!ParserGetString(a, b, _countof(b), FindFileData.cFileName)) \
24 #define GET_STRING2(a, b) \
25 if (!ParserGetString(a, b, _countof(b), FindFileData.cFileName)) \
28 LIST_ENTRY CachedEntriesHead
= { &CachedEntriesHead
, &CachedEntriesHead
};
29 PLIST_ENTRY pCachedEntry
= &CachedEntriesHead
;
32 ShowAvailableAppInfo(INT Index
)
34 PAPPLICATION_INFO Info
= (PAPPLICATION_INFO
) ListViewGetlParam(Index
);
35 WCHAR szText
[MAX_STR_LEN
];
37 if (!Info
) return FALSE
;
39 NewRichEditText(Info
->szName
, CFE_BOLD
);
41 InsertRichEditText(L
"\n", 0);
43 ADD_TEXT(IDS_AINFO_VERSION
, Info
->szVersion
, CFE_BOLD
, 0);
44 ADD_TEXT(IDS_AINFO_LICENSE
, Info
->szLicense
, CFE_BOLD
, 0);
45 ADD_TEXT(IDS_AINFO_SIZE
, Info
->szSize
, CFE_BOLD
, 0);
46 ADD_TEXT(IDS_AINFO_URLSITE
, Info
->szUrlSite
, CFE_BOLD
, CFE_LINK
);
47 ADD_TEXT(IDS_AINFO_DESCRIPTION
, Info
->szDesc
, CFE_BOLD
, 0);
53 DeleteCurrentAppsDB(VOID
)
55 HANDLE hFind
= INVALID_HANDLE_VALUE
;
56 WIN32_FIND_DATAW FindFileData
;
57 WCHAR szCabPath
[MAX_PATH
];
58 WCHAR szSearchPath
[MAX_PATH
];
59 WCHAR szPath
[MAX_PATH
];
60 WCHAR szTmp
[MAX_PATH
];
64 if (!GetStorageDirectory(szPath
, _countof(szPath
)))
67 hr
= StringCbPrintfW(szCabPath
, sizeof(szCabPath
),
73 result
= result
&& DeleteFileW(szCabPath
);
75 hr
= StringCbCatW(szPath
, sizeof(szPath
), L
"\\rapps\\");
80 hr
= StringCbPrintfW(szSearchPath
, sizeof(szSearchPath
),
86 hFind
= FindFirstFileW(szSearchPath
, &FindFileData
);
88 if (hFind
== INVALID_HANDLE_VALUE
)
93 hr
= StringCbPrintfW(szTmp
, sizeof(szTmp
),
95 szPath
, FindFileData
.cFileName
);
98 result
= result
&& DeleteFileW(szTmp
);
100 } while (FindNextFileW(hFind
, &FindFileData
) != 0);
111 WCHAR szPath
[MAX_PATH
];
112 WCHAR szAppsPath
[MAX_PATH
];
113 WCHAR szCabPath
[MAX_PATH
];
115 if (!DeleteCurrentAppsDB())
118 DownloadApplicationsDB(APPLICATION_DATABASE_URL
);
120 if (!GetStorageDirectory(szPath
, _countof(szPath
)))
123 if (FAILED(StringCbPrintfW(szCabPath
, sizeof(szCabPath
),
130 if (FAILED(StringCbPrintfW(szAppsPath
, sizeof(szAppsPath
),
137 ExtractFilesFromCab(szCabPath
, szAppsPath
);
144 EnumAvailableApplications(INT EnumType
, AVAILENUMPROC lpEnumProc
)
146 HANDLE hFind
= INVALID_HANDLE_VALUE
;
147 WIN32_FIND_DATAW FindFileData
;
148 WCHAR szPath
[MAX_PATH
];
149 WCHAR szAppsPath
[MAX_PATH
];
150 WCHAR szCabPath
[MAX_PATH
];
151 PAPPLICATION_INFO Info
;
154 if (!GetStorageDirectory(szPath
, _countof(szPath
)))
157 hr
= StringCbPrintfW(szCabPath
, sizeof(szCabPath
),
163 hr
= StringCbCatW(szPath
, sizeof(szPath
), L
"\\rapps\\");
168 hr
= StringCbCopyW(szAppsPath
, sizeof(szAppsPath
), szPath
);
173 if (!CreateDirectory(szPath
, NULL
) &&
174 GetLastError() != ERROR_ALREADY_EXISTS
)
179 hr
= StringCbCatW(szPath
, sizeof(szPath
), L
"*.txt");
184 hFind
= FindFirstFileW(szPath
, &FindFileData
);
186 if (hFind
== INVALID_HANDLE_VALUE
)
188 if (GetFileAttributesW(szCabPath
) == INVALID_FILE_ATTRIBUTES
)
189 DownloadApplicationsDB(APPLICATION_DATABASE_URL
);
191 ExtractFilesFromCab(szCabPath
, szAppsPath
);
192 hFind
= FindFirstFileW(szPath
, &FindFileData
);
194 if (hFind
== INVALID_HANDLE_VALUE
)
200 /* loop for all the cached entries */
201 for (pCachedEntry
= CachedEntriesHead
.Flink
; pCachedEntry
!= &CachedEntriesHead
; pCachedEntry
= pCachedEntry
->Flink
)
203 Info
= CONTAINING_RECORD(pCachedEntry
, APPLICATION_INFO
, List
);
205 /* do we already have this entry in cache? */
206 if(_wcsicmp(FindFileData
.cFileName
, Info
->cFileName
) == 0)
208 /* is it current enough, or the file has been modified since our last time here? */
209 if (CompareFileTime(&FindFileData
.ftLastWriteTime
, &Info
->ftCacheStamp
) == 1)
211 /* recreate our cache, this is the slow path */
212 RemoveEntryList(&Info
->List
);
213 HeapFree(GetProcessHeap(), 0, Info
);
217 /* speedy path, compare directly, we already have the data */
225 /* create a new entry */
226 Info
= (PAPPLICATION_INFO
)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(APPLICATION_INFO
));
231 Info
->Category
= ParserGetInt(L
"Category", FindFileData
.cFileName
);
233 /* copy the cache-related fields for the next time */
234 RtlCopyMemory(&Info
->cFileName
, &FindFileData
.cFileName
, MAX_PATH
);
235 RtlCopyMemory(&Info
->ftCacheStamp
, &FindFileData
.ftLastWriteTime
, sizeof(FILETIME
));
237 /* add our cached entry to the cached list */
238 InsertTailList(&CachedEntriesHead
, &Info
->List
);
242 if (Info
->Category
== FALSE
)
245 if (EnumType
!= Info
->Category
&& EnumType
!= ENUM_ALL_AVAILABLE
)
248 /* if our cache hit was only partial, we need to parse
249 and lazily fill the rest of fields only when needed */
251 if (Info
->szUrlDownload
[0] == 0)
253 GET_STRING1(L
"Name", Info
->szName
);
254 GET_STRING1(L
"URLDownload", Info
->szUrlDownload
);
256 GET_STRING2(L
"RegName", Info
->szRegName
);
257 GET_STRING2(L
"Version", Info
->szVersion
);
258 GET_STRING2(L
"License", Info
->szLicense
);
259 GET_STRING2(L
"Description", Info
->szDesc
);
260 GET_STRING2(L
"Size", Info
->szSize
);
261 GET_STRING2(L
"URLSite", Info
->szUrlSite
);
262 GET_STRING2(L
"CDPath", Info
->szCDPath
);
263 GET_STRING2(L
"SHA1", Info
->szSHA1
);
266 if (!lpEnumProc(Info
))
269 } while (FindNextFileW(hFind
, &FindFileData
) != 0);
276 VOID
FreeCachedAvailableEntries(VOID
)
278 PAPPLICATION_INFO Info
;
280 /* loop and deallocate all the cached app infos in the list */
281 for (pCachedEntry
= CachedEntriesHead
.Flink
; pCachedEntry
!= &CachedEntriesHead
;)
283 Info
= CONTAINING_RECORD(pCachedEntry
, APPLICATION_INFO
, List
);
285 /* grab a reference to the next linked entry before getting rid of the current one */
286 pCachedEntry
= pCachedEntry
->Flink
;
288 /* flush them down the toilet :D */
289 RemoveEntryList(&Info
->List
);
290 HeapFree(GetProcessHeap(), 0, Info
);