Skip to content

Commit

Permalink
Make up front enumeration progress dialog more responsive by moving t…
Browse files Browse the repository at this point in the history
…o a separate thread
  • Loading branch information
Chris Davis (EDGE) committed Feb 28, 2021
1 parent a6bc2e9 commit 78c7c29
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 174 deletions.
82 changes: 0 additions & 82 deletions SmartRenameLib/SmartRenameEnum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,48 +27,8 @@ IFACEMETHODIMP CSmartRenameEnum::QueryInterface(_In_ REFIID riid, _Outptr_ void*
return QISearch(this, qit, riid, ppv);
}

IFACEMETHODIMP CSmartRenameEnum::Advise(_In_ ISmartRenameEnumEvents* events, _Out_ DWORD* cookie)
{
CSRWExclusiveAutoLock lock(&m_lockEvents);
m_cookie++;
RENAME_ENUM_EVENT srme;
srme.cookie = m_cookie;
srme.pEvents = events;
events->AddRef();
m_renameEnumEvents.push_back(srme);

*cookie = m_cookie;

return S_OK;
}

IFACEMETHODIMP CSmartRenameEnum::UnAdvise(_In_ DWORD cookie)
{
HRESULT hr = E_FAIL;
CSRWExclusiveAutoLock lock(&m_lockEvents);

for (std::vector<RENAME_ENUM_EVENT>::iterator it = m_renameEnumEvents.begin(); it != m_renameEnumEvents.end(); ++it)
{
if (it->cookie == cookie)
{
hr = S_OK;
it->cookie = 0;
if (it->pEvents)
{
it->pEvents->Release();
it->pEvents = nullptr;
}
break;
}
}

return hr;
}


IFACEMETHODIMP CSmartRenameEnum::Start()
{
_OnStarted();
m_canceled = false;
CComPtr<IShellItemArray> spsia;
HRESULT hr = SHCreateShellItemArrayFromDataObject(m_spdo, IID_PPV_ARGS(&spsia));
Expand All @@ -82,7 +42,6 @@ IFACEMETHODIMP CSmartRenameEnum::Start()
}
}

_OnCompleted();
return hr;
}

Expand Down Expand Up @@ -120,46 +79,6 @@ CSmartRenameEnum::~CSmartRenameEnum()
{
}


void CSmartRenameEnum::_OnStarted()
{
CSRWSharedAutoLock lock(&m_lockEvents);

for (std::vector<RENAME_ENUM_EVENT>::iterator it = m_renameEnumEvents.begin(); it != m_renameEnumEvents.end(); ++it)
{
if (it->pEvents)
{
it->pEvents->OnStarted();
}
}
}

void CSmartRenameEnum::_OnCompleted()
{
CSRWSharedAutoLock lock(&m_lockEvents);

for (std::vector<RENAME_ENUM_EVENT>::iterator it = m_renameEnumEvents.begin(); it != m_renameEnumEvents.end(); ++it)
{
if (it->pEvents)
{
it->pEvents->OnCompleted(m_canceled);
}
}
}

void CSmartRenameEnum::_OnFoundItem(_In_ ISmartRenameItem* item)
{
CSRWSharedAutoLock lock(&m_lockEvents);

for (std::vector<RENAME_ENUM_EVENT>::iterator it = m_renameEnumEvents.begin(); it != m_renameEnumEvents.end(); ++it)
{
if (it->pEvents)
{
it->pEvents->OnFoundItem(item);
}
}
}

HRESULT CSmartRenameEnum::_Init(_In_ IDataObject* pdo, _In_ ISmartRenameManager* psrm)
{
m_spdo = pdo;
Expand Down Expand Up @@ -197,7 +116,6 @@ HRESULT CSmartRenameEnum::_ParseEnumItems(_In_ IEnumShellItems* pesi, _In_ int d
if (SUCCEEDED(spsrif->Create(spsi, &spNewItem)))
{
spNewItem->put_depth(depth);
_OnFoundItem(spNewItem);
hr = m_spsrm->AddItem(spNewItem);
if (SUCCEEDED(hr))
{
Expand Down
17 changes: 0 additions & 17 deletions SmartRenameLib/SmartRenameEnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ class CSmartRenameEnum :
IFACEMETHODIMP_(ULONG) Release();

// ISmartRenameEnum
IFACEMETHODIMP Advise(_In_ ISmartRenameEnumEvents* events, _Out_ DWORD* cookie);
IFACEMETHODIMP UnAdvise(_In_ DWORD cookie);
IFACEMETHODIMP Start();
IFACEMETHODIMP Cancel();

Expand All @@ -29,21 +27,6 @@ class CSmartRenameEnum :
HRESULT _Init(_In_ IDataObject* pdo, _In_ ISmartRenameManager* psrm);
HRESULT _ParseEnumItems(_In_ IEnumShellItems* pesi, _In_ int depth = 0);

void _OnStarted();
void _OnCompleted();
void _OnFoundItem(_In_ ISmartRenameItem* item);

struct RENAME_ENUM_EVENT
{
ISmartRenameEnumEvents* pEvents;
DWORD cookie;
};

DWORD m_cookie = 0;

CSRWLock m_lockEvents;
_Guarded_by_(m_lockEvents) std::vector<RENAME_ENUM_EVENT> m_renameEnumEvents;

CComPtr<ISmartRenameManager> m_spsrm;
CComPtr<IDataObject> m_spdo;
bool m_canceled = false;
Expand Down
10 changes: 0 additions & 10 deletions SmartRenameLib/SmartRenameInterfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,9 @@ interface __declspec(uuid("04AAFABE-B76E-4E13-993A-B5941F52B139")) ISmartRenameM
IFACEMETHOD(AddMRUString)(_In_ PCWSTR entry) = 0;
};

interface __declspec(uuid("7ABDE437-7AAF-4545-AA52-EC47A6F428C1")) ISmartRenameEnumEvents : public IUnknown
{
public:
IFACEMETHOD(OnStarted)() = 0;
IFACEMETHOD(OnCompleted)(_In_ bool canceled) = 0;
IFACEMETHOD(OnFoundItem)(_In_ ISmartRenameItem* item) = 0;
};

interface __declspec(uuid("2EFBAB41-A841-47B5-898B-B1CFBF151855")) ISmartRenameEnum : public IUnknown
{
public:
IFACEMETHOD(Advise)(_In_ ISmartRenameEnumEvents* events, _Out_ DWORD* cookie) = 0;
IFACEMETHOD(UnAdvise)(_In_ DWORD cookie) = 0;
IFACEMETHOD(Start)() = 0;
IFACEMETHOD(Cancel)() = 0;
};
Expand Down
Loading

0 comments on commit 78c7c29

Please sign in to comment.