[FORMATTING][RAPPS] available.cpp: Fix braces

svn path=/branches/GSoC_2017/rapps/; revision=75220
This commit is contained in:
Alexander Shaposhnikov 2017-06-27 23:33:15 +00:00
parent 17e36ed120
commit de725c5391

View file

@ -9,17 +9,19 @@
#include "rapps.h" #include "rapps.h"
inline void _AddText(UINT a, LPCWSTR b, DWORD c, DWORD d) { inline void _AddText(UINT a, LPCWSTR b, DWORD c, DWORD d)
if (b[0] != '\0') {
{ if (b[0] != '\0')
WCHAR szText[MAX_STR_LEN]; {
LoadStringW(hInst, a, szText, _countof(szText)); WCHAR szText[MAX_STR_LEN];
InsertRichEditText(szText, c); LoadStringW(hInst, a, szText, _countof(szText));
InsertRichEditText(b, d); InsertRichEditText(szText, c);
} InsertRichEditText(b, d);
}
} }
inline void _AddTextNewl(UINT a, DWORD b) { inline void _AddTextNewl(UINT a, DWORD b)
{
WCHAR szText[MAX_STR_LEN]; WCHAR szText[MAX_STR_LEN];
LoadStringW(hInst, a, szText, _countof(szText)); LoadStringW(hInst, a, szText, _countof(szText));
InsertRichEditText(L"\n", 0); InsertRichEditText(L"\n", 0);
@ -28,15 +30,18 @@ inline void _AddTextNewl(UINT a, DWORD b) {
} }
template<typename T, size_t N, size_t N2> template<typename T, size_t N, size_t N2>
inline BOOL _GetString(LPCWSTR a, T(&b)[N], T (&cFileName)[N2]) { inline BOOL _GetString(LPCWSTR a, T(&b)[N], T(&cFileName)[N2])
return ParserGetString(a, b, N, cFileName); {
return ParserGetString(a, b, N, cFileName);
} }
template<typename T, size_t N, size_t N2> template<typename T, size_t N, size_t N2>
inline void _GetStringNullFailure(LPCWSTR a, T(&b)[N], T (&cFileName)[N2]) { inline void _GetStringNullFailure(LPCWSTR a, T(&b)[N], T(&cFileName)[N2])
if (!_GetString(a, b, cFileName)) { {
b[0] = '\0'; if (!_GetString(a, b, cFileName))
} {
b[0] = '\0';
}
} }
//App is "installed" if the RegName or Name is in the registry //App is "installed" if the RegName or Name is in the registry
@ -52,9 +57,10 @@ inline BOOL _AppInstallCheckWithKey(PAPPLICATION_INFO Info, REGSAM key)
//Check both registry keys in 64bit system //Check both registry keys in 64bit system
//TODO: check system type beforehand to avoid double checks? //TODO: check system type beforehand to avoid double checks?
inline BOOL _AppInstallCheck(PAPPLICATION_INFO Info) { inline BOOL _AppInstallCheck(PAPPLICATION_INFO Info)
return _AppInstallCheckWithKey(Info, KEY_WOW64_32KEY) {
|| _AppInstallCheckWithKey(Info, KEY_WOW64_64KEY); return _AppInstallCheckWithKey(Info, KEY_WOW64_32KEY)
|| _AppInstallCheckWithKey(Info, KEY_WOW64_64KEY);
} }
//App is "installed" if the RegName or Name is in the registry //App is "installed" if the RegName or Name is in the registry
@ -74,7 +80,7 @@ inline BOOL _GetInstalledVersion(PAPPLICATION_INFO Info, LPWSTR szVersion, UINT
|| _GetInstalledVersionWithKey(Info, szVersion, iVersionSize, KEY_WOW64_64KEY); || _GetInstalledVersionWithKey(Info, szVersion, iVersionSize, KEY_WOW64_64KEY);
} }
LIST_ENTRY CachedEntriesHead = { &CachedEntriesHead, &CachedEntriesHead }; LIST_ENTRY CachedEntriesHead = {&CachedEntriesHead, &CachedEntriesHead};
PLIST_ENTRY pCachedEntry = &CachedEntriesHead; PLIST_ENTRY pCachedEntry = &CachedEntriesHead;
BOOL BOOL
@ -89,14 +95,15 @@ ShowAvailableAppInfo(INT Index)
NewRichEditText(Info->szName, CFE_BOLD); NewRichEditText(Info->szName, CFE_BOLD);
if (bIsInstalled) if (bIsInstalled)
{ {
_AddTextNewl(IDS_STATUS_INSTALLED, CFE_ITALIC); _AddTextNewl(IDS_STATUS_INSTALLED, CFE_ITALIC);
if (_GetInstalledVersion(Info, szVersion, _countof(szVersion))) if (_GetInstalledVersion(Info, szVersion, _countof(szVersion)))
{ {
_AddText(IDS_AINFO_VERSION, szVersion, CFE_BOLD, 0); _AddText(IDS_AINFO_VERSION, szVersion, CFE_BOLD, 0);
} }
} else }
else
{ {
_AddTextNewl(IDS_STATUS_NOTINSTALLED, CFE_ITALIC); _AddTextNewl(IDS_STATUS_NOTINSTALLED, CFE_ITALIC);
} }
_AddText(IDS_AINFO_AVAILABLEVERSION, Info->szVersion, CFE_BOLD, 0); _AddText(IDS_AINFO_AVAILABLEVERSION, Info->szVersion, CFE_BOLD, 0);
@ -125,8 +132,8 @@ DeleteCurrentAppsDB(VOID)
return FALSE; return FALSE;
hr = StringCbPrintfW(szCabPath, sizeof(szCabPath), hr = StringCbPrintfW(szCabPath, sizeof(szCabPath),
L"%ls\\rappmgr.cab", L"%ls\\rappmgr.cab",
szPath); szPath);
if (FAILED(hr)) if (FAILED(hr))
return FALSE; return FALSE;
@ -138,8 +145,8 @@ DeleteCurrentAppsDB(VOID)
return FALSE; return FALSE;
hr = StringCbPrintfW(szSearchPath, sizeof(szSearchPath), hr = StringCbPrintfW(szSearchPath, sizeof(szSearchPath),
L"%ls*.txt", L"%ls*.txt",
szPath); szPath);
if (FAILED(hr)) if (FAILED(hr))
return FALSE; return FALSE;
@ -151,13 +158,14 @@ DeleteCurrentAppsDB(VOID)
do do
{ {
hr = StringCbPrintfW(szTmp, sizeof(szTmp), hr = StringCbPrintfW(szTmp, sizeof(szTmp),
L"%ls%ls", L"%ls%ls",
szPath, FindFileData.cFileName); szPath, FindFileData.cFileName);
if (FAILED(hr)) if (FAILED(hr))
continue; continue;
result = result && DeleteFileW(szTmp); result = result && DeleteFileW(szTmp);
} while (FindNextFileW(hFind, &FindFileData) != 0); }
while (FindNextFileW(hFind, &FindFileData) != 0);
FindClose(hFind); FindClose(hFind);
@ -181,15 +189,15 @@ UpdateAppsDB(VOID)
return FALSE; return FALSE;
if (FAILED(StringCbPrintfW(szCabPath, sizeof(szCabPath), if (FAILED(StringCbPrintfW(szCabPath, sizeof(szCabPath),
L"%ls\\rappmgr.cab", L"%ls\\rappmgr.cab",
szPath))) szPath)))
{ {
return FALSE; return FALSE;
} }
if (FAILED(StringCbPrintfW(szAppsPath, sizeof(szAppsPath), if (FAILED(StringCbPrintfW(szAppsPath, sizeof(szAppsPath),
L"%ls\\rapps\\", L"%ls\\rapps\\",
szPath))) szPath)))
{ {
return FALSE; return FALSE;
} }
@ -215,8 +223,8 @@ EnumAvailableApplications(INT EnumType, AVAILENUMPROC lpEnumProc)
return FALSE; return FALSE;
hr = StringCbPrintfW(szCabPath, sizeof(szCabPath), hr = StringCbPrintfW(szCabPath, sizeof(szCabPath),
L"%ls\\rappmgr.cab", L"%ls\\rappmgr.cab",
szPath); szPath);
if (FAILED(hr)) if (FAILED(hr))
return FALSE; return FALSE;
@ -263,7 +271,7 @@ EnumAvailableApplications(INT EnumType, AVAILENUMPROC lpEnumProc)
Info = CONTAINING_RECORD(pCachedEntry, APPLICATION_INFO, List); Info = CONTAINING_RECORD(pCachedEntry, APPLICATION_INFO, List);
/* do we already have this entry in cache? */ /* do we already have this entry in cache? */
if(_wcsicmp(FindFileData.cFileName, Info->cFileName) == 0) if (_wcsicmp(FindFileData.cFileName, Info->cFileName) == 0)
{ {
/* is it current enough, or the file has been modified since our last time here? */ /* is it current enough, or the file has been modified since our last time here? */
if (CompareFileTime(&FindFileData.ftLastWriteTime, &Info->ftCacheStamp) == 1) if (CompareFileTime(&FindFileData.ftLastWriteTime, &Info->ftCacheStamp) == 1)
@ -283,21 +291,21 @@ EnumAvailableApplications(INT EnumType, AVAILENUMPROC lpEnumProc)
} }
/* create a new entry */ /* create a new entry */
Info = (PAPPLICATION_INFO)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(APPLICATION_INFO)); Info = (PAPPLICATION_INFO) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(APPLICATION_INFO));
if(!Info) if (!Info)
break; break;
Info->Category = ParserGetInt(L"Category", FindFileData.cFileName); Info->Category = ParserGetInt(L"Category", FindFileData.cFileName);
/* copy the cache-related fields for the next time */ /* copy the cache-related fields for the next time */
RtlCopyMemory(&Info->cFileName, &FindFileData.cFileName, MAX_PATH); RtlCopyMemory(&Info->cFileName, &FindFileData.cFileName, MAX_PATH);
RtlCopyMemory(&Info->ftCacheStamp, &FindFileData.ftLastWriteTime, sizeof(FILETIME)); RtlCopyMemory(&Info->ftCacheStamp, &FindFileData.ftLastWriteTime, sizeof(FILETIME));
/* add our cached entry to the cached list */ /* add our cached entry to the cached list */
InsertTailList(&CachedEntriesHead, &Info->List); InsertTailList(&CachedEntriesHead, &Info->List);
skip_if_cached: skip_if_cached:
if (Info->Category == FALSE) if (Info->Category == FALSE)
continue; continue;
@ -310,26 +318,27 @@ skip_if_cached:
if (Info->szUrlDownload[0] == 0) if (Info->szUrlDownload[0] == 0)
{ {
if (!_GetString(L"Name", Info->szName, FindFileData.cFileName) if (!_GetString(L"Name", Info->szName, FindFileData.cFileName)
|| !_GetString(L"URLDownload", Info->szUrlDownload, FindFileData.cFileName)) || !_GetString(L"URLDownload", Info->szUrlDownload, FindFileData.cFileName))
{ {
continue; continue;
} }
_GetStringNullFailure(L"RegName", Info->szRegName, FindFileData.cFileName); _GetStringNullFailure(L"RegName", Info->szRegName, FindFileData.cFileName);
_GetStringNullFailure(L"Version", Info->szVersion, FindFileData.cFileName); _GetStringNullFailure(L"Version", Info->szVersion, FindFileData.cFileName);
_GetStringNullFailure(L"License", Info->szLicense, FindFileData.cFileName); _GetStringNullFailure(L"License", Info->szLicense, FindFileData.cFileName);
_GetStringNullFailure(L"Description", Info->szDesc, FindFileData.cFileName); _GetStringNullFailure(L"Description", Info->szDesc, FindFileData.cFileName);
_GetStringNullFailure(L"Size", Info->szSize, FindFileData.cFileName); _GetStringNullFailure(L"Size", Info->szSize, FindFileData.cFileName);
_GetStringNullFailure(L"URLSite", Info->szUrlSite, FindFileData.cFileName); _GetStringNullFailure(L"URLSite", Info->szUrlSite, FindFileData.cFileName);
_GetStringNullFailure(L"CDPath", Info->szCDPath, FindFileData.cFileName); _GetStringNullFailure(L"CDPath", Info->szCDPath, FindFileData.cFileName);
_GetStringNullFailure(L"SHA1", Info->szSHA1, FindFileData.cFileName); _GetStringNullFailure(L"SHA1", Info->szSHA1, FindFileData.cFileName);
} }
if (!lpEnumProc(Info)) if (!lpEnumProc(Info))
break; break;
} while (FindNextFileW(hFind, &FindFileData) != 0); }
while (FindNextFileW(hFind, &FindFileData) != 0);
FindClose(hFind); FindClose(hFind);
@ -338,16 +347,16 @@ skip_if_cached:
VOID FreeCachedAvailableEntries(VOID) VOID FreeCachedAvailableEntries(VOID)
{ {
PAPPLICATION_INFO Info; PAPPLICATION_INFO Info;
/* loop and deallocate all the cached app infos in the list */ /* loop and deallocate all the cached app infos in the list */
for (pCachedEntry = CachedEntriesHead.Flink; pCachedEntry != &CachedEntriesHead;) for (pCachedEntry = CachedEntriesHead.Flink; pCachedEntry != &CachedEntriesHead;)
{ {
Info = CONTAINING_RECORD(pCachedEntry, APPLICATION_INFO, List); Info = CONTAINING_RECORD(pCachedEntry, APPLICATION_INFO, List);
/* grab a reference to the next linked entry before getting rid of the current one */ /* grab a reference to the next linked entry before getting rid of the current one */
pCachedEntry = pCachedEntry->Flink; pCachedEntry = pCachedEntry->Flink;
/* flush them down the toilet :D */ /* flush them down the toilet :D */
RemoveEntryList(&Info->List); RemoveEntryList(&Info->List);
HeapFree(GetProcessHeap(), 0, Info); HeapFree(GetProcessHeap(), 0, Info);