Skip to content

Commit

Permalink
fixed a bug where custom openmw cfg was not used
Browse files Browse the repository at this point in the history
  • Loading branch information
rfuzzo committed Mar 12, 2024
1 parent e933f87 commit 1dee179
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
12 changes: 10 additions & 2 deletions gui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AppData>,

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -89,14 +92,15 @@ 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()
};

// 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());
Expand Down Expand Up @@ -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");
}
Expand Down
29 changes: 21 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}

Expand Down Expand Up @@ -365,7 +365,7 @@ where
names
}

pub fn gather_openmw_mods<P>(config: Option<P>) -> Vec<PluginData>
pub fn gather_openmw_mods<P>(config: &Option<P>) -> Vec<PluginData>
where
P: AsRef<Path>,
{
Expand Down Expand Up @@ -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<P: AsRef<Path>>(
game: ESupportedGame,
result: &[String],
config: Option<P>,
) -> 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),
}
}
Expand All @@ -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<P: AsRef<Path>>(result: &[String], config: Option<P>) -> 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=") {
Expand All @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1dee179

Please sign in to comment.