[RAPPS]
[reactos.git] / reactos / base / applications / rapps / available.cpp
index b194ebe..f484260 100644 (file)
@@ -91,7 +91,7 @@ VOID CAvailableApplicationInfo::RetrieveLanguages()
 
     // Parse parameter string
     ATL::CStringW m_szLocale;
-    int iLCID;
+    INT iLCID;
     for (INT i = 0; szBuffer[i] != UNICODE_NULL; ++i)
     {
         if (szBuffer[i] != cDelimiter && szBuffer[i] != L'\n')
@@ -227,37 +227,32 @@ VOID CAvailableApps::FreeCachedEntries()
     }
 }
 
-BOOL CAvailableApps::DeleteCurrentAppsDB()
+VOID CAvailableApps::DeleteCurrentAppsDB()
 {
     HANDLE hFind = INVALID_HANDLE_VALUE;
     WIN32_FIND_DATAW FindFileData;
-    BOOL result = TRUE;
 
     if (m_szPath.IsEmpty())
-        return FALSE;
+        return;
 
-    result = result && DeleteFileW(m_szCabPath.GetString());
+    DeleteFileW(m_szCabPath.GetString());
     hFind = FindFirstFileW(m_szSearchPath.GetString(), &FindFileData);
 
-    if (hFind == INVALID_HANDLE_VALUE)
-        return result;
-
-    ATL::CStringW szTmp;
-    do
+    if (hFind != INVALID_HANDLE_VALUE)
     {
-        szTmp = m_szPath + FindFileData.cFileName;
-        result = result && DeleteFileW(szTmp.GetString());
-    } while (FindNextFileW(hFind, &FindFileData) != 0);
-
-    FindClose(hFind);
-
-    return result;
+        ATL::CStringW szTmp;
+        do
+        {
+            szTmp = m_szPath + FindFileData.cFileName;
+            DeleteFileW(szTmp.GetString());
+        } while (FindNextFileW(hFind, &FindFileData) != 0);
+        FindClose(hFind);
+    }
 }
 
 BOOL CAvailableApps::UpdateAppsDB()
 {
-    if (!DeleteCurrentAppsDB())
-        return FALSE;
+    DeleteCurrentAppsDB();
 
     CDownloadManager::DownloadApplicationsDB(APPLICATION_DATABASE_URL);
 
@@ -287,14 +282,16 @@ BOOL CAvailableApps::EnumAvailableApplications(INT EnumType, AVAILENUMPROC lpEnu
 
     if (hFind == INVALID_HANDLE_VALUE)
     {
-        if (GetFileAttributesW(m_szCabPath) == INVALID_FILE_ATTRIBUTES)
-            CDownloadManager::DownloadApplicationsDB(APPLICATION_DATABASE_URL);
+        if(!UpdateAppsDB()) {
+            return FALSE;
+        }
 
-        ExtractFilesFromCab(m_szCabPath, m_szAppsPath);
         hFind = FindFirstFileW(m_szSearchPath.GetString(), &FindFileData);
 
         if (hFind == INVALID_HANDLE_VALUE)
+        {
             return FALSE;
+        }
     }
 
     do
@@ -345,8 +342,8 @@ skip_if_cached:
 
         Info->RefreshAppInfo();
 
-        if (!lpEnumProc(static_cast<PAPPLICATION_INFO>(Info), m_szAppsPath.GetString()))
-            break;
+        if (lpEnumProc)
+            lpEnumProc(static_cast<PAPPLICATION_INFO>(Info), m_szAppsPath.GetString());
 
     } while (FindNextFileW(hFind, &FindFileData) != 0);
 
@@ -354,17 +351,52 @@ skip_if_cached:
     return TRUE;
 }
 
-const ATL::CStringW & CAvailableApps::GetFolderPath()
+const PAPPLICATION_INFO CAvailableApps::FindInfo(const ATL::CStringW& szAppName)
+{
+    if (m_InfoList.IsEmpty())
+    {
+        return NULL;
+    }
+
+    // linear search
+    POSITION CurrentListPosition = m_InfoList.GetHeadPosition();
+    PAPPLICATION_INFO info;
+    while (CurrentListPosition != NULL)
+    {
+        info = m_InfoList.GetNext(CurrentListPosition);
+        if (info->szName == szAppName)
+        {
+            return info;
+        }
+    }
+    return NULL;
+}
+
+ATL::CSimpleArray<PAPPLICATION_INFO> CAvailableApps::FindInfoList(const ATL::CSimpleArray<ATL::CStringW> &arrAppsNames)
+{
+    ATL::CSimpleArray<PAPPLICATION_INFO> result;
+    for (INT i = 0; i < arrAppsNames.GetSize(); ++i)
+    {
+        PAPPLICATION_INFO Info = FindInfo(arrAppsNames[i]);
+        if (Info)
+        {
+            result.Add(Info);
+        }
+    }
+    return result;
+}
+
+const ATL::CStringW& CAvailableApps::GetFolderPath()
 {
     return m_szPath;
 }
 
-const ATL::CStringW & CAvailableApps::GetAppPath()
+const ATL::CStringW& CAvailableApps::GetAppPath()
 {
     return m_szAppsPath;
 }
 
-const ATL::CStringW & CAvailableApps::GetCabPath()
+const ATL::CStringW& CAvailableApps::GetCabPath()
 {
     return m_szCabPath;
 }
@@ -384,109 +416,3 @@ const LPCWSTR CAvailableApps::GetCabPathString()
     return m_szPath.GetString();
 }
 // CAvailableApps
-
-// CConfigParser
-ATL::CStringW CConfigParser::m_szLocaleID;
-ATL::CStringW CConfigParser::m_szCachedINISectionLocale;
-ATL::CStringW CConfigParser::m_szCachedINISectionLocaleNeutral;
-
-CConfigParser::CConfigParser(const ATL::CStringW& FileName) : szConfigPath(GetINIFullPath(FileName))
-{
-    // we don't have cached section strings for the current system language, create them, lazy
-    CacheINILocaleLazy();
-}
-
-ATL::CStringW CConfigParser::GetINIFullPath(const ATL::CStringW& FileName)
-{
-    ATL::CStringW szDir;
-    ATL::CStringW szBuffer;
-
-    GetStorageDirectory(szDir);
-    szBuffer.Format(L"%ls\\rapps\\%ls", szDir, FileName);
-
-    return szBuffer;
-}
-
-VOID CConfigParser::CacheINILocaleLazy()
-{
-    if (m_szLocaleID.IsEmpty())
-    {
-        // TODO: Set default locale if call fails
-        // find out what is the current system lang code (e.g. "0a") and append it to SectionLocale
-        GetLocaleInfoW(GetUserDefaultLCID(), LOCALE_ILANGUAGE,
-                       m_szLocaleID.GetBuffer(m_cchLocaleSize), m_cchLocaleSize);
-
-        m_szLocaleID.ReleaseBuffer();
-        m_szCachedINISectionLocale = L"Section." + m_szLocaleID;
-
-        // turn "Section.0c0a" into "Section.0a", keeping just the neutral lang part
-        m_szCachedINISectionLocaleNeutral = m_szCachedINISectionLocale + m_szLocaleID.Right(2);
-    }
-}
-
-const ATL::CStringW& CConfigParser::GetLocale()
-{
-    CacheINILocaleLazy();
-    return m_szLocaleID;
-}
-
-INT CConfigParser::GetLocaleSize()
-{
-    return m_cchLocaleSize;
-}
-
-UINT CConfigParser::GetString(const ATL::CStringW& KeyName, ATL::CStringW& ResultString)
-{
-    DWORD dwResult;
-
-    LPWSTR ResultStringBuffer = ResultString.GetBuffer(MAX_PATH);
-    // 1st - find localized strings (e.g. "Section.0c0a")
-    dwResult = GetPrivateProfileStringW(m_szCachedINISectionLocale.GetString(),
-                                        KeyName.GetString(),
-                                        NULL,
-                                        ResultStringBuffer,
-                                        MAX_PATH,
-                                        szConfigPath.GetString());
-
-    if (!dwResult)
-    {
-        // 2nd - if they weren't present check for neutral sub-langs/ generic translations (e.g. "Section.0a")
-        dwResult = GetPrivateProfileStringW(m_szCachedINISectionLocaleNeutral.GetString(),
-                                            KeyName.GetString(),
-                                            NULL,
-                                            ResultStringBuffer,
-                                            MAX_PATH,
-                                            szConfigPath.GetString());
-        if (!dwResult)
-        {
-            // 3rd - if they weren't present fallback to standard english strings (just "Section")
-            dwResult = GetPrivateProfileStringW(L"Section",
-                                                KeyName.GetString(),
-                                                NULL,
-                                                ResultStringBuffer,
-                                                MAX_PATH,
-                                                szConfigPath.GetString());
-        }
-    }
-
-    ResultString.ReleaseBuffer();
-    return (dwResult != 0 ? TRUE : FALSE);
-}
-
-UINT CConfigParser::GetInt(const ATL::CStringW& KeyName)
-{
-    ATL::CStringW Buffer;
-
-    // grab the text version of our entry
-    if (!GetString(KeyName, Buffer))
-        return FALSE;
-
-    if (Buffer.IsEmpty())
-        return FALSE;
-
-    // convert it to an actual integer
-    int result = StrToIntW(Buffer.GetString());
-
-    return (UINT) (result <= 0) ? 0 : result;
-}
-// CConfigParser