Search code examples
windows-runtimeiconscloudstoragec++-winrt

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


In relation to the blocked question at 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()));
    }
}

I prefer asking here instead of MSDN forums due to compulsory advertisement consent attached to their forum usage.


Solution

    1. There is an open PR demoing how to set the error icon using PKEY_LastSyncError.

    2. After asked the question on MSDN forums(which seems I can't reply anymore), I found another way to achieve this: call CfSetPinState on the target file and pass in CF_PIN_STATE_EXCLUDED, this will exclude the file from syncing thus remove the existing icon, then apply your custom state on that file, there should be only your custom icon on the file now.