pub struct Object { /* private fields */ }
Implementations§
Source§impl Object
impl Object
pub fn new( device_content: Content, id: U16CString, name: U16CString, ty: ObjectType, ) -> Self
pub fn id(&self) -> &U16CStr
pub fn name(&self) -> &U16CStr
pub fn object_type(&self) -> ObjectType
Sourcepub fn properties(
&self,
properties_to_fetch: &[PROPERTYKEY],
) -> WindowsResult<DeviceValues>
pub fn properties( &self, properties_to_fetch: &[PROPERTYKEY], ) -> WindowsResult<DeviceValues>
Get a list of requested metadata about an object.
pub fn parent_id(&self) -> WindowsResult<U16CString>
Sourcepub fn children(&self) -> WindowsResult<ObjectIterator<'_>>
pub fn children(&self) -> WindowsResult<ObjectIterator<'_>>
Returns an iterator to list every children of the current object (including sub-folders)
Examples found in repository?
24fn show_content(basic_device: &BasicDevice) -> Result<(), Box<dyn Error>> {
25 let app_ident = winmtp::make_current_app_identifiers!();
26
27 let device = basic_device.open(&app_ident, true)?;
28 let content = device.content()?;
29
30 let root_obj = content.root()?;
31 println!("root: {:?}", root_obj);
32
33 for child in root_obj.children()? {
34 println!(" * {:?}", child);
35 }
36 Ok(())
37}
Sourcepub fn sub_folders(&self) -> WindowsResult<impl Iterator<Item = Object> + '_>
pub fn sub_folders(&self) -> WindowsResult<impl Iterator<Item = Object> + '_>
Returns an iterator that only lists folders within this object
Sourcepub fn object_by_path(
&self,
relative_path: &Path,
) -> Result<Object, ItemByPathError>
pub fn object_by_path( &self, relative_path: &Path, ) -> Result<Object, ItemByPathError>
Retrieve an item by its path
This function looks for a sub-item with the right name, then iteratively does so for the matching child.
This is quite expensive. Depending on your use-cases, you may want to cache some “parent folders” that you will want to access often.
Note that caching however defeats the purpose of MTP, which is supposed to not use any cache, so that it guarantees there is no race between concurrent accesses to the same medium.
Sourcepub fn open_raw_stream(
&self,
stream_mode: STGM,
) -> Result<(IStream, u32), OpenStreamError>
pub fn open_raw_stream( &self, stream_mode: STGM, ) -> Result<(IStream, u32), OpenStreamError>
Opens a COM IStream
to this object.
An error will be returned if the required operation does not make sense (e.g. get a stream to a folder).
Also returns the optimal transfer buffer size (in bytes) for this transfer, as stated by the Microsoft API.
See also Self::open_read_stream
.
Sourcepub fn open_read_stream(&self) -> Result<BufReader<ReadStream>, OpenStreamError>
pub fn open_read_stream(&self) -> Result<BufReader<ReadStream>, OpenStreamError>
The same as Self::open_raw_stream
, but wrapped into a crate::io::ReadStream
for more added Rust magic.
§Example
let object = device.content().unwrap().object_by_id(some_id).unwrap();
let mut input_stream = object.open_read_stream().unwrap();
let mut output_file = std::fs::File::create("pulled-from-device.dat").unwrap();
std::io::copy(&mut input_stream, &mut output_file).unwrap();
Sourcepub fn create_subfolder(
&self,
folder_name: &OsStr,
) -> Result<U16CString, CreateFolderError>
pub fn create_subfolder( &self, folder_name: &OsStr, ) -> Result<U16CString, CreateFolderError>
Create a subfolder, and return its object ID
If a folder with the same name already exists (“same name” depends on the chosen case-folding mode), an CreateFolderError::AlreadyExists
error will be returned.
See also Self::create_subfolder_recursive
Sourcepub fn create_subfolder_recursive(
&self,
folder_path: &Path,
) -> Result<(), CreateFolderError>
pub fn create_subfolder_recursive( &self, folder_path: &Path, ) -> Result<(), CreateFolderError>
Create a path of folders, creating intermediate folders if needed
Sourcepub fn push_file(
&self,
local_file: &Path,
allow_overwrite: bool,
) -> Result<(), AddFileError>
pub fn push_file( &self, local_file: &Path, allow_overwrite: bool, ) -> Result<(), AddFileError>
Add a file into the current directory
Sourcepub fn push_data(
&self,
file_name: &OsStr,
data: &[u8],
allow_overwrite: bool,
) -> Result<(), AddFileError>
pub fn push_data( &self, file_name: &OsStr, data: &[u8], allow_overwrite: bool, ) -> Result<(), AddFileError>
Add a file into the current directory
Sourcepub fn delete(&mut self, recursive: bool) -> WindowsResult<()>
pub fn delete(&mut self, recursive: bool) -> WindowsResult<()>
Delete an object
If this is a folder, you must set recursive
to true
, otherwise this would return an error.
Sourcepub fn move_to(&mut self, new_folder_id: &U16CStr) -> WindowsResult<()>
pub fn move_to(&mut self, new_folder_id: &U16CStr) -> WindowsResult<()>
Move an object that is already on the device to a new folder