find install dir by uninstall

This commit is contained in:
nyyu 2018-06-10 15:02:08 +02:00
parent 71038e9a44
commit 4b9ba0aa8f

View File

@ -20,8 +20,9 @@ use reqwest::header::{Headers, UserAgent};
use select::document::Document;
use select::predicate::{Class, Name};
use serde_json::Value;
use std::io::{Error, ErrorKind};
use std::path::PathBuf;
use std::{fs, io, thread, time};
use std::{fs, thread, time};
use time::Duration;
use winreg::RegKey;
@ -154,7 +155,8 @@ fn get_champs_with_positions_and_patch(
let mut champions = IndexMap::new();
for node in document.find(Class("champ-height")) {
let id = node.find(Class("home-champion"))
let id = node
.find(Class("home-champion"))
.next()
.unwrap()
.attr("class")
@ -163,7 +165,8 @@ fn get_champs_with_positions_and_patch(
.last()
.unwrap()
.to_string();
let positions = node.find(Name("a"))
let positions = node
.find(Name("a"))
.skip(1)
.map(|x| {
x.attr("href")
@ -190,7 +193,8 @@ fn get_champ_data(id: &str, position: &str, client: &reqwest::Client) -> Option<
.unwrap();
if req.status().is_success() {
lazy_static! {
static ref RE: Regex = Regex::new(r"(?m)^\s+matchupData\.championData = (.*)$").unwrap();
static ref RE: Regex =
Regex::new(r"(?m)^\s+matchupData\.championData = (.*)$").unwrap();
}
serde_json::from_str(&RE.captures(&req.text().unwrap())?[1]).unwrap()
} else {
@ -275,7 +279,7 @@ fn write_item_set(
}
}
fn lol_champ_dir() -> Result<PathBuf, io::Error> {
fn lol_champ_dir() -> Result<PathBuf, Error> {
let hklm = RegKey::predef(winreg::enums::HKEY_LOCAL_MACHINE);
let node = hklm.open_subkey(r"SOFTWARE\WOW6432Node\Riot Games\RADS");
let path: PathBuf;
@ -284,8 +288,26 @@ fn lol_champ_dir() -> Result<PathBuf, io::Error> {
path = PathBuf::from(val).parent().unwrap().to_path_buf();
} else {
let node = hklm.open_subkey(r"SOFTWARE\WOW6432Node\Riot Games, Inc\League of Legends");
let val: String = node?.get_value("Location")?;
path = PathBuf::from(val);
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
.enum_keys()
.map(|x| x.unwrap())
.find(|x| x.starts_with("League of Legends"));
if key == None {
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"))
}