[SYSDM] Calculate and display the size of the user profiles
authorEric Kohl <eric.kohl@reactos.org>
Wed, 11 Sep 2019 08:14:02 +0000 (10:14 +0200)
committerEric Kohl <eric.kohl@reactos.org>
Wed, 11 Sep 2019 08:14:02 +0000 (10:14 +0200)
dll/cpl/sysdm/userprofile.c

index b266a97..d2dcb66 100644 (file)
@@ -323,6 +323,68 @@ SetListViewColumns(
 }
 
 
+static
+BOOL
+GetProfileSize(
+    PWSTR pszProfilePath,
+    PULONGLONG pullProfileSize)
+{
+    HANDLE hFile = INVALID_HANDLE_VALUE;
+    WIN32_FIND_DATA FindData;
+    DWORD dwProfilePathLength;
+    ULARGE_INTEGER Size;
+    BOOL bResult = TRUE;
+
+    dwProfilePathLength = wcslen(pszProfilePath);
+
+    wcscat(pszProfilePath, L"\\*.*");
+
+    hFile = FindFirstFileW(pszProfilePath, &FindData);
+    if (hFile == INVALID_HANDLE_VALUE)
+    {
+        if ((GetLastError() != ERROR_FILE_NOT_FOUND) &&
+            (GetLastError() != ERROR_PATH_NOT_FOUND))
+            bResult = FALSE;
+
+        goto done;
+    }
+
+    do
+    {
+        if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+        {
+            if ((_wcsicmp(FindData.cFileName, L".") == 0) ||
+                (_wcsicmp(FindData.cFileName, L"..") == 0))
+                continue;
+
+            pszProfilePath[dwProfilePathLength + 1] = UNICODE_NULL;
+            wcscat(pszProfilePath, FindData.cFileName);
+
+            if (!GetProfileSize(pszProfilePath, pullProfileSize))
+            {
+                bResult = FALSE;
+                goto done;
+            }
+        }
+        else
+        {
+            Size.u.LowPart = FindData.nFileSizeLow;
+            Size.u.HighPart = FindData.nFileSizeHigh;
+            *pullProfileSize += Size.QuadPart;
+        }
+    }
+    while (FindNextFile(hFile, &FindData));
+
+done:
+    pszProfilePath[dwProfilePathLength] = UNICODE_NULL;
+
+    if (hFile != INVALID_HANDLE_VALUE)
+        FindClose(hFile);
+
+    return bResult;
+}
+
+
 static
 BOOL
 GetProfileName(
@@ -387,6 +449,7 @@ AddUserProfile(
     WIN32_FIND_DATA FindData;
     HANDLE hFile;
     SYSTEMTIME SystemTime;
+    ULONGLONG ullProfileSize;
     DWORD dwError;
 
     /* Get the profile path */
@@ -424,6 +487,10 @@ AddUserProfile(
     FindClose(hFile);
     szProfilePath[dwProfilePathLength] = UNICODE_NULL;
 
+    /* Get the profile size */
+    ullProfileSize = 0ULL;
+    GetProfileSize(szProfilePath, &ullProfileSize);
+
     /* Get the profile name */
     if (!GetProfileName(pProfileSid, ARRAYSIZE(szNameBuffer), szNameBuffer))
         return;
@@ -466,6 +533,8 @@ AddUserProfile(
     iItem = ListView_InsertItem(hwndListView, &lvi);
 
     /* FIXME: Set the profile size */
+    swprintf(szNameBuffer, L"%I64u MB", ullProfileSize / (1024 * 1024));
+    ListView_SetItemText(hwndListView, iItem, 1, szNameBuffer);
 
     /* Set the profile type */
     if (dwState & 0x0001) // PROFILE_MANDATORY