Add .keep guard files in order to restore lost but empty directories we had with...
[reactos.git] / base / applications / rapps / installed.c
index 8c8cb33..2bdf69e 100644 (file)
@@ -8,11 +8,10 @@
 
 #include "rapps.h"
 
-
 BOOL
 GetApplicationString(HKEY hKey, LPWSTR lpKeyName, LPWSTR lpString)
 {
-    DWORD dwSize = MAX_PATH;
+    DWORD dwSize = MAX_PATH * sizeof(WCHAR);
 
     if (RegQueryValueExW(hKey,
                          lpKeyName,
@@ -24,7 +23,7 @@ GetApplicationString(HKEY hKey, LPWSTR lpKeyName, LPWSTR lpString)
         return TRUE;
     }
 
-    wcscpy(lpString, L"---");
+    (VOID)StringCchCopyW(lpString, MAX_PATH, L"---");
 
     return FALSE;
 }
@@ -51,7 +50,7 @@ IsInstalledApplication(LPWSTR lpRegName, BOOL IsUserKey)
         if (RegOpenKeyW(hKey, szName, &hSubKey) == ERROR_SUCCESS)
         {
             dwType = REG_SZ;
-            dwSize = MAX_PATH;
+            dwSize = sizeof(szDisplayName);
             if (RegQueryValueExW(hSubKey,
                                  L"DisplayName",
                                  NULL,
@@ -105,10 +104,10 @@ UninstallApplication(INT Index, BOOL bModify)
         ItemIndex = Index;
     }
 
-    ListView_GetItemText(hListView, ItemIndex, 0, szAppName, sizeof(szAppName) / sizeof(WCHAR));
+    ListView_GetItemText(hListView, ItemIndex, 0, szAppName, _countof(szAppName));
     WriteLogMessage(EVENTLOG_SUCCESS, MSG_SUCCESS_REMOVE, szAppName);
 
-    ZeroMemory(&Item, sizeof(LVITEM));
+    ZeroMemory(&Item, sizeof(Item));
 
     Item.mask = LVIF_PARAM;
     Item.iItem = ItemIndex;
@@ -119,7 +118,7 @@ UninstallApplication(INT Index, BOOL bModify)
     hKey = ItemInfo->hSubKey;
 
     dwType = REG_SZ;
-    dwSize = MAX_PATH;
+    dwSize = sizeof(szPath);
     if (RegQueryValueExW(hKey,
                          bModify ? szModify : szUninstall,
                          NULL,
@@ -150,7 +149,7 @@ ShowInstalledAppInfo(INT Index)
 #define GET_INFO(a, b, c, d) \
     if (GetApplicationString(Info->hSubKey, a, szInfo)) \
     { \
-        LoadStringW(hInst, b, szText, sizeof(szText) / sizeof(WCHAR)); \
+        LoadStringW(hInst, b, szText, _countof(szText)); \
         InsertRichEditText(szText, c); \
         InsertRichEditText(szInfo, d); \
     } \
@@ -191,8 +190,8 @@ RemoveAppFromRegistry(INT Index)
     Info = ListViewGetlParam(Index);
     if (!Info || !Info->hSubKey || (ItemIndex == -1)) return;
 
-    if (!LoadStringW(hInst, IDS_APP_REG_REMOVE, szMsgText, sizeof(szMsgText) / sizeof(WCHAR)) ||
-        !LoadStringW(hInst, IDS_INFORMATION, szMsgTitle, sizeof(szMsgTitle) / sizeof(WCHAR)))
+    if (!LoadStringW(hInst, IDS_APP_REG_REMOVE, szMsgText, _countof(szMsgText)) ||
+        !LoadStringW(hInst, IDS_INFORMATION, szMsgTitle, _countof(szMsgTitle)))
         return;
 
     if (MessageBoxW(hMainWnd, szMsgText, szMsgTitle, MB_YESNO | MB_ICONQUESTION) == IDYES)
@@ -205,7 +204,7 @@ RemoveAppFromRegistry(INT Index)
             return;
         }
 
-        if (!LoadStringW(hInst, IDS_UNABLE_TO_REMOVE, szMsgText, sizeof(szMsgText) / sizeof(WCHAR)))
+        if (!LoadStringW(hInst, IDS_UNABLE_TO_REMOVE, szMsgText, _countof(szMsgText)))
             return;
 
         MessageBoxW(hMainWnd, szMsgText, NULL, MB_OK | MB_ICONERROR);
@@ -255,7 +254,7 @@ EnumInstalledApplications(INT EnumType, BOOL IsUserKey, APPENUMPROC lpEnumProc)
             }
 
             dwType = REG_SZ;
-            dwSize = MAX_PATH;
+            dwSize = sizeof(pszParentKeyName);
             bIsUpdate = (RegQueryValueExW(Info.hSubKey,
                                           L"ParentKeyName",
                                           NULL,
@@ -263,7 +262,7 @@ EnumInstalledApplications(INT EnumType, BOOL IsUserKey, APPENUMPROC lpEnumProc)
                                           (LPBYTE)pszParentKeyName,
                                           &dwSize) == ERROR_SUCCESS);
 
-            dwSize = MAX_PATH;
+            dwSize = sizeof(pszDisplayName);
             if (RegQueryValueExW(Info.hSubKey,
                                  L"DisplayName",
                                  NULL,
@@ -280,11 +279,23 @@ EnumInstalledApplications(INT EnumType, BOOL IsUserKey, APPENUMPROC lpEnumProc)
                         ((EnumType == ENUM_APPLICATIONS) && (!bIsUpdate)) || /* Applications only */
                         ((EnumType == ENUM_UPDATES) && (bIsUpdate))) /* Updates only */
                     {
-                        if (!lpEnumProc(ItemIndex, pszDisplayName, Info))
+                        if (!lpEnumProc(ItemIndex, pszDisplayName, &Info))
                             break;
                     }
+                    else
+                    {
+                        RegCloseKey(Info.hSubKey);
+                    }
+                }
+                else
+                {
+                    RegCloseKey(Info.hSubKey);
                 }
             }
+            else
+            {
+                RegCloseKey(Info.hSubKey);
+            }
         }
 
         dwSize = MAX_PATH;