Allow cases without info for a Steam ID

This commit is contained in:
mtkennerly 2023-11-29 21:51:09 +08:00
parent e5a2b9dce9
commit 549bbfbfbe
No known key found for this signature in database
GPG key ID: E764BE00BE6E6408

View file

@ -23,7 +23,9 @@ impl SteamCache {
}); });
for app_id in app_ids { for app_id in app_ids {
let latest = SteamCacheEntry::fetch_from_id(app_id)?; let Some(latest) = SteamCacheEntry::fetch_from_id(app_id)? else {
continue;
};
self.0.insert(app_id.to_string(), latest); self.0.insert(app_id.to_string(), latest);
i += 1; i += 1;
@ -167,7 +169,7 @@ mod product_info {
} }
impl SteamCacheEntry { impl SteamCacheEntry {
pub fn fetch_from_id(app_id: u32) -> Result<Self, Error> { pub fn fetch_from_id(app_id: u32) -> Result<Option<Self>, Error> {
println!("Steam: {}", app_id); println!("Steam: {}", app_id);
let mut cmd = Command::new("python"); let mut cmd = Command::new("python");
@ -182,11 +184,10 @@ impl SteamCacheEntry {
let stdout = String::from_utf8_lossy(&output.stdout); let stdout = String::from_utf8_lossy(&output.stdout);
let response = serde_json::from_str::<product_info::Response>(&stdout).map_err(|_| Error::SteamProductInfo)?; let response = serde_json::from_str::<product_info::Response>(&stdout).map_err(|_| Error::SteamProductInfo)?;
let app = response let Some(app) = response.apps.get(&app_id.to_string()).cloned() else {
.apps eprintln!("No results for Steam ID: {}", app_id);
.get(&app_id.to_string()) return Ok(None);
.ok_or(Error::SteamProductInfo)? };
.clone();
let launch: Vec<_> = app let launch: Vec<_> = app
.config .config
@ -208,11 +209,11 @@ impl SteamCacheEntry {
.filter(|x| !x.is_empty()) .filter(|x| !x.is_empty())
.collect(); .collect();
Ok(Self { Ok(Some(Self {
state: State::Handled, state: State::Handled,
install_dir: app.config.installdir, install_dir: app.config.installdir,
name_localized: app.common.name_localized, name_localized: app.common.name_localized,
launch, launch,
}) }))
} }
} }