Skip to content

Commit

Permalink
Support skyrim LE in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
divanvisagie committed Jan 29, 2022
1 parent d39c7d3 commit 6198bfb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
12 changes: 10 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use eframe::egui::Color32;
use eframe::epi;

use crate::{
load_save_file,
load_installed, load_mod_map, load_save_file,
mod_search::vortex_scanner::Plugin,
sktypes::{
self,
Expand Down Expand Up @@ -36,7 +36,15 @@ impl epi::App for AppState {
self.file_path = String::from(path_buf.to_str().unwrap());
match load_save_file(self.file_path.to_string()) {
Ok(values) => {
self.values = values;
let (dts, is_se) = values;
if is_se {
self.mod_map = load_mod_map("skyrimse");
self.installed = load_installed("skyrimse")
} else {
self.mod_map = load_mod_map("skyrim");
self.installed = load_installed("skyrim");
}
self.values = dts;
self.error = None;
}
Err(e) => {
Expand Down
16 changes: 8 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@ mod mod_search;
mod parser;
mod sktypes;

fn load_mod_map() -> HashMap<String, Plugin> {
fn load_mod_map(game: &str) -> HashMap<String, Plugin> {
let mut map = HashMap::new();
if let Ok(plugins) = get_masterlist_data() {
if let Ok(plugins) = get_masterlist_data(game) {
for plugin in plugins {
map.insert(plugin.name.clone(), plugin);
}
}
map
}

fn load_installed() -> HashSet<String> {
fn load_installed(game: &str) -> HashSet<String> {
let mut installed = HashSet::new();
for p in get_installed_from_all_profiles() {
for p in get_installed_from_all_profiles(game) {
installed.insert(p);
}
installed
}

fn load_save_file(path: String) -> Result<Vec<SkUIValue>, Error> {
fn load_save_file(path: String) -> Result<(Vec<SkUIValue>, bool), Error> {
tracing::info!("Loading file: {:?}", path);
let mut file = std::fs::File::open(path)?;

Expand Down Expand Up @@ -107,7 +107,7 @@ fn load_save_file(path: String) -> Result<Vec<SkUIValue>, Error> {
items.push(SkUIValue::new("Plugin", plugin, UIValueType::Plugin));
}

Ok(items)
Ok((items, parsed.header.is_se))
}

fn main() {
Expand All @@ -117,8 +117,8 @@ fn main() {
let app_state = AppState {
file_path: String::from(""),
values: Vec::with_capacity(150),
mod_map: load_mod_map(),
installed: load_installed(),
mod_map: HashMap::new(),
installed: HashSet::new(),
error: None,
};
let mut window_options = eframe::NativeOptions::default();
Expand Down
20 changes: 9 additions & 11 deletions src/mod_search/vortex_scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ struct MasterListFileType {
plugins: Vec<PluginFileType>,
}

pub fn get_masterlist_data() -> Result<Vec<Plugin>, Error> {
pub fn get_masterlist_data(game: &str) -> Result<Vec<Plugin>, Error> {
let app_data_path = env::var("APPDATA").unwrap();
let mut path_buf = PathBuf::new();
path_buf.push(app_data_path);
path_buf.push("Vortex");
path_buf.push("skyrimse");
path_buf.push(game);
path_buf.push("masterlist");
path_buf.push("masterlist.yaml");
println!("Looking for vortex at: {:?}", path_buf);
Expand Down Expand Up @@ -63,12 +63,12 @@ pub fn get_profile_data(profile_name: &str) -> Result<Vec<String>, Error> {
Ok(plugins_in_profile)
}

pub fn get_profiles() -> Result<Vec<String>, Error> {
pub fn get_profiles(game: &str) -> Result<Vec<String>, Error> {
let app_data_path = env::var("APPDATA").unwrap();
let mut path_buf = PathBuf::new();
path_buf.push(app_data_path);
path_buf.push("Vortex");
path_buf.push("skyrimse");
path_buf.push(game);
path_buf.push("profiles");

let read = fs::read_dir(path_buf)?;
Expand All @@ -80,17 +80,15 @@ pub fn get_profiles() -> Result<Vec<String>, Error> {
Ok(items)
}

pub fn get_installed_from_all_profiles() -> Vec<String> {
pub fn get_installed_from_all_profiles(game: &str) -> Vec<String> {
let mut all = Vec::new();
if let Ok(profiles) = get_profiles() {
if let Ok(profiles) = get_profiles(game) {
for prof in profiles {
match get_profile_data(&prof) {
Ok(plugins_in_profile) => {
all.extend(plugins_in_profile);
}
_ => (
tracing::error!("Cannot read plugins from profile: {prof}")
),
_ => (tracing::error!("Cannot read plugins from profile: {prof}")),
}
}
} else {
Expand Down Expand Up @@ -120,13 +118,13 @@ mod tests {

#[test]
fn get_masterlist_data_test() {
let plugins = get_masterlist_data();
let plugins = get_masterlist_data("skyrimse");
println!("{:?}", plugins);
}

#[test]
fn get_profile_data_test() {
let p = get_installed_from_all_profiles();
let p = get_installed_from_all_profiles("skyrimse");
println!("String interpolation yay {:?}", p)
}
}

0 comments on commit 6198bfb

Please sign in to comment.