-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show progress dialog during startup (#9255)
* Show progress dialog during startup for selection enumeration that can take a long time. * Updated with better code organization and a timer to ensure the progress dialog does not appear in most cases. * Update based on PR feedback * Change progress dialog delay from 1500ms to 2500ms * Move progress dialog invocation off the main UI thread Co-authored-by: Chris Davis (EDGE) <chrdavis@microsoft.com>
- Loading branch information
Showing
12 changed files
with
463 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
#include "pch.h" | ||
#include "PowerRenameEnum.h" | ||
#include <ShlGuid.h> | ||
#include <helpers.h> | ||
|
||
IFACEMETHODIMP_(ULONG) CPowerRenameEnum::AddRef() | ||
{ | ||
return InterlockedIncrement(&m_refCount); | ||
} | ||
|
||
IFACEMETHODIMP_(ULONG) CPowerRenameEnum::Release() | ||
{ | ||
long refCount = InterlockedDecrement(&m_refCount); | ||
|
||
if (refCount == 0) | ||
{ | ||
delete this; | ||
} | ||
return refCount; | ||
} | ||
|
||
IFACEMETHODIMP CPowerRenameEnum::QueryInterface(_In_ REFIID riid, _Outptr_ void** ppv) | ||
{ | ||
static const QITAB qit[] = { | ||
QITABENT(CPowerRenameEnum, IPowerRenameEnum), | ||
{ 0 } | ||
}; | ||
return QISearch(this, qit, riid, ppv); | ||
} | ||
|
||
IFACEMETHODIMP CPowerRenameEnum::Start() | ||
{ | ||
m_canceled = false; | ||
CComPtr<IShellItemArray> spsia; | ||
HRESULT hr = GetShellItemArrayFromDataObject(m_spdo, &spsia); | ||
if (SUCCEEDED(hr)) | ||
{ | ||
CComPtr<IEnumShellItems> spesi; | ||
hr = spsia->EnumItems(&spesi); | ||
if (SUCCEEDED(hr)) | ||
{ | ||
hr = _ParseEnumItems(spesi); | ||
} | ||
} | ||
|
||
return hr; | ||
} | ||
|
||
IFACEMETHODIMP CPowerRenameEnum::Cancel() | ||
{ | ||
m_canceled = true; | ||
return S_OK; | ||
} | ||
|
||
HRESULT CPowerRenameEnum::s_CreateInstance(_In_ IUnknown* pdo, _In_ IPowerRenameManager* pManager, _In_ REFIID iid, _Outptr_ void** resultInterface) | ||
{ | ||
*resultInterface = nullptr; | ||
|
||
CPowerRenameEnum* newRenameEnum = new CPowerRenameEnum(); | ||
HRESULT hr = newRenameEnum ? S_OK : E_OUTOFMEMORY; | ||
if (SUCCEEDED(hr)) | ||
{ | ||
hr = newRenameEnum->_Init(pdo, pManager); | ||
if (SUCCEEDED(hr)) | ||
{ | ||
hr = newRenameEnum->QueryInterface(iid, resultInterface); | ||
} | ||
|
||
newRenameEnum->Release(); | ||
} | ||
return hr; | ||
} | ||
|
||
CPowerRenameEnum::CPowerRenameEnum() : | ||
m_refCount(1) | ||
{ | ||
} | ||
|
||
CPowerRenameEnum::~CPowerRenameEnum() | ||
{ | ||
} | ||
|
||
HRESULT CPowerRenameEnum::_Init(_In_ IUnknown* pdo, _In_ IPowerRenameManager* pManager) | ||
{ | ||
m_spdo = pdo; | ||
m_spsrm = pManager; | ||
return S_OK; | ||
} | ||
|
||
HRESULT CPowerRenameEnum::_ParseEnumItems(_In_ IEnumShellItems* pesi, _In_ int depth) | ||
{ | ||
HRESULT hr = E_INVALIDARG; | ||
|
||
// We shouldn't get this deep since we only enum the contents of | ||
// regular folders but adding just in case | ||
if ((pesi) && (depth < (MAX_PATH / 2))) | ||
{ | ||
hr = S_OK; | ||
|
||
ULONG celtFetched; | ||
CComPtr<IShellItem> spsi; | ||
while ((S_OK == pesi->Next(1, &spsi, &celtFetched)) && (SUCCEEDED(hr))) | ||
{ | ||
if (m_canceled) | ||
{ | ||
return E_ABORT; | ||
} | ||
|
||
CComPtr<IPowerRenameItemFactory> spFactory; | ||
hr = m_spsrm->GetRenameItemFactory(&spFactory); | ||
if (SUCCEEDED(hr)) | ||
{ | ||
CComPtr<IPowerRenameItem> spNewItem; | ||
// 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))) | ||
{ | ||
spNewItem->PutDepth(depth); | ||
hr = m_spsrm->AddItem(spNewItem); | ||
if (SUCCEEDED(hr)) | ||
{ | ||
bool isFolder = false; | ||
if (SUCCEEDED(spNewItem->GetIsFolder(&isFolder)) && isFolder) | ||
{ | ||
// Bind to the IShellItem for the IEnumShellItems interface | ||
CComPtr<IEnumShellItems> spesiNext; | ||
hr = spsi->BindToHandler(nullptr, BHID_EnumItems, IID_PPV_ARGS(&spesiNext)); | ||
if (SUCCEEDED(hr)) | ||
{ | ||
// Parse the folder contents recursively | ||
hr = _ParseEnumItems(spesiNext, depth + 1); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
spsi = nullptr; | ||
} | ||
} | ||
|
||
return hr; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#pragma once | ||
#include "pch.h" | ||
#include "PowerRenameInterfaces.h" | ||
#include <vector> | ||
#include "srwlock.h" | ||
|
||
class CPowerRenameEnum : | ||
public IPowerRenameEnum | ||
{ | ||
public: | ||
// IUnknown | ||
IFACEMETHODIMP QueryInterface(_In_ REFIID iid, _Outptr_ void** resultInterface); | ||
IFACEMETHODIMP_(ULONG) AddRef(); | ||
IFACEMETHODIMP_(ULONG) Release(); | ||
|
||
// ISmartRenameEnum | ||
IFACEMETHODIMP Start(); | ||
IFACEMETHODIMP Cancel(); | ||
|
||
public: | ||
static HRESULT s_CreateInstance(_In_ IUnknown* pdo, _In_ IPowerRenameManager* pManager, _In_ REFIID iid, _Outptr_ void** resultInterface); | ||
|
||
protected: | ||
CPowerRenameEnum(); | ||
virtual ~CPowerRenameEnum(); | ||
|
||
HRESULT _Init(_In_ IUnknown* pdo, _In_ IPowerRenameManager* pManager); | ||
HRESULT _ParseEnumItems(_In_ IEnumShellItems* pesi, _In_ int depth = 0); | ||
|
||
CComPtr<IPowerRenameManager> m_spsrm; | ||
CComPtr<IUnknown> m_spdo; | ||
bool m_canceled = false; | ||
long m_refCount = 0; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
d128939
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Misspellings found, please review:
To accept these changes, run the following commands from this repository on this branch