Readd old regkey for old install
Some checks reported errors
continuous-integration/drone/push Build encountered an error

This commit is contained in:
nyyu 2021-03-14 13:06:29 +01:00
parent a723ec1609
commit b08dd9c6c0

View file

@ -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;
@ -140,21 +141,56 @@ fn get_champ_from_key(champs: &Champion, key: &str) -> String {
#[cfg(target_os = "windows")]
fn lol_champ_dir() -> Result<PathBuf, Error> {
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
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));
}
}
let node = hklm.open_subkey(r"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall");
let mut sub_node: io::Result<RegKey> = 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 == None {
return Err(Error::new(ErrorKind::NotFound, ""));
if key.is_some() {
sub_node = n.open_subkey(key.unwrap());
}
}
}
node = node.open_subkey(key.unwrap())?;
let val: String = node.get_value("InstallLocation")?;
Ok(PathBuf::from(val).join("Config").join("Champions"))
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"))]