【发布时间】:2021-04-15 10:13:04
【问题描述】:
我尝试将使用 CFAPI 创建的占位符文件的状态图标设置为错误。 (见下文)
我在文件上设置了错误状态,但它没有显示错误。但是错误会显示在包含的文件夹中。
我使用以下代码对文件设置错误(完整代码发布在github):
void SetTransferStatus(_In_ PCWSTR fullPath, _In_ SYNC_TRANSFER_STATUS status)
{
// Tell the Shell so File Explorer can display the progress bar in its view
try
{
// First, get the Volatile property store for the file. That's where the properties are maintained.
winrt::com_ptr<IShellItem2> shellItem;
winrt::check_hresult(SHCreateItemFromParsingName(fullPath, nullptr, __uuidof(shellItem), shellItem.put_void()));
winrt::com_ptr<IPropertyStore> propStoreVolatile;
winrt::check_hresult(
shellItem->GetPropertyStore(
GETPROPERTYSTOREFLAGS::GPS_READWRITE | GETPROPERTYSTOREFLAGS::GPS_VOLATILEPROPERTIESONLY,
__uuidof(propStoreVolatile),
propStoreVolatile.put_void()));
// Set the sync transfer status accordingly
PROPVARIANT transferStatus;
winrt::check_hresult(
InitPropVariantFromUInt32(
status,
&transferStatus));
winrt::check_hresult(propStoreVolatile->SetValue(PKEY_SyncTransferStatus, transferStatus));
// Without this, all your hard work is wasted.
winrt::check_hresult(propStoreVolatile->Commit());
// Broadcast a notification that something about the file has changed, so that apps
// who subscribe (such as File Explorer) can update their UI to reflect the new progress
SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH, static_cast<LPCVOID>(fullPath), nullptr);
//wprintf(L"Succesfully Set Transfer Progress on \"%s\" to %llu/%llu\n", fullPath, completed, total);
}
catch (...)
{
// winrt::to_hresult() will eat the exception if it is a result of winrt::check_hresult,
// otherwise the exception will get rethrown and this method will crash out as it should
wprintf(L"Failed to Set Transfer Progress on \"%s\" with %08x\n", fullPath, static_cast<HRESULT>(winrt::to_hresult()));
}
}
此外,如果我删除文件并创建一个新文件,状态仍然会出错。
【问题讨论】:
-
嗨,我现在可以重现此问题。我会与内部工程师确认,如果有任何更新,请在此处回复。感谢您的理解。
-
您好,您能解释一下为什么
IPropertyStore::SetValue函数会设置状态。我认为这是问题的原因。我想你可以参考official sample来实现你的需求。 -
@SongZhu-MSFT 我对那个链接很感兴趣,但它似乎被破坏了:(页面底部显示
Error:null|403 -
抱歉,是我造成的错误。可以参考:CloudMirror
-
@SongZhu-MSFT 感谢我的项目基于示例。但是错误状态的设置不在示例中。您可以设置其他图标,但不能将第一个图标设置为错误状态。我想我在示例中没有看到这样的代码
标签: c++ windows winapi minifilter