Resolve every base directory in one place, and on Windows
Five sites each read XDG_*_HOME and fell back to $HOME/.local/… on their own, which is fine on Linux and wrong everywhere else: Windows sets neither variable, so every one of them degraded to a path relative to the working directory — for a Start Menu launch, C:\Windows\System32. The models lookup walked XDG_DATA_DIRS the same way. dr_plat::dirs now holds the rule per platform: XDG on Unix, the known folders on Windows — %APPDATA% for config, which roams, and %LOCALAPPDATA% for data and state, which do not — and the executable's own directory as the system data dir, which is where the installer puts the models. The Android overrides stay where they were; only the fallback behind them moved. Both rule sets are unit-tested on either host, and the Windows one was confirmed by running the application under Wine: its log landed in AppData\Local\darkroom\state and nothing was written anywhere else.
This commit is contained in:
@@ -67,15 +67,21 @@ pub fn set_data_dir(dir: PathBuf) {
|
||||
let _ = DATA_DIR.set(dir);
|
||||
}
|
||||
|
||||
/// The directory the platform entry point declared, if it declared one.
|
||||
///
|
||||
/// Android does; a desktop does not, and resolves through `dr_plat::dirs`
|
||||
/// instead. Exposed so a caller wanting the *data* directory can honour the
|
||||
/// same declaration without inheriting the config rule as its fallback.
|
||||
pub fn declared_data_dir() -> Option<PathBuf> {
|
||||
DATA_DIR.get().cloned()
|
||||
}
|
||||
|
||||
/// The directory configuration lives in.
|
||||
pub fn config_dir() -> PathBuf {
|
||||
if let Some(d) = DATA_DIR.get() {
|
||||
return d.clone();
|
||||
}
|
||||
std::env::var_os("XDG_CONFIG_HOME")
|
||||
.map(PathBuf::from)
|
||||
.unwrap_or_else(|| PathBuf::from(std::env::var("HOME").unwrap_or_default()).join(".config"))
|
||||
.join("darkroom")
|
||||
dr_plat::base_dir(dr_plat::Base::Config)
|
||||
}
|
||||
|
||||
/// TRACES: FR-NC-12
|
||||
|
||||
Reference in New Issue
Block a user