diff options
| -rw-r--r-- | src/app.rs | 5 | ||||
| -rw-r--r-- | src/lib.rs | 22 | ||||
| -rw-r--r-- | src/ugc.rs | 22 |
3 files changed, 39 insertions, 10 deletions
@@ -4,6 +4,11 @@ use super::*; #[derive(Clone, Copy, Debug, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct AppId(pub u32); +impl From<u32> for AppId { + fn from(id: u32) -> Self { + AppId(id) + } +} /// Access to the steam apps interface pub struct Apps<Manager> { @@ -119,7 +119,8 @@ impl Client<ClientManager> { /// /// If the game isn't being run through steam this can be provided by /// placing a `steam_appid.txt` with the ID inside in the current - /// working directory + /// working directory. Alternatively, you can use `Client::init_app(<app_id>)` + /// to force a specific app ID. /// * The game isn't running on the same user/level as the steam client /// * The user doesn't own a license for the game. /// * The app ID isn't completely set up. @@ -147,6 +148,25 @@ impl Client<ClientManager> { })) } } + + /// Attempts to initialize the steamworks api **for a specified app ID** + /// and returns a client to access the rest of the api. + /// + /// This should only ever have one instance per a program. + /// + /// # Errors + /// + /// This can fail if: + /// * The steam client isn't running + /// * The game isn't running on the same user/level as the steam client + /// * The user doesn't own a license for the game. + /// * The app ID isn't completely set up. + pub fn init_app<ID: Into<AppId>>(app_id: ID) -> SResult<(Client<ClientManager>, SingleClient<ClientManager>)> { + let app_id = app_id.into().0.to_string(); + std::env::set_var("SteamAppId", &app_id); + std::env::set_var("SteamGameId", app_id); + Client::init() + } } impl <M> SingleClient<M> where M: Manager { /// Runs any currently pending callbacks @@ -299,21 +299,23 @@ bitflags! { pub struct DownloadItemResult { pub app_id: AppId, pub published_file_id: PublishedFileId, + pub error: Option<SteamError>, } -unsafe impl Callback for Result<DownloadItemResult, SteamError> { +unsafe impl Callback for DownloadItemResult { const ID: i32 = CALLBACK_BASE_ID + 6; const SIZE: i32 = ::std::mem::size_of::<sys::DownloadItemResult_t>() as i32; unsafe fn from_raw(raw: *mut c_void) -> Self { let val = &mut *(raw as *mut sys::DownloadItemResult_t); - if val.m_eResult == sys::EResult::k_EResultOK { - Ok(DownloadItemResult { - app_id: AppId(val.m_unAppID), - published_file_id: PublishedFileId(val.m_nPublishedFileId), - }) - } else { - Err(val.m_eResult.into()) + DownloadItemResult { + app_id: AppId(val.m_unAppID), + published_file_id: PublishedFileId(val.m_nPublishedFileId), + + error: match val.m_eResult { + sys::EResult::k_EResultOK => None, + error => Some(error.into()) + } } } } @@ -1253,7 +1255,8 @@ impl<'a> QueryResults<'a> { num_children: raw_details.m_unNumChildren, tags, tags_truncated: raw_details.m_bTagsTruncated, - file_type: raw_details.m_eFileType.into() + file_type: raw_details.m_eFileType.into(), + file_size: raw_details.m_nFileSize.max(0) as u32, }) } } @@ -1354,6 +1357,7 @@ pub struct QueryResult { pub tags: Vec<String>, pub tags_truncated: bool, pub file_type: FileType, + pub file_size: u32, pub url: String, pub num_upvotes: u32, |