find install dir by uninstall
This commit is contained in:
parent
71038e9a44
commit
4b9ba0aa8f
1 changed files with 29 additions and 7 deletions
36
src/main.rs
36
src/main.rs
|
@ -20,8 +20,9 @@ use reqwest::header::{Headers, UserAgent};
|
||||||
use select::document::Document;
|
use select::document::Document;
|
||||||
use select::predicate::{Class, Name};
|
use select::predicate::{Class, Name};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
use std::io::{Error, ErrorKind};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::{fs, io, thread, time};
|
use std::{fs, thread, time};
|
||||||
use time::Duration;
|
use time::Duration;
|
||||||
use winreg::RegKey;
|
use winreg::RegKey;
|
||||||
|
|
||||||
|
@ -154,7 +155,8 @@ fn get_champs_with_positions_and_patch(
|
||||||
|
|
||||||
let mut champions = IndexMap::new();
|
let mut champions = IndexMap::new();
|
||||||
for node in document.find(Class("champ-height")) {
|
for node in document.find(Class("champ-height")) {
|
||||||
let id = node.find(Class("home-champion"))
|
let id = node
|
||||||
|
.find(Class("home-champion"))
|
||||||
.next()
|
.next()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.attr("class")
|
.attr("class")
|
||||||
|
@ -163,7 +165,8 @@ fn get_champs_with_positions_and_patch(
|
||||||
.last()
|
.last()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_string();
|
.to_string();
|
||||||
let positions = node.find(Name("a"))
|
let positions = node
|
||||||
|
.find(Name("a"))
|
||||||
.skip(1)
|
.skip(1)
|
||||||
.map(|x| {
|
.map(|x| {
|
||||||
x.attr("href")
|
x.attr("href")
|
||||||
|
@ -190,7 +193,8 @@ fn get_champ_data(id: &str, position: &str, client: &reqwest::Client) -> Option<
|
||||||
.unwrap();
|
.unwrap();
|
||||||
if req.status().is_success() {
|
if req.status().is_success() {
|
||||||
lazy_static! {
|
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()
|
serde_json::from_str(&RE.captures(&req.text().unwrap())?[1]).unwrap()
|
||||||
} else {
|
} 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 hklm = RegKey::predef(winreg::enums::HKEY_LOCAL_MACHINE);
|
||||||
let node = hklm.open_subkey(r"SOFTWARE\WOW6432Node\Riot Games\RADS");
|
let node = hklm.open_subkey(r"SOFTWARE\WOW6432Node\Riot Games\RADS");
|
||||||
let path: PathBuf;
|
let path: PathBuf;
|
||||||
|
@ -284,8 +288,26 @@ fn lol_champ_dir() -> Result<PathBuf, io::Error> {
|
||||||
path = PathBuf::from(val).parent().unwrap().to_path_buf();
|
path = PathBuf::from(val).parent().unwrap().to_path_buf();
|
||||||
} else {
|
} else {
|
||||||
let node = hklm.open_subkey(r"SOFTWARE\WOW6432Node\Riot Games, Inc\League of Legends");
|
let node = hklm.open_subkey(r"SOFTWARE\WOW6432Node\Riot Games, Inc\League of Legends");
|
||||||
let val: String = node?.get_value("Location")?;
|
if node.is_ok() {
|
||||||
path = PathBuf::from(val);
|
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"))
|
Ok(path.join("Config").join("Champions"))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue