[PowerRename] Sort files alphabetically as in file explorer (#15269)

* [PowerRename] Sort files

* Run spellcheck
This commit is contained in:
Stefan Markovic
2022-01-07 18:56:12 +01:00
committed by GitHub
parent a0dca4f401
commit 67933a8470
3 changed files with 25 additions and 5 deletions

View File

@@ -246,6 +246,7 @@ CMINVOKECOMMANDINFO
CMINVOKECOMMANDINFOEX CMINVOKECOMMANDINFOEX
CMock CMock
CMONITORS CMONITORS
cmp
cmyk cmyk
cnt cnt
coclass coclass
@@ -1764,6 +1765,7 @@ SHOWNOACTIVATE
SHOWNORMAL SHOWNORMAL
SHOWWINDOW SHOWWINDOW
shtypes shtypes
SICHINT
sid sid
siex siex
SIGABRT SIGABRT

View File

@@ -89,7 +89,22 @@ HRESULT CPowerRenameEnum::_ParseEnumItems(_In_ IEnumShellItems* pesi, _In_ int d
ULONG celtFetched; ULONG celtFetched;
CComPtr<IShellItem> spsi; CComPtr<IShellItem> spsi;
while ((S_OK == pesi->Next(1, &spsi, &celtFetched)) && (SUCCEEDED(hr))) std::vector<CComPtr<IShellItem>> items;
while ((S_OK == pesi->Next(1, &spsi, &celtFetched)))
{
items.push_back(spsi);
spsi = nullptr;
}
auto cmpShellItems = [](CComPtr<IShellItem> l, CComPtr<IShellItem> r) {
int res = 0;
l->Compare(r, SICHINT_DISPLAY, &res);
return res < 0;
};
std::sort(items.begin(), items.end(), cmpShellItems);
for (const auto& item : items)
{ {
if (m_canceled) if (m_canceled)
{ {
@@ -104,7 +119,7 @@ HRESULT CPowerRenameEnum::_ParseEnumItems(_In_ IEnumShellItems* pesi, _In_ int d
// Failure may be valid if we come across a shell item that does // Failure may be valid if we come across a shell item that does
// not support a file system path. In that case we simply ignore // not support a file system path. In that case we simply ignore
// the item. // the item.
if (SUCCEEDED(spFactory->Create(spsi, &spNewItem))) if (SUCCEEDED(spFactory->Create(item, &spNewItem)))
{ {
spNewItem->PutDepth(depth); spNewItem->PutDepth(depth);
hr = m_spsrm->AddItem(spNewItem); hr = m_spsrm->AddItem(spNewItem);
@@ -115,7 +130,7 @@ HRESULT CPowerRenameEnum::_ParseEnumItems(_In_ IEnumShellItems* pesi, _In_ int d
{ {
// Bind to the IShellItem for the IEnumShellItems interface // Bind to the IShellItem for the IEnumShellItems interface
CComPtr<IEnumShellItems> spesiNext; CComPtr<IEnumShellItems> spesiNext;
hr = spsi->BindToHandler(nullptr, BHID_EnumItems, IID_PPV_ARGS(&spesiNext)); hr = item->BindToHandler(nullptr, BHID_EnumItems, IID_PPV_ARGS(&spesiNext));
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
// Parse the folder contents recursively // Parse the folder contents recursively
@@ -125,8 +140,10 @@ HRESULT CPowerRenameEnum::_ParseEnumItems(_In_ IEnumShellItems* pesi, _In_ int d
} }
} }
} }
if (FAILED(hr))
spsi = nullptr; {
break;
}
} }
} }

View File

@@ -7,6 +7,7 @@
#include <windows.h> #include <windows.h>
// C RunTime Header Files // C RunTime Header Files
#include <algorithm>
#include <cstdlib> #include <cstdlib>
#include <malloc.h> #include <malloc.h>
#include <memory.h> #include <memory.h>