[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
CMock
CMONITORS
cmp
cmyk
cnt
coclass
@@ -1764,6 +1765,7 @@ SHOWNOACTIVATE
SHOWNORMAL
SHOWWINDOW
shtypes
SICHINT
sid
siex
SIGABRT

View File

@@ -89,7 +89,22 @@ HRESULT CPowerRenameEnum::_ParseEnumItems(_In_ IEnumShellItems* pesi, _In_ int d
ULONG celtFetched;
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)
{
@@ -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
// not support a file system path. In that case we simply ignore
// the item.
if (SUCCEEDED(spFactory->Create(spsi, &spNewItem)))
if (SUCCEEDED(spFactory->Create(item, &spNewItem)))
{
spNewItem->PutDepth(depth);
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
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))
{
// Parse the folder contents recursively
@@ -125,8 +140,10 @@ HRESULT CPowerRenameEnum::_ParseEnumItems(_In_ IEnumShellItems* pesi, _In_ int d
}
}
}
spsi = nullptr;
if (FAILED(hr))
{
break;
}
}
}

View File

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