Search code examples
c++winapifilesystemsc++-winrt

How can be shown the placeholder sync icon in a renamed folder using Win32 Cloud Filter API?


I'm using the Microsoft Cloud Filter API to manage placeholders in my local directory, and when I rename a folder its state icon isn't visually updated after I apply the CfSetInSyncState function to this folder. This folder contains a file that was previously copied from another placeholder from this cloned directory. I've applied several functions besides CfSetInSyncState as CfUpdatePlaceholder, CfSetPinState, CfRevertPlaceholder and CfConvertToPlaceholder to the folder but the sync icon isn't shown properly and I checked that the placeholder has the CF_PLACEHOLDER_STATE_IN_SYNC state. Is there some way to set the sync icon properly in this case?

Sync state icon correctly shown before rename a folder.

Sync state icon correctly shown after sync the renamed folder.

Sync state icon isn't visually updated after sync a renamed folder.

Sync state icon isn't visually updated after sync the renamed folder.


Solution

  • I could show the placeholder sync icon correctly in this case renaming the folder twice using MoveFileW and CfUpdatePlaceholder functions. Here I show you the method that renames the folder twice.

    bool FolderRenameTrick(const std::wstring& folderPath)
    {
        // Gets a nonexistent folder path
        std::wstring folderPathAux = GenerateAuxPath(folderPath);
    
        if (folderPathAux != L"")
        {
            bool renamed = false;
            
            // Renames the folder with MoveFileW method (auxiliary folder)
            if (MoveFile(folderPath.c_str(), folderPathAux.c_str())) 
            {
                // UpdatePlaceholder calls internally to CfUpdatePlaceholder (auxiliary folder)
                if (UpdatePlaceholder(folderPathAux)) 
                {
                    renamed = true;
                }
            }
    
            if (renamed)
            {
                // Renames the folder with MoveFileW method (correct folder)
                if (MoveFile(folderPathAux.c_str(), folderPath.c_str()))
                {
                    // UpdatePlaceholder calls internally to CfUpdatePlaceholder (correct folder)
                    if (UpdatePlaceholder(folderPath))
                    {
                        return true;
                    }
                }
            }
        }
    
        return false;
    }