[SYSDM] Improve the user profile dialog
authorEric Kohl <eric.kohl@reactos.org>
Sat, 4 Jan 2020 13:54:30 +0000 (14:54 +0100)
committerEric Kohl <eric.kohl@reactos.org>
Sat, 4 Jan 2020 13:54:30 +0000 (14:54 +0100)
- Currently used profiles cannot be copied or deleted.
- Unknown profiles cannot be copied.
- A double click on a profile opens the change profile type dialog.

dll/cpl/sysdm/userprofile.c

index bd2ac0f..faef543 100644 (file)
@@ -18,6 +18,7 @@ typedef struct _PROFILEDATA
 {
     DWORD dwRefCount;
     DWORD dwState;
+    BOOL bUnknownProfile;
     PWSTR pszFullName;
     PWSTR pszProfilePath;
 } PROFILEDATA, *PPROFILEDATA;
@@ -391,7 +392,8 @@ BOOL
 GetProfileName(
     _In_ PSID pProfileSid,
     _In_ DWORD dwNameBufferSize,
-    _Out_ PWSTR pszNameBuffer)
+    _Out_ PWSTR pszNameBuffer,
+    _Out_ PBOOL pbUnknownProfile)
 {
     WCHAR szAccountName[128], szDomainName[128];
     DWORD dwAccountNameSize, dwDomainNameSize;
@@ -409,6 +411,7 @@ GetProfileName(
     {
         /* Unknown account */
         LoadStringW(hApplet, IDS_USERPROFILE_ACCOUNT_UNKNOWN, pszNameBuffer, dwNameBufferSize);
+        *pbUnknownProfile = TRUE;
     }
     else
     {
@@ -426,6 +429,7 @@ GetProfileName(
             /* Normal account */
             wsprintf(pszNameBuffer, L"%s\\%s", szDomainName, szAccountName);
         }
+        *pbUnknownProfile = FALSE;
     }
 
     return TRUE;
@@ -479,6 +483,7 @@ AddUserProfile(
     HANDLE hFile;
     SYSTEMTIME SystemTime;
     ULONGLONG ullProfileSize;
+    BOOL bUnknownProfile;
     DWORD dwError;
 
     /* Get the profile path */
@@ -521,7 +526,10 @@ AddUserProfile(
     GetProfileSize(szProfilePath, &ullProfileSize);
 
     /* Get the profile name */
-    if (!GetProfileName(pProfileSid, ARRAYSIZE(szNameBuffer), szNameBuffer))
+    if (!GetProfileName(pProfileSid,
+                        ARRAYSIZE(szNameBuffer),
+                        szNameBuffer,
+                        &bUnknownProfile))
         return;
 
     /* Get the profile state value */
@@ -560,6 +568,7 @@ AddUserProfile(
 
     pProfileData->dwRefCount = dwRefCount;
     pProfileData->dwState = dwState;
+    pProfileData->bUnknownProfile = bUnknownProfile;
 
     ptr = (PWSTR)((ULONG_PTR)pProfileData + sizeof(PROFILEDATA));
     pProfileData->pszFullName = ptr;
@@ -629,29 +638,37 @@ UpdateButtonState(
     BOOL bChange = FALSE;
     BOOL bCopy = FALSE;
     BOOL bDelete = FALSE;
+    PPROFILEDATA pProfileData;
 
-    iSelected = ListView_GetNextItem(hwndListView, -1, LVNI_SELECTED);
-    if (iSelected != -1)
+    if (ListView_GetSelectedCount(hwndListView) != 0)
     {
-        Item.mask = LVIF_PARAM;
-        Item.iItem = iSelected;
-        Item.iSubItem = 0;
-        if (ListView_GetItem(hwndListView, &Item))
+        iSelected = ListView_GetNextItem(hwndListView, -1, LVNI_SELECTED);
+        if (iSelected != -1)
         {
-            if (Item.lParam != 0)
+            Item.mask = LVIF_PARAM;
+            Item.iItem = iSelected;
+            Item.iSubItem = 0;
+            if (ListView_GetItem(hwndListView, &Item))
             {
-                bCopy = (((PPROFILEDATA)Item.lParam)->dwRefCount == 0);
-                bDelete = (((PPROFILEDATA)Item.lParam)->dwRefCount == 0);
+                if (Item.lParam != 0)
+                {
+                    pProfileData = (PPROFILEDATA)Item.lParam;
+
+                    if (pProfileData->bUnknownProfile)
+                    {
+                        bDelete = TRUE;
+                        bCopy = FALSE;
+                    }
+                    else
+                    {
+                        bDelete = (pProfileData->dwRefCount == 0);
+                        bCopy = (pProfileData->dwRefCount == 0);
+                    }
+                }
             }
-        }
 
-        bChange = TRUE;
-    }
-    else
-    {
-        bChange = FALSE;
-        bCopy = FALSE;
-        bDelete = FALSE;
+            bChange = TRUE;
+        }
     }
 
     EnableWindow(GetDlgItem(hwndDlg, IDC_USERPROFILE_CHANGE), bChange);
@@ -823,9 +840,12 @@ OnNotify(
     {
         ShellExecuteW(hwndDlg, NULL, L"usrmgr.cpl", NULL, NULL, 0);
     }
-    else if (nmhdr->idFrom == IDC_USERPROFILE_LIST && nmhdr->code == LVN_ITEMCHANGED)
+    else if (nmhdr->idFrom == IDC_USERPROFILE_LIST)
     {
-        UpdateButtonState(hwndDlg, nmhdr->hwndFrom);
+        if (nmhdr->code == LVN_ITEMCHANGED)
+            UpdateButtonState(hwndDlg, nmhdr->hwndFrom);
+        else if (nmhdr->code == NM_DBLCLK)
+            ChangeUserProfileType(hwndDlg);
     }
 }