1use std::path::PathBuf;
15
16#[cfg(feature = "istmo")]
24#[must_use]
25pub fn config_base_dir() -> Option<PathBuf> {
26 Some(istmo_core::path::config_dir().to_path_buf())
27}
28
29#[cfg(all(not(feature = "istmo"), target_os = "windows"))]
30#[must_use]
31pub fn config_base_dir() -> Option<PathBuf> {
32 std::env::var_os("APPDATA").map(PathBuf::from)
33}
34
35#[cfg(all(not(feature = "istmo"), target_os = "macos"))]
36#[must_use]
37pub fn config_base_dir() -> Option<PathBuf> {
38 home_dir().map(|h| h.join("Library").join("Application Support"))
39}
40
41#[cfg(all(
42 not(feature = "istmo"),
43 not(any(target_os = "windows", target_os = "macos"))
44))]
45#[must_use]
46pub fn config_base_dir() -> Option<PathBuf> {
47 std::env::var_os("XDG_CONFIG_HOME")
48 .map(PathBuf::from)
49 .or_else(|| home_dir().map(|h| h.join(".config")))
50}
51
52#[cfg(feature = "istmo")]
60#[must_use]
61pub fn data_base_dir() -> Option<PathBuf> {
62 Some(istmo_core::path::data_dir().to_path_buf())
63}
64
65#[cfg(all(not(feature = "istmo"), target_os = "windows"))]
66#[must_use]
67pub fn data_base_dir() -> Option<PathBuf> {
68 std::env::var_os("LOCALAPPDATA").map(PathBuf::from)
69}
70
71#[cfg(all(not(feature = "istmo"), target_os = "macos"))]
72#[must_use]
73pub fn data_base_dir() -> Option<PathBuf> {
74 home_dir().map(|h| h.join("Library").join("Application Support"))
75}
76
77#[cfg(all(
78 not(feature = "istmo"),
79 not(any(target_os = "windows", target_os = "macos"))
80))]
81#[must_use]
82pub fn data_base_dir() -> Option<PathBuf> {
83 std::env::var_os("XDG_DATA_HOME")
84 .map(PathBuf::from)
85 .or_else(|| home_dir().map(|h| h.join(".local").join("share")))
86}
87
88#[cfg(feature = "istmo")]
93#[must_use]
94pub fn app_config_dir(_app_name: &str) -> Option<PathBuf> {
95 Some(istmo_core::path::config_dir().to_path_buf())
96}
97
98#[cfg(not(feature = "istmo"))]
99#[must_use]
100pub fn app_config_dir(app_name: &str) -> Option<PathBuf> {
101 config_base_dir().map(|d| d.join(app_name))
102}
103
104#[cfg(feature = "istmo")]
109#[must_use]
110pub fn app_data_dir(_app_name: &str) -> Option<PathBuf> {
111 Some(istmo_core::path::data_dir().to_path_buf())
112}
113
114#[cfg(not(feature = "istmo"))]
115#[must_use]
116pub fn app_data_dir(app_name: &str) -> Option<PathBuf> {
117 data_base_dir().map(|d| d.join(app_name))
118}
119
120#[cfg(feature = "istmo")]
124#[must_use]
125pub fn app_cache_dir(_app_name: &str) -> Option<PathBuf> {
126 Some(istmo_core::path::cache_dir().to_path_buf())
127}
128
129#[cfg(feature = "istmo")]
133#[must_use]
134pub fn app_state_dir(_app_name: &str) -> Option<PathBuf> {
135 Some(istmo_core::path::state_dir().to_path_buf())
136}
137
138#[cfg(not(feature = "istmo"))]
139fn home_dir() -> Option<PathBuf> {
140 std::env::var_os("HOME").map(PathBuf::from)
141}