https://git.reactos.org/?p=reactos.git;a=commitdiff;h=1f4c63645314c7c6468979d761a57743a667fdef

commit 1f4c63645314c7c6468979d761a57743a667fdef
Author:     Katayama Hirofumi MZ <[email protected]>
AuthorDate: Tue Mar 6 07:40:41 2018 +0900
Commit:     Mark Jansen <[email protected]>
CommitDate: Mon Mar 5 23:40:41 2018 +0100

    [SHELL32] Fix item order in Folder Options (#415)
---
 dll/win32/shell32/dialogs/folder_options.cpp | 47 +++++++++++++++++++++++-----
 1 file changed, 39 insertions(+), 8 deletions(-)

diff --git a/dll/win32/shell32/dialogs/folder_options.cpp 
b/dll/win32/shell32/dialogs/folder_options.cpp
index cab61908b5..197b301395 100644
--- a/dll/win32/shell32/dialogs/folder_options.cpp
+++ b/dll/win32/shell32/dialogs/folder_options.cpp
@@ -359,6 +359,9 @@ CreateTreeImageList(VOID)
 static ADVANCED_ENTRY *
 Advanced_GetItem(DWORD dwID)
 {
+    if (dwID == DWORD(-1))
+        return NULL;
+
     for (INT i = 0; i < s_AdvancedCount; ++i)
     {
         ADVANCED_ENTRY *pEntry = &s_Advanced[i];
@@ -701,24 +704,52 @@ Advanced_Compare(const void *x, const void *y)
 {
     ADVANCED_ENTRY *pEntry1 = (ADVANCED_ENTRY *)x;
     ADVANCED_ENTRY *pEntry2 = (ADVANCED_ENTRY *)y;
+
     DWORD dwParentID1 = pEntry1->dwParentID;
     DWORD dwParentID2 = pEntry2->dwParentID;
-    while (dwParentID1 != dwParentID2)
+
+    if (dwParentID1 == dwParentID2)
+        return lstrcmpi(pEntry1->szText, pEntry2->szText);
+
+    DWORD i, m, n;
+    const UINT MAX_DEPTH = 32;
+    ADVANCED_ENTRY *pArray1[MAX_DEPTH];
+    ADVANCED_ENTRY *pArray2[MAX_DEPTH];
+
+    // Make ancestor lists
+    for (i = m = n = 0; i < MAX_DEPTH; ++i)
     {
         ADVANCED_ENTRY *pParent1 = Advanced_GetItem(dwParentID1);
         ADVANCED_ENTRY *pParent2 = Advanced_GetItem(dwParentID2);
         if (!pParent1 && !pParent2)
             break;
-        if (!pParent1 && pParent2)
+
+        if (pParent1)
+        {
+            pArray1[m++] = pParent1;
+            dwParentID1 = pParent1->dwParentID;
+        }
+        if (pParent2)
+        {
+            pArray2[n++] = pParent2;
+            dwParentID2 = pParent2->dwParentID;
+        }
+    }
+
+    UINT k = min(m, n);
+    for (i = 0; i < k; ++i)
+    {
+        INT nCompare = lstrcmpi(pArray1[m - i - 1]->szText, pArray2[n - i - 
1]->szText);
+        if (nCompare < 0)
             return -1;
-        if (pParent1 && !pParent2)
+        if (nCompare > 0)
             return 1;
-        INT nCompare = lstrcmpi(pParent1->szText, pParent2->szText);
-        if (nCompare)
-            return nCompare;
-        dwParentID1 = pParent1->dwParentID;
-        dwParentID2 = pParent2->dwParentID;
     }
+
+    if (m < n)
+        return -1;
+    if (m > n)
+        return 1;
     return lstrcmpi(pEntry1->szText, pEntry2->szText);
 }
 

Reply via email to