[RAPPS]
[reactos.git] / reactos / base / applications / rapps / available.c
index 016e580..f650af2 100644 (file)
@@ -8,7 +8,6 @@
 
 #include "rapps.h"
 
-
 BOOL
 ShowAvailableAppInfo(INT Index)
 {
@@ -47,11 +46,16 @@ DeleteCurrentAppsDB(VOID)
     WCHAR szSearchPath[MAX_PATH];
     WCHAR szPath[MAX_PATH];
     WCHAR szTmp[MAX_PATH];
+    HRESULT hr;
 
-    if (!GetCurrentDirectoryW(MAX_PATH, szPath))
+    if (!GetStorageDirectory(szPath, sizeof(szPath) / sizeof(szPath[0])))
         return FALSE;
 
-    swprintf(szCabPath, L"%s\\rappmgr.cab", szPath);
+    hr = StringCbPrintfW(szCabPath, sizeof(szCabPath),
+                         L"%ls\\rappmgr.cab",
+                         szPath);
+    if (FAILED(hr))
+        return FALSE;
 
     if (GetFileAttributesW(szCabPath) != INVALID_FILE_ATTRIBUTES)
     {
@@ -59,8 +63,15 @@ DeleteCurrentAppsDB(VOID)
             return FALSE;
     }
 
-    wcscat(szPath, L"\\rapps\\");
-    swprintf(szSearchPath, L"%s*.txt", szPath);
+    hr = StringCbCatW(szPath, sizeof(szPath), L"\\rapps\\");
+    if (FAILED(hr))
+        return FALSE;
+
+    hr = StringCbPrintfW(szSearchPath, sizeof(szSearchPath),
+                         L"%ls*.txt",
+                         szPath);
+    if (FAILED(hr))
+        return FALSE;
 
     hFind = FindFirstFileW(szSearchPath, &FindFileData);
     if (hFind == INVALID_HANDLE_VALUE)
@@ -68,8 +79,10 @@ DeleteCurrentAppsDB(VOID)
 
     do
     {
-        swprintf(szTmp, L"%s%s", szPath, FindFileData.cFileName);
-        if (!DeleteFileW(szTmp))
+        hr = StringCbPrintfW(szTmp, sizeof(szTmp),
+                             L"%ls%ls",
+                             szPath, FindFileData.cFileName);
+        if (FAILED(hr) || !DeleteFileW(szTmp))
         {
             FindClose(hFind);
             return FALSE;
@@ -95,13 +108,22 @@ UpdateAppsDB(VOID)
 
     DownloadApplicationsDB(APPLICATION_DATEBASE_URL);
 
-    if (!GetCurrentDirectoryW(MAX_PATH, szPath))
+    if (!GetStorageDirectory(szPath, sizeof(szPath) / sizeof(szPath[0])))
         return FALSE;
 
-    swprintf(szCabPath, L"%s\\rappmgr.cab", szPath);
+    if (FAILED(StringCbPrintfW(szCabPath, sizeof(szCabPath),
+                               L"%ls\\rappmgr.cab",
+                               szPath)))
+    {
+        return FALSE;
+    }
 
-    wcscat(szPath, L"\\rapps\\");
-    wcscpy(szAppsPath, szPath);
+    if (FAILED(StringCbPrintfW(szAppsPath, sizeof(szAppsPath),
+                               L"%ls\\rapps\\",
+                               szPath)))
+    {
+        return FALSE;
+    }
 
     ExtractFilesFromCab(szCabPath, szAppsPath);
 
@@ -120,16 +142,25 @@ EnumAvailableApplications(INT EnumType, AVAILENUMPROC lpEnumProc)
     WCHAR szCabPath[MAX_PATH];
     WCHAR szLocale[4 + 1];
     APPLICATION_INFO Info;
+    HRESULT hr;
 
-    if (!GetCurrentDirectoryW(MAX_PATH, szPath))
+    if (!GetStorageDirectory(szPath, sizeof(szPath) / sizeof(szPath[0])))
     {
         return FALSE;
     }
 
-    swprintf(szCabPath, L"%s\\rappmgr.cab", szPath);
+    hr = StringCbPrintfW(szCabPath, sizeof(szCabPath),
+                         L"%ls\\rappmgr.cab",
+                         szPath);
+    if (FAILED(hr))
+        return FALSE;
 
-    wcscat(szPath, L"\\rapps\\");
-    wcscpy(szAppsPath, szPath);
+    hr = StringCbCatW(szPath, sizeof(szPath), L"\\rapps\\");
+    if (FAILED(hr))
+        return FALSE;
+    hr = StringCbCopyW(szAppsPath, sizeof(szAppsPath), szPath);
+    if (FAILED(hr))
+        return FALSE;
 
     if (!CreateDirectory(szPath, NULL) &&
         GetLastError() != ERROR_ALREADY_EXISTS)
@@ -138,9 +169,13 @@ EnumAvailableApplications(INT EnumType, AVAILENUMPROC lpEnumProc)
     }
 
     GetLocaleInfoW(GetUserDefaultLCID(), LOCALE_ILANGUAGE, szLocale, sizeof(szLocale) / sizeof(WCHAR));
-    wcscat(szSectionLocale, szLocale);
+    hr = StringCbCatW(szSectionLocale, sizeof(szSectionLocale), szLocale);
+    if (FAILED(hr))
+        return FALSE;
 
-    wcscat(szPath, L"*.txt");
+    hr = StringCbCatW(szPath, sizeof(szPath), L"*.txt");
+    if (FAILED(hr))
+        return FALSE;
 
     hFind = FindFirstFileW(szPath, &FindFileData);
     if (hFind == INVALID_HANDLE_VALUE)