Fix reg key

This commit is contained in:
nyyu 2021-03-14 09:23:54 +01:00
parent 215f922020
commit b8b6d78951

View file

@ -137,39 +137,24 @@ fn get_champ_from_key(champs: &Champion, key: &String) -> String {
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
fn lol_champ_dir() -> Result<PathBuf, Error> { fn lol_champ_dir() -> Result<PathBuf, Error> {
let hklm = RegKey::predef(winreg::enums::HKEY_LOCAL_MACHINE); let hklm = RegKey::predef(winreg::enums::HKEY_CURRENT_USER);
let node = hklm.open_subkey(r"SOFTWARE\WOW6432Node\Riot Games\RADS"); let mut node = hklm.open_subkey(r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\")?;
let path: PathBuf;
if node.is_ok() {
let val: String = node?.get_value("LocalRootFolder")?;
path = 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")?;
path = PathBuf::from(val);
} else {
let mut node = hklm
.open_subkey(r"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall")?;
let key = node let key = node
.enum_keys() .enum_keys()
.map(|x| x.unwrap()) .map(|x| x.unwrap())
.find(|x| x.starts_with("League of Legends")); .find(|x| x == "Riot Game league_of_legends.live");
if key == None { if key == None {
return Err(Error::new(ErrorKind::NotFound, "")); return Err(Error::new(ErrorKind::NotFound, ""));
}
node = node.open_subkey(key.unwrap())?;
let val: String = node.get_value("InstallLocation")?;
path = PathBuf::from(val);
}
} }
Ok(path.join("Config").join("Champions"))
node = node.open_subkey(key.unwrap())?;
let val: String = node.get_value("InstallLocation")?;
Ok(PathBuf::from(val).join("Config").join("Champions"))
} }
#[cfg(not(target_os = "windows"))] #[cfg(not(target_os = "windows"))]
fn lol_champ_dir() -> Result<PathBuf, Error> { fn lol_champ_dir() -> Result<PathBuf, Error> {
Ok(PathBuf::from("./champs")) Ok(PathBuf::from(LOL_CHAMPS_DIR))
} }