Skip to content

Commit

Permalink
Default to legacy project dirs if they exist
Browse files Browse the repository at this point in the history
  • Loading branch information
trumank committed Dec 16, 2023
1 parent 2cdf7b2 commit f2cf65f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
11 changes: 8 additions & 3 deletions src/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use tokio::{
sync::mpsc::{self, Receiver, Sender},
task::JoinHandle,
};
use tracing::{debug, info, trace};
use tracing::{debug, trace};

use crate::mod_lints::{LintId, LintReport, SplitAssetPair};
use crate::Dirs;
Expand Down Expand Up @@ -146,8 +146,6 @@ impl App {
fn new(cc: &eframe::CreationContext, dirs: Dirs, args: Option<Vec<String>>) -> Result<Self> {
let (tx, rx) = mpsc::channel(10);
let state = State::init(dirs)?;
info!("config dir = {}", state.dirs.config_dir.display());
info!("cache dir = {}", state.dirs.cache_dir.display());

Ok(Self {
default_visuals: cc
Expand Down Expand Up @@ -944,6 +942,13 @@ impl App {
}
ui.end_row();

let data_dir = &self.state.dirs.data_dir;
ui.label("Data directory:");
if ui.link(data_dir.display().to_string()).clicked() {
opener::open(data_dir).ok();
}
ui.end_row();

ui.label("GUI theme:");
ui.horizontal(|ui| {
ui.horizontal(|ui| {
Expand Down
18 changes: 14 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,31 @@ use providers::{ModResolution, ModSpecification, ProviderFactory, ReadSeek};
use state::State;
use tracing::{info, warn};

#[derive(Debug)]
pub struct Dirs {
pub config_dir: PathBuf,
pub cache_dir: PathBuf,
pub data_dir: PathBuf,
}

impl Dirs {
pub fn defauld_xdg() -> Result<Self> {
pub fn default_xdg() -> Result<Self> {
let legacy_dirs = ProjectDirs::from("", "", "drg-mod-integration")
.context("constructing project dirs")?;

let project_dirs =
ProjectDirs::from("", "", "mint").context("constructing project dirs")?;

Self::from_paths(
project_dirs.config_dir(),
project_dirs.cache_dir(),
project_dirs.data_dir(),
Some(legacy_dirs.config_dir())
.filter(|p| p.exists())
.unwrap_or(project_dirs.config_dir()),
Some(legacy_dirs.cache_dir())
.filter(|p| p.exists())
.unwrap_or(project_dirs.cache_dir()),
Some(legacy_dirs.data_dir())
.filter(|p| p.exists())
.unwrap_or(project_dirs.data_dir()),
)
}
pub fn from_path<P: AsRef<Path>>(path: P) -> Result<Self> {
Expand Down
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,16 @@ fn main() -> Result<()> {
.appdata
.as_ref()
.map(Dirs::from_path)
.unwrap_or_else(Dirs::defauld_xdg)?;
.unwrap_or_else(Dirs::default_xdg)?;

std::env::set_var("RUST_BACKTRACE", "1");
let _guard = setup_logging(&dirs)?;
debug!("logging setup complete");

info!("config dir = {}", dirs.config_dir.display());
info!("cache dir = {}", dirs.cache_dir.display());
info!("data dir = {}", dirs.data_dir.display());

let rt = tokio::runtime::Runtime::new().expect("Unable to create Runtime");
debug!("tokio runtime created");
let _enter = rt.enter();
Expand Down

0 comments on commit f2cf65f

Please sign in to comment.