diff --git a/src/main.rs b/src/main.rs index e819c64..987f726 100644 --- a/src/main.rs +++ b/src/main.rs @@ -57,7 +57,10 @@ fn main() -> Result<(), Box> { Ok(x) => x, Err(_e) => PathBuf::from(LOL_CHAMPS_DIR), }; - info!("LoL Champs Folder: {}", lol_champs_dir.to_str().unwrap_or(LOL_CHAMPS_DIR)); + info!( + "LoL Champs Folder: {}", + lol_champs_dir.to_str().unwrap_or(LOL_CHAMPS_DIR) + ); let client = ureq::AgentBuilder::new() .timeout(Duration::from_secs(10)) @@ -97,27 +100,24 @@ fn main() -> Result<(), Box> { ); for (id, positions) in &champs { - let mut champ_id: String = id.to_owned(); + let mut champ_id = id.to_owned(); if !champion.data.contains_key(&champ_id) { - champ_id = get_champ_from_key(&champion, &champ_id); + if let Some(c_id) = get_champ_from_key(&champion, &champ_id) { + champ_id = c_id; + } } - if champion.data.contains_key(&champ_id) { - let path = lol_champs_dir.join(&champ_id).join("Recommended"); - fs::create_dir_all(&path).unwrap(); + if let Some(champ) = champion.data.get(&champ_id) { if positions.is_empty() { error!("{} missing positions", &champ_id); - } - for pos in positions { - data_source.write_item_set( - &champion.data.get(&champ_id).unwrap(), - &pos, - &patch, - &path, - &client, - ); - thread::sleep(Duration::from_millis(data_source.get_timeout())); + } else { + let path = lol_champs_dir.join(&champ_id).join("Recommended"); + fs::create_dir_all(&path)?; + for pos in positions { + data_source.write_item_set(&champ, &pos, &patch, &path, &client); + thread::sleep(Duration::from_millis(data_source.get_timeout())); + } } } else { error!("{} not found in LoL champs", &champ_id); @@ -127,13 +127,13 @@ fn main() -> Result<(), Box> { Ok(()) } -fn get_champ_from_key(champs: &Champion, key: &str) -> String { +fn get_champ_from_key(champs: &Champion, key: &str) -> Option { for champ in champs.data.values() { if key == champ.key { - return champ.id.to_owned(); + return Some(champ.id.to_owned()); } } - String::new() + None } #[cfg(target_os = "windows")]