#[macro_use] extern crate serde_derive; #[macro_use] extern crate log; extern crate reqwest; extern crate serde; #[macro_use] extern crate serde_json; extern crate regex; extern crate select; extern crate simple_logger; #[macro_use] extern crate lazy_static; extern crate indexmap; extern crate winreg; mod cgg_data_source; mod data_source; use cgg_data_source::CGGDataSource; use data_source::DataSource; use indexmap::IndexMap; use reqwest::header::{Headers, UserAgent}; use std::io::{Error, ErrorKind}; use std::path::PathBuf; use std::{fs, thread, time}; use time::Duration; use winreg::RegKey; #[derive(Deserialize)] struct Realm { v: String, } #[derive(Deserialize)] struct Champion { data: IndexMap, } #[derive(Deserialize)] struct ChampInfo { name: String, } const USER_AGENT: &str = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0"; const LOL_CHAMPS_DIR: &str = ".\\champs"; fn main() { simple_logger::init_with_level(log::Level::Info).unwrap(); info!("CGG Item Sets"); let lol_champs_dir = match lol_champ_dir() { Ok(x) => x, Err(_e) => PathBuf::from(LOL_CHAMPS_DIR), }; info!("LoL Champs Folder: {}", lol_champs_dir.to_str().unwrap()); let mut headers = Headers::new(); headers.set(UserAgent::new(USER_AGENT)); let client = reqwest::Client::builder() .default_headers(headers) .timeout(Duration::from_secs(10)) .build() .unwrap(); let realm: Realm = client .get("https://ddragon.leagueoflegends.com/realms/euw.json") .send() .unwrap() .json() .unwrap(); info!("LoL version: {}", realm.v); let champion: Champion = client .get(&format!( "https://ddragon.leagueoflegends.com/cdn/{}/data/en_US/champion.json", realm.v )) .send() .unwrap() .json() .unwrap(); info!("LoL numbers of champs: {}", champion.data.len()); let data_sources = [CGGDataSource]; for data_source in data_sources.iter() { let (champs, patch) = data_source.get_champs_with_positions_and_patch(&client); info!("CGG version: {}", patch); info!("CGG numbers of champs: {}", champs.len()); for (id, positions) in &champs { if champion.data.contains_key(id) { let path = lol_champs_dir.join(&id).join("Recommended"); fs::create_dir_all(&path).unwrap(); for pos in positions { data_source.write_item_set( &id, &champion.data.get(id).unwrap().name, &pos, &patch, &path, &client, ); thread::sleep(Duration::from_millis(300)); } } else { error!("{} not found in LoL champs", &id); } } } } fn lol_champ_dir() -> Result { let hklm = RegKey::predef(winreg::enums::HKEY_LOCAL_MACHINE); let node = hklm.open_subkey(r"SOFTWARE\WOW6432Node\Riot Games\RADS"); 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 .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")) }