Author: dquintana Date: Sun Mar 15 17:33:55 2015 New Revision: 66729
URL: http://svn.reactos.org/svn/reactos?rev=66729&view=rev Log: [NTOBJSHEX] * Fix CompareID sorting to prefer "folders" first, and sort by name otherwise.
Modified: trunk/reactos/dll/shellext/ntobjshex/ntobjns.cpp trunk/reactos/dll/shellext/ntobjshex/regfolder.cpp
Modified: trunk/reactos/dll/shellext/ntobjshex/ntobjns.cpp URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/shellext/ntobjshex/ntob... ============================================================================== --- trunk/reactos/dll/shellext/ntobjshex/ntobjns.cpp [iso-8859-1] (original) +++ trunk/reactos/dll/shellext/ntobjshex/ntobjns.cpp [iso-8859-1] Sun Mar 15 17:33:55 2015 @@ -294,45 +294,57 @@ HRESULT CompareIDs(LPARAM lParam, NtPidlEntry * first, NtPidlEntry * second) { if (LOWORD(lParam) != 0) + { + DbgPrint("Unsupported sorting mode.\n"); return E_INVALIDARG; - - if (second->cb > first->cb) - return MAKE_HRESULT(0, 0, (USHORT) 1); - if (second->cb < first->cb) - return MAKE_HRESULT(0, 0, (USHORT) -1); - - if (second->entryNameLength > first->entryNameLength) - return MAKE_HRESULT(0, 0, (USHORT) 1); - if (second->entryNameLength < first->entryNameLength) - return MAKE_HRESULT(0, 0, (USHORT) -1); + }
if (HIWORD(lParam) == SHCIDS_ALLFIELDS) { - int ord = memcmp(second, first, first->cb); + int minsize = min(first->cb, second->cb); + int ord = memcmp(second, first, minsize);
if (ord != 0) return MAKE_HRESULT(0, 0, (USHORT) ord); + + if (second->cb > first->cb) + return MAKE_HRESULT(0, 0, (USHORT) 1); + if (second->cb < first->cb) + return MAKE_HRESULT(0, 0, (USHORT) -1); } else if (HIWORD(lParam) == SHCIDS_CANONICALONLY) { - int ord = StrCmpNW(second->entryName, first->entryName, first->entryNameLength); + int minlength = min(first->entryNameLength, second->entryNameLength); + int ord = StrCmpNW(first->entryName, second->entryName, minlength);
if (ord != 0) return MAKE_HRESULT(0, 0, (USHORT) ord); + + if (second->entryNameLength > first->entryNameLength) + return MAKE_HRESULT(0, 0, (USHORT) 1); + if (second->entryNameLength < first->entryNameLength) + return MAKE_HRESULT(0, 0, (USHORT) -1); } else { - int ord = (int) second->objectType - (int) first->objectType; - - if (ord > 0) + bool f1 = (first->objectType == DIRECTORY_OBJECT) || (first->objectType == KEY_OBJECT); + bool f2 = (second->objectType == DIRECTORY_OBJECT) || (second->objectType == KEY_OBJECT); + + if (f1 && !f2) + return MAKE_HRESULT(0, 0, (USHORT) -1); + if (f2 && !f1) return MAKE_HRESULT(0, 0, (USHORT) 1); - if (ord < 0) - return MAKE_HRESULT(0, 0, (USHORT) -1); - - ord = StrCmpNW(second->entryName, first->entryName, first->entryNameLength / sizeof(WCHAR)); + + int minlength = min(first->entryNameLength, second->entryNameLength); + int ord = StrCmpNW(first->entryName, second->entryName, minlength);
if (ord != 0) return MAKE_HRESULT(0, 0, (USHORT) ord); + + if (second->entryNameLength > first->entryNameLength) + return MAKE_HRESULT(0, 0, (USHORT) 1); + if (second->entryNameLength < first->entryNameLength) + return MAKE_HRESULT(0, 0, (USHORT) -1); }
return S_OK;
Modified: trunk/reactos/dll/shellext/ntobjshex/regfolder.cpp URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/shellext/ntobjshex/regf... ============================================================================== --- trunk/reactos/dll/shellext/ntobjshex/regfolder.cpp [iso-8859-1] (original) +++ trunk/reactos/dll/shellext/ntobjshex/regfolder.cpp [iso-8859-1] Sun Mar 15 17:33:55 2015 @@ -290,45 +290,57 @@ HRESULT CompareIDs(LPARAM lParam, RegPidlEntry * first, RegPidlEntry * second) { if (LOWORD(lParam) != 0) + { + DbgPrint("Unsupported sorting mode.\n"); return E_INVALIDARG; - - if (second->cb > first->cb) - return MAKE_HRESULT(0, 0, (USHORT) 1); - if (second->cb < first->cb) - return MAKE_HRESULT(0, 0, (USHORT) -1); - - if (second->entryNameLength > first->entryNameLength) - return MAKE_HRESULT(0, 0, (USHORT) 1); - if (second->entryNameLength < first->entryNameLength) - return MAKE_HRESULT(0, 0, (USHORT) -1); + }
if (HIWORD(lParam) == SHCIDS_ALLFIELDS) { - int ord = memcmp(second, first, first->cb); + int minsize = min(first->cb, second->cb); + int ord = memcmp(second, first, minsize);
if (ord != 0) return MAKE_HRESULT(0, 0, (USHORT) ord); + + if (second->cb > first->cb) + return MAKE_HRESULT(0, 0, (USHORT) 1); + if (second->cb < first->cb) + return MAKE_HRESULT(0, 0, (USHORT) -1); } else if (HIWORD(lParam) == SHCIDS_CANONICALONLY) { - int ord = StrCmpNW(second->entryName, first->entryName, first->entryNameLength); + int minlength = min(first->entryNameLength, second->entryNameLength); + int ord = StrCmpNW(first->entryName, second->entryName, minlength);
if (ord != 0) return MAKE_HRESULT(0, 0, (USHORT) ord); + + if (second->entryNameLength > first->entryNameLength) + return MAKE_HRESULT(0, 0, (USHORT) 1); + if (second->entryNameLength < first->entryNameLength) + return MAKE_HRESULT(0, 0, (USHORT) -1); } else { - int ord = (int) second->entryType - (int) first->entryType; - - if (ord > 0) + bool f1 = (first->entryType == REG_ENTRY_KEY) || (first->entryType == REG_ENTRY_ROOT); + bool f2 = (second->entryType == REG_ENTRY_KEY) || (second->entryType == REG_ENTRY_ROOT); + + if (f1 && !f2) + return MAKE_HRESULT(0, 0, (USHORT) -1); + if (f2 && !f1) return MAKE_HRESULT(0, 0, (USHORT) 1); - if (ord < 0) - return MAKE_HRESULT(0, 0, (USHORT) -1); - - ord = StrCmpNW(second->entryName, first->entryName, first->entryNameLength / sizeof(WCHAR)); + + int minlength = min(first->entryNameLength, second->entryNameLength); + int ord = StrCmpNW(first->entryName, second->entryName, minlength);
if (ord != 0) return MAKE_HRESULT(0, 0, (USHORT) ord); + + if (second->entryNameLength > first->entryNameLength) + return MAKE_HRESULT(0, 0, (USHORT) 1); + if (second->entryNameLength < first->entryNameLength) + return MAKE_HRESULT(0, 0, (USHORT) -1); }
return S_OK;