同步根文件夹中的云存储状态图标 *替换*

Cloud Storage state icons *replacement* inside the Sync Root folder

关于 https://social.msdn.microsoft.com/Forums/SECURITY/ro-RO/74b81550-f2d9-47f5-af03-a44585119832/how-to-change-a-cloud-file-placeholders-status-icon?forum=windowssdk

处被屏蔽的问题
A call to ApplyCustomStateToPlaceholderFile() will set a new icon next to the existing one
It does not replace an existing icon. Can we set a new custom icon, so there is only one icon is displayed?
void Utilities::ApplyCustomStateToPlaceholderFile(PCWSTR path, PCWSTR filename, winrt::StorageProviderItemProperty& prop)
{
    try
    {
        std::wstring fullPath(path);
        fullPath.append(L"\");
        fullPath.append(filename);

        auto customProperties{ winrt::single_threaded_vector<winrt::StorageProviderItemProperty>() };
        customProperties.Append(prop);
    
        winrt::IStorageItem item = winrt::StorageFile::GetFileFromPathAsync(fullPath).get();
        winrt::StorageProviderItemProperties::SetAsync(item, customProperties).get();
    }
    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 custom state with %08x\n", static_cast<HRESULT>(winrt::to_hresult()));
    }
}

我更喜欢在这里提问而不是 MSDN 论坛,因为他们的论坛使用附带强制广告许可。

  1. 有一个 open PR 演示如何使用 PKEY_LastSyncError 设置错误图标。

  2. 在MSDN论坛上问了这个问题(好像不能再回复了),我找到了另一种实现方式: 在目标文件上调用 CfSetPinState 并传入 CF_PIN_STATE_EXCLUDED,这会将文件从同步中排除,从而删除现有图标,然后在该文件上应用您的自定义状态,应该只有您的自定义图标立即归档。