From 1f753ca45d6b88d7e09ac5f37938405ef5647cf3 Mon Sep 17 00:00:00 2001 From: Casper Rogild Storm Date: Mon, 8 Feb 2021 08:32:28 +0100 Subject: [PATCH 1/5] feat: initial work on rewriting flavor detection --- crates/core/src/config/mod.rs | 12 ++++++++++++ src/gui/update.rs | 1 + 2 files changed, 13 insertions(+) diff --git a/crates/core/src/config/mod.rs b/crates/core/src/config/mod.rs index 12552543..640e37a1 100644 --- a/crates/core/src/config/mod.rs +++ b/crates/core/src/config/mod.rs @@ -56,6 +56,18 @@ pub struct Config { } impl Config { + /// Returns a `Option` to the falvor directory. + /// This will return `None` if no `wow_directory` is set in the config. + pub fn get_flavor_directory(&self, flavor: &Flavor) -> Option { + match &self.wow.directory { + Some(dir) => { + let flavor_dir = dir.join(&flavor.folder_name()); + Some(flavor_dir) + } + None => None, + } + } + /// Returns a `Option` to the directory containing the addons. /// This will return `None` if no `wow_directory` is set in the config. pub fn get_addon_directory_for_flavor(&self, flavor: &Flavor) -> Option { diff --git a/src/gui/update.rs b/src/gui/update.rs index f4fa210b..1646ad8c 100644 --- a/src/gui/update.rs +++ b/src/gui/update.rs @@ -656,6 +656,7 @@ pub fn handle_message(ajour: &mut Ajour, message: Message) -> Result Date: Mon, 8 Feb 2021 17:23:13 +0100 Subject: [PATCH 2/5] fix: if launching ajour before wow we try to create addon folder --- crates/core/src/config/mod.rs | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/crates/core/src/config/mod.rs b/crates/core/src/config/mod.rs index 640e37a1..2036b86b 100644 --- a/crates/core/src/config/mod.rs +++ b/crates/core/src/config/mod.rs @@ -3,6 +3,7 @@ use glob::MatchOptions; use serde::{Deserialize, Serialize}; use std::collections::HashMap; use std::fmt::{self, Display, Formatter}; +use std::fs::create_dir_all; use std::path::PathBuf; mod addons; @@ -56,25 +57,15 @@ pub struct Config { } impl Config { - /// Returns a `Option` to the falvor directory. - /// This will return `None` if no `wow_directory` is set in the config. - pub fn get_flavor_directory(&self, flavor: &Flavor) -> Option { - match &self.wow.directory { - Some(dir) => { - let flavor_dir = dir.join(&flavor.folder_name()); - Some(flavor_dir) - } - None => None, - } - } - /// Returns a `Option` to the directory containing the addons. /// This will return `None` if no `wow_directory` is set in the config. pub fn get_addon_directory_for_flavor(&self, flavor: &Flavor) -> Option { match &self.wow.directory { - Some(dir) => { - // The path to the directory containing the addons - let mut addon_dir = dir.join(&flavor.folder_name()).join("Interface/AddOns"); + Some(wow_dir) => { + // The path to the flavor directory + let flavor_dir = wow_dir.join(&flavor.folder_name()); + // The path to the addons directory + let mut addon_dir = flavor_dir.join("Interface/AddOns"); // If path doesn't exist, it could have been modified by the user. // Check for a case-insensitive version and use that instead. @@ -86,10 +77,7 @@ impl Config { // For some reason the case insensitive pattern doesn't work // unless we add an actual pattern symbol, hence the `?`. - let pattern = format!( - "{}/?nterface/?ddons", - dir.join(&flavor.folder_name()).display() - ); + let pattern = format!("{}/?nterface/?ddons", flavor_dir.display()); for entry in glob::glob_with(&pattern, options).unwrap() { if let Ok(path) = entry { @@ -98,6 +86,13 @@ impl Config { } } + // If flavor dir exists but not addon dir we try to create it. + // This state can happen if you do a fresh install of WoW and + // launch Ajour before you launch WoW. + if flavor_dir.exists() && !addon_dir.exists() { + let _ = create_dir_all(&addon_dir); + } + Some(addon_dir) } None => None, From 17dc9abbdc6fa90bc0bd29bce1a5f707bfc017fa Mon Sep 17 00:00:00 2001 From: Casper Rogild Storm Date: Mon, 8 Feb 2021 17:25:33 +0100 Subject: [PATCH 3/5] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 953315a0..c5251abb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,8 @@ and `Removed`. ### Fixed - Multiple error messages are now correctly localized. +- Corrected error in flavor detection if Ajour was launched before WoW had ever + been launched. ## [0.7.0] - 2021-01-26 From 87628774795e239825a92590db1a989438f0f9c2 Mon Sep 17 00:00:00 2001 From: Casper Rogild Storm Date: Mon, 8 Feb 2021 17:27:17 +0100 Subject: [PATCH 4/5] Update update.rs --- src/gui/update.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/gui/update.rs b/src/gui/update.rs index 1646ad8c..f4fa210b 100644 --- a/src/gui/update.rs +++ b/src/gui/update.rs @@ -656,7 +656,6 @@ pub fn handle_message(ajour: &mut Ajour, message: Message) -> Result Date: Mon, 8 Feb 2021 17:29:45 +0100 Subject: [PATCH 5/5] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5251abb..02101f09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,7 +32,7 @@ and `Removed`. - Multiple error messages are now correctly localized. - Corrected error in flavor detection if Ajour was launched before WoW had ever - been launched. + been launched. ## [0.7.0] - 2021-01-26