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",
]