How to use IStorageProviderItemPropertySource.GetItemProperties method

Peter 1 Reputation point
2022-09-17T01:02:50.657+00:00

Need to fetch the StorageProviderItemProperty on a cloud file, but I don't see any ways to instantiate this class/interface/struct: "IStorageProviderItemPropertySource", do I need to implement anything of my own? Any instructions/documentation/sample code that can help me understand how to use it ?

Windows development | Windows API - Win32
{count} votes

2 answers

Sort by: Most helpful
  1. WithinRafael 326 Reputation points Volunteer Moderator
    2022-09-21T01:23:23.74+00:00

    Hi @Peter ,

    The Windows.Storage APIs generally involve brokered I/O (read: slow) and are mainly still around to support older Universal Windows Platform (UWP) apps. Perhaps the Cloud Filter APIs are more useful to you? If not, can you share a bit more information on what you're trying to do?

    main.rs

       use windows::*;  
       use windows::{  
           core::PCWSTR,  
           Win32::{  
               Foundation::MAX_PATH,  
               Storage::CloudFilters::{  
                   CfGetPlaceholderInfo, CfOpenFileWithOplock, CF_OPEN_FILE_FLAG_NONE,  
                   CF_PLACEHOLDER_INFO_STANDARD, CF_PLACEHOLDER_STANDARD_INFO,  
               },  
               System::Environment::ExpandEnvironmentStringsW,  
           },  
       };  
         
       fn main() -> windows::core::Result<()> {  
           unsafe {  
               let mut path = [0; MAX_PATH as usize];  
               ExpandEnvironmentStringsW(w!(r#"%OneDriveConsumer%\example.txt"#), Some(&mut path));  
         
               let handle = CfOpenFileWithOplock(PCWSTR::from_raw(&path as _), CF_OPEN_FILE_FLAG_NONE)?;  
         
               let mut buffer = [0u8; 2048];  
               CfGetPlaceholderInfo(handle, CF_PLACEHOLDER_INFO_STANDARD, &mut buffer, None)?;  
         
               let basic_info: CF_PLACEHOLDER_STANDARD_INFO = std::ptr::read(buffer.as_ptr() as *const _);  
         
               // Total number of bytes on disk.  
               println!("OnDiskDataSize (bytes): {}", basic_info.OnDiskDataSize);  
         
               // Total number of bytes that have been overwritten/appended locally that are not in sync with the cloud.  
               println!("ModifiedDataSize (bytes): {}", basic_info.ModifiedDataSize);  
         
               // Total number of bytes in sync with the cloud.  
               println!(  
                   "ValidatedDataSize (bytes): {}",  
                   basic_info.ValidatedDataSize  
               );  
           }  
         
           Ok(())  
       }  
    

    Cargo.toml

       [package]  
       name = "app"  
       version = "0.0.0"  
       edition = "2018"  
       publish = false  
         
       [dependencies.windows]  
       version = "0.40.0"  
       features = [  
           "Win32_Foundation",  
           "Win32_Storage_CloudFilters",  
           "Win32_System_Environment",  
       ]  
    

  2. Peter 1 Reputation point
    2022-10-05T21:40:53.217+00:00

    Hello @WithinRafael

    The placeholder info returned by Cloud Filter APIs doesn't contain the custom property I expect, what I want to is to fetch the custom property of a storage item being set by the SetAsync api here. Use cases like: I want to verify if SetAsync is done correctly, build logics around different states.
    So I am wondering that: is "IStorageProviderItemPropertySource.GetItemProperties" the one I should use or there are some other ways? What're some code samples/instructions?

    Thanks

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.