diff --git a/gui/src/app.rs b/gui/src/app.rs index c9c52dd..7dd8625 100644 --- a/gui/src/app.rs +++ b/gui/src/app.rs @@ -22,6 +22,8 @@ pub enum EModListView { #[derive(serde::Deserialize, serde::Serialize)] #[serde(default)] // if we add new fields, give them default values when deserializing old state pub struct TemplateApp { + #[serde(skip)] + settings: AppSettings, #[serde(skip)] app_data: Option, @@ -61,6 +63,7 @@ impl Default for TemplateApp { let (tx2, rx2) = std::sync::mpsc::channel(); Self { + settings: AppSettings::default(), app_data: None, show_notes: true, show_conflicts: true, @@ -89,7 +92,7 @@ impl TemplateApp { // Load previous app state (if any). // Note that you must enable the `persistence` feature for this to work. - let app: TemplateApp = if let Some(storage) = cc.storage { + let mut app: TemplateApp = if let Some(storage) = cc.storage { eframe::get_value(storage, eframe::APP_KEY).unwrap_or_default() } else { Default::default() @@ -97,6 +100,7 @@ impl TemplateApp { // deserialize settings from plox.toml let settings = AppSettings::from_file(&PathBuf::from("plox.toml")); + app.settings = settings.clone(); // init logger let log_level = settings.log_level.clone().unwrap_or("info".to_string()); @@ -256,7 +260,11 @@ impl eframe::App for TemplateApp { if r.clicked() { // apply sorting - match update_new_load_order(data.game, &data.new_order) { + match update_new_load_order( + data.game, + &data.new_order, + self.settings.config.clone(), + ) { Ok(_) => { info!("Update successful"); } diff --git a/src/lib.rs b/src/lib.rs index e24978e..d588e57 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -238,7 +238,7 @@ where match game { ESupportedGame::Morrowind => gather_tes3_mods(root), ESupportedGame::Cyberpunk => gather_cp77_mods(root), - ESupportedGame::OpenMW => gather_openmw_mods(config), + ESupportedGame::OpenMW => gather_openmw_mods(&config), } } @@ -365,7 +365,7 @@ where names } -pub fn gather_openmw_mods

(config: Option

) -> Vec +pub fn gather_openmw_mods

(config: &Option

) -> Vec where P: AsRef, { @@ -468,10 +468,14 @@ where } /// Update on disk -pub fn update_new_load_order(game: ESupportedGame, result: &[String]) -> std::io::Result<()> { +pub fn update_new_load_order>( + game: ESupportedGame, + result: &[String], + config: Option

, +) -> std::io::Result<()> { match game { ESupportedGame::Morrowind => update_tes3(result), - ESupportedGame::OpenMW => update_openmw(result), + ESupportedGame::OpenMW => update_openmw(result, config), ESupportedGame::Cyberpunk => update_cp77(result), } } @@ -481,12 +485,21 @@ fn update_cp77(_result: &[String]) -> std::io::Result<()> { panic!("Not implemented") } -fn update_openmw(result: &[String]) -> std::io::Result<()> { +fn update_openmw>(result: &[String], config: Option

) -> std::io::Result<()> { // in openMW we just update the cfg with the new order - if let Ok(_cfg) = openmw_cfg::get_config() { + let mut path = config_path(); + if let Some(config_path) = config { + if config_path.as_ref().exists() { + path = config_path.as_ref().to_path_buf(); + } else { + error!("openmw.cfg not found at {}", config_path.as_ref().display()); + } + } + + if let Ok(_cfg) = openmw_cfg::Ini::load_from_file_noescape(&path) { // parse ini let mut buf = Vec::new(); - for line in read_lines(config_path())?.map_while(Result::ok) { + for line in read_lines(&path)?.map_while(Result::ok) { // skip plugin lines if line.starts_with("content=") { @@ -501,7 +514,7 @@ fn update_openmw(result: &[String]) -> std::io::Result<()> { } // save - let mut file = File::create(config_path())?; + let mut file = File::create(path)?; file.write_all(&buf)?; } else { error!("No openmw.cfg found"); diff --git a/src/main.rs b/src/main.rs index edd3355..0a9959f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -201,7 +201,7 @@ pub fn sort(options: CliSortOptions) -> ExitCode { mods = match game { ESupportedGame::Morrowind => gather_tes3_mods(&root), ESupportedGame::Cyberpunk => gather_cp77_mods(&root), - ESupportedGame::OpenMW => gather_openmw_mods(config), + ESupportedGame::OpenMW => gather_openmw_mods(&config), }; if mods.is_empty() { info!("No mods found"); @@ -303,7 +303,7 @@ pub fn sort(options: CliSortOptions) -> ExitCode { } else { info!("New:\n{:?}", result); - match update_new_load_order(game, &result) { + match update_new_load_order(game, &result, config) { Ok(_) => { info!("Update successful"); ExitCode::SUCCESS