From 95fb43b908945ddec6a74404870fe463d39804c8 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Wed, 22 Jan 2025 08:52:27 -0800 Subject: [PATCH] settings: implement directories --- engine/settings/src/directories.rs | 32 ++++++++++++++++++++++++++++++ engine/settings/src/lib.rs | 1 + 2 files changed, 33 insertions(+) create mode 100644 engine/settings/src/directories.rs diff --git a/engine/settings/src/directories.rs b/engine/settings/src/directories.rs new file mode 100644 index 0000000..1cc9150 --- /dev/null +++ b/engine/settings/src/directories.rs @@ -0,0 +1,32 @@ +use std::path::PathBuf; + +use crate::settings::{UserSettings,load_user_settings}; + +pub struct Directories{ + pub settings:PathBuf, + pub maps:PathBuf, + pub replays:PathBuf, +} +impl Directories{ + pub fn settings(&self)->UserSettings{ + load_user_settings(&self.settings) + } + pub fn user()->Option{ + let dirs=directories::ProjectDirs::from("net.strafes","StrafesNET","Strafe Client")?; + Some(Self{ + settings:dirs.config_dir().join("settings.conf"), + maps:dirs.cache_dir().join("maps"), + // separate directory for remote downloaded replays (cache) + // bots:dirs.cache_dir().join("bots"), + replays:dirs.data_local_dir().join("replays"), + }) + } + pub fn portable()->Result{ + let current_dir=std::env::current_dir()?; + Ok(Self{ + settings:current_dir.join("settings.conf"), + maps:current_dir.join("maps"), + replays:current_dir.join("replays"), + }) + } +} diff --git a/engine/settings/src/lib.rs b/engine/settings/src/lib.rs index 6e98cef..a6db573 100644 --- a/engine/settings/src/lib.rs +++ b/engine/settings/src/lib.rs @@ -1 +1,2 @@ pub mod settings; +pub mod directories;