aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaro Perämaa <[email protected]>2021-05-03 12:08:14 +0300
committerGitHub <[email protected]>2021-05-03 12:08:14 +0300
commit29e401de5d1f4d267e46faf0f0f03f540437bcc0 (patch)
treed7e0f98d6ede7f1e7b147ef0a796f2f86728f972
parentMerge pull request #46 from WilliamVenner/download_item_result_pr (diff)
parentAdd missing SteamAPI_ISteamUGC_SetReturnKeyValueTags (diff)
downloadsteamworks-rs-29e401de5d1f4d267e46faf0f0f03f540437bcc0.tar.xz
steamworks-rs-29e401de5d1f4d267e46faf0f0f03f540437bcc0.zip
Merge pull request #49 from WilliamVenner/more_ugc_bindings
More UGC bindings
-rw-r--r--src/ugc.rs97
-rw-r--r--src/utils.rs21
2 files changed, 118 insertions, 0 deletions
diff --git a/src/ugc.rs b/src/ugc.rs
index c317d76..d98bf8a 100644
--- a/src/ugc.rs
+++ b/src/ugc.rs
@@ -545,6 +545,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
@@ -594,6 +614,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
{
@@ -777,6 +805,15 @@ impl <Manager> UserListQuery<Manager> {
self
}
+ /// Include key value tags in results
+ pub fn include_key_value_tags(self, include: bool) -> Self {
+ let ok = unsafe {
+ sys::SteamAPI_ISteamUGC_SetReturnKeyValueTags(self.ugc, self.handle.unwrap(), include)
+ };
+ debug_assert!(ok);
+ self
+ }
+
/// Runs the query
pub fn fetch<F>(mut self, cb: F)
where F: for<'a> FnOnce(Result<QueryResults<'a>,SteamError>) + 'static + Send
@@ -928,6 +965,15 @@ impl <Manager> ItemListDetailsQuery<Manager> {
self
}
+ /// Include key value tags in results
+ pub fn include_key_value_tags(self, include: bool) -> Self {
+ let ok = unsafe {
+ sys::SteamAPI_ISteamUGC_SetReturnKeyValueTags(self.ugc, self.handle.unwrap(), include)
+ };
+ debug_assert!(ok);
+ self
+ }
+
/// Runs the query
pub fn fetch<F>(mut self, cb: F)
where F: for<'a> FnOnce(Result<QueryResults<'a>,SteamError>) + 'static + Send
@@ -1240,6 +1286,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
diff --git a/src/utils.rs b/src/utils.rs
index 5120f40..5b853ab 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -100,3 +100,24 @@ impl <Manager> Utils<Manager> {
}
}
}
+
+pub(crate) struct SteamParamStringArray(Vec<*mut i8>);
+impl Drop for SteamParamStringArray {
+ fn drop(&mut self) {
+ for c_string in &self.0 {
+ unsafe { CString::from_raw(*c_string) };
+ }
+ }
+}
+impl SteamParamStringArray {
+ pub(crate) fn new<S: AsRef<str>>(vec: &[S]) -> SteamParamStringArray {
+ SteamParamStringArray(vec.into_iter().map(|s| CString::new(s.as_ref()).expect("String passed could not be converted to a c string").into_raw()).collect())
+ }
+
+ pub(crate) fn as_raw(&mut self) -> sys::SteamParamStringArray_t {
+ sys::SteamParamStringArray_t {
+ m_nNumStrings: self.0.len() as i32,
+ m_ppStrings: self.0.as_mut_ptr() as *mut *const i8
+ }
+ }
+}