diff options
| author | William Venner <[email protected]> | 2021-04-24 00:07:17 +0100 |
|---|---|---|
| committer | William Venner <[email protected]> | 2021-04-24 00:07:17 +0100 |
| commit | a33ebe97165c4e19cd2d553350afd2487b6d8ec4 (patch) | |
| tree | cad873a4d0d826ef52a857c16a3fe53a40e3885c | |
| parent | Add safe wrapper for sys::SteamParamStringArray_t (diff) | |
| download | steamworks-rs-a33ebe97165c4e19cd2d553350afd2487b6d8ec4.tar.xz steamworks-rs-a33ebe97165c4e19cd2d553350afd2487b6d8ec4.zip | |
Add more UGC bindings
| -rw-r--r-- | src/ugc.rs | 79 |
1 files changed, 79 insertions, 0 deletions
@@ -543,6 +543,26 @@ impl <Manager> UGC<Manager> { handle: Some(res), }) } + + /// **DELETES** the item from the Steam Workshop. + pub fn delete_item<F>(&self, published_file_id: PublishedFileId, cb: F) + where F: FnOnce(Result<(), SteamError>) + 'static + Send + { + unsafe { + let api_call = sys::SteamAPI_ISteamUGC_DeleteItem(self.ugc, published_file_id.0); + register_call_result::<sys::DownloadItemResult_t, _, _>( + &self.inner, api_call, CALLBACK_REMOTE_STORAGE_BASE_ID + 17, + move |v, io_error| { + cb(if io_error { + Err(SteamError::IOFailure) + } else if v.m_eResult != sys::EResult::k_EResultNone && v.m_eResult != sys::EResult::k_EResultOK { + Err(v.m_eResult.into()) + } else { + Ok(()) + }) + }); + } + } } /// A handle to update a published item @@ -592,6 +612,14 @@ impl <Manager> UpdateHandle<Manager> { self } + pub fn tags<S: AsRef<str>>(self, tags: Vec<S>) -> Self { + unsafe { + let mut tags = SteamParamStringArray::new(&tags); + assert!(sys::SteamAPI_ISteamUGC_SetItemTags(self.ugc, self.handle, &tags.as_raw())); + } + self + } + pub fn submit<F>(self, change_note: Option<&str>, cb: F) -> UpdateWatchHandle<Manager> where F: FnOnce(Result<(PublishedFileId, bool), SteamError>) + 'static + Send { @@ -1237,6 +1265,57 @@ impl<'a> QueryResults<'a> { None } } + + /// Returns the number of key value tags associated with the item at the specified index. + pub fn key_value_tags(&self, index: u32) -> u32 { + unsafe { sys::SteamAPI_ISteamUGC_GetQueryUGCNumKeyValueTags(self.ugc, self.handle, index) } + } + + /// Gets the key value pair of a specified key value tag associated with the item at the specified index. + pub fn get_key_value_tag(&self, index: u32, kv_tag_index: u32) -> Option<(String, String)> { + let mut key = [0 as c_char; 256]; + let mut value = [0 as c_char; 256]; + + let ok = unsafe { + sys::SteamAPI_ISteamUGC_GetQueryUGCKeyValueTag(self.ugc, self.handle, index, kv_tag_index, key.as_mut_ptr(), 256, value.as_mut_ptr(), 256) + }; + + if ok { + Some(unsafe {( + CStr::from_ptr(key.as_ptr() as *const _) + .to_string_lossy() + .into_owned(), + + CStr::from_ptr(value.as_ptr() as *const _) + .to_string_lossy() + .into_owned() + )}) + } else { + None + } + } + + /// Gets the developer-set metadata associated with the item at the specified index. + /// + /// This is returned as a vector of raw bytes. + pub fn get_metadata(&self, index: u32) -> Option<Vec<u8>> { + let mut metadata = [0 as c_char; sys::k_cchDeveloperMetadataMax as usize]; + + let ok = unsafe { + sys::SteamAPI_ISteamUGC_GetQueryUGCMetadata(self.ugc, self.handle, index, metadata.as_mut_ptr(), sys::k_cchDeveloperMetadataMax) + }; + + if ok { + let metadata = unsafe { CStr::from_ptr(metadata.as_ptr() as *const _).to_bytes() }; + if metadata.is_empty() { + None + } else { + Some(metadata.to_vec()) + } + } else { + None + } + } } /// Query result |