diff --git a/src/main.rs b/src/main.rs index 5bedbba..5049b85 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ use indexmap::IndexMap; use log::{error, info, LevelFilter}; use serde_derive::Deserialize; use simple_logger::SimpleLogger; +use std::io; use std::io::Error; #[cfg(target_os = "windows")] use std::io::ErrorKind; @@ -110,7 +111,7 @@ fn main() { let path = lol_champs_dir.join(&champ_id).join("Recommended"); fs::create_dir_all(&path).unwrap(); if positions.is_empty() { - error!("{} missing positions", &champ_id); + error!("{} missing positions", &champ_id); } for pos in positions { data_source.write_item_set( @@ -140,21 +141,56 @@ fn get_champ_from_key(champs: &Champion, key: &str) -> String { #[cfg(target_os = "windows")] fn lol_champ_dir() -> Result { - let hklm = RegKey::predef(winreg::enums::HKEY_CURRENT_USER); - let mut node = hklm.open_subkey(r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\")?; + let hklm = RegKey::predef(winreg::enums::HKEY_LOCAL_MACHINE); - let key = node - .enum_keys() - .map(|x| x.unwrap()) - .find(|x| x == "Riot Game league_of_legends.live"); - - if key == None { - return Err(Error::new(ErrorKind::NotFound, "")); + let node = hklm.open_subkey(r"SOFTWARE\WOW6432Node\Riot Games\RADS"); + if node.is_ok() { + let val: String = node?.get_value("LocalRootFolder")?; + return Ok(PathBuf::from(val).parent().unwrap().to_path_buf()); + } else { + let node = hklm.open_subkey(r"SOFTWARE\WOW6432Node\Riot Games, Inc\League of Legends"); + if node.is_ok() { + let val: String = node?.get_value("Location")?; + return Ok(PathBuf::from(val)); + } } - node = node.open_subkey(key.unwrap())?; - let val: String = node.get_value("InstallLocation")?; - Ok(PathBuf::from(val).join("Config").join("Champions")) + let node = hklm.open_subkey(r"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall"); + let mut sub_node: io::Result = Err(Error::from(ErrorKind::NotFound)); + + if node.is_ok() { + let n = node.unwrap(); + let key = n + .enum_keys() + .map(|x| x.unwrap()) + .find(|x| x.starts_with("League of Legends")); + if key.is_some() { + sub_node = n.open_subkey(key.unwrap()); + } + } + + if sub_node.is_err() { + let hkcu = RegKey::predef(winreg::enums::HKEY_CURRENT_USER); + let node = hkcu.open_subkey(r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"); + if node.is_ok() { + let n = node.unwrap(); + let key = n + .enum_keys() + .map(|x| x.unwrap()) + .find(|x| x == "Riot Game league_of_legends.live"); + if key.is_some() { + sub_node = n.open_subkey(key.unwrap()); + } + } + } + + if sub_node.is_ok() { + let val: String = sub_node?.get_value("InstallLocation")?; + return Ok(PathBuf::from(val).join("Config").join("Champions")); + } + + + Err(Error::from(ErrorKind::NotFound)) } #[cfg(not(target_os = "windows"))]