diff --git a/app/src/daemon.rs b/app/src/daemon.rs index 14c1bfb..88a7a14 100644 --- a/app/src/daemon.rs +++ b/app/src/daemon.rs @@ -8,8 +8,14 @@ use std::time::Duration; use crate::ipc::Client; +/// Set this to point the app and the daemon at a scratch directory, as scripts do. +pub const HOME_ENV: &str = "RECORD_DAEMON_HOME"; + /// The daemon's data directory, shared with the daemon itself. pub fn data_dir() -> Option { + if let Some(home) = std::env::var_os(HOME_ENV).filter(|value| !value.is_empty()) { + return Some(PathBuf::from(home).join("data")); + } directories::ProjectDirs::from("com", "leaguerecorder", "record-daemon") .map(|dirs| dirs.data_dir().to_path_buf()) } diff --git a/app/src/ipc.rs b/app/src/ipc.rs index 8f73a4e..e30e1b4 100644 --- a/app/src/ipc.rs +++ b/app/src/ipc.rs @@ -69,16 +69,25 @@ pub struct IpcResponse { pub error: Option, } -/// The pipe the daemon listens on. +/// The pipe the daemon listens on. A scratch home, as scripts set, gets a pipe of its own. pub fn default_socket_path() -> PathBuf { + let scratch = std::env::var_os(crate::daemon::HOME_ENV).is_some_and(|value| !value.is_empty()); #[cfg(windows)] { + if scratch { + return PathBuf::from(r"\\.\pipe\record-daemon-scratch"); + } PathBuf::from(r"\\.\pipe\record-daemon") } #[cfg(not(windows))] { + let name = if scratch { + "record-daemon-scratch.sock" + } else { + "record-daemon.sock" + }; let dir = std::env::var("XDG_RUNTIME_DIR").unwrap_or_else(|_| "/tmp".into()); - Path::new(&dir).join("record-daemon.sock") + Path::new(&dir).join(name) } } diff --git a/record-daemon/README.md b/record-daemon/README.md index b8c1fc4..4598601 100644 --- a/record-daemon/README.md +++ b/record-daemon/README.md @@ -109,8 +109,13 @@ cargo build --release ## Configuration The configuration file is stored at: -- Linux: `~/.config/record-daemon/config.toml` -- Windows: `%APPDATA%\record-daemon\config.toml` +- Linux: `~/.config/leaguerecorder/record-daemon/config.toml` +- Windows: `%APPDATA%\leaguerecorder\record-daemon\config\config.toml` + +Recordings and timelines go to `recordings` next to that `config` folder. + +Set `RECORD_DAEMON_HOME` to move all of it, config, recordings, logs and the IPC pipe, under one +directory. Scripts and end-to-end tests use it so a run never reads or writes the real settings. ### Example Configuration diff --git a/record-daemon/src/config/mod.rs b/record-daemon/src/config/mod.rs index 9249d50..1b770c9 100644 --- a/record-daemon/src/config/mod.rs +++ b/record-daemon/src/config/mod.rs @@ -19,14 +19,35 @@ use std::path::PathBuf; /// Default configuration file name. pub const CONFIG_FILE_NAME: &str = "config.toml"; +/// Set this to run the daemon against a scratch directory instead of the user's config, +/// recordings and log. Scripts and end-to-end tests set it so they cannot touch real data. +pub const HOME_ENV: &str = "RECORD_DAEMON_HOME"; + +fn override_home() -> Option { + std::env::var_os(HOME_ENV) + .filter(|value| !value.is_empty()) + .map(PathBuf::from) +} + /// Get the default configuration directory. pub fn get_config_dir() -> Option { + if let Some(home) = override_home() { + return Some(home.join("config")); + } directories::ProjectDirs::from("com", "leaguerecorder", "record-daemon") .map(|dirs| dirs.config_dir().to_path_buf()) } +/// Get the data directory, which holds `recordings` and `logs`. +pub fn get_data_dir() -> Option { + if let Some(home) = override_home() { + return Some(home.join("data")); + } + directories::ProjectDirs::from("com", "leaguerecorder", "record-daemon") + .map(|dirs| dirs.data_dir().to_path_buf()) +} + /// Get the default output directory for recordings. pub fn get_default_output_dir() -> Option { - directories::ProjectDirs::from("com", "leaguerecorder", "record-daemon") - .map(|dirs| dirs.data_dir().join("recordings")) + get_data_dir().map(|dir| dir.join("recordings")) } diff --git a/record-daemon/src/ipc/mod.rs b/record-daemon/src/ipc/mod.rs index 454a3c8..f30df48 100644 --- a/record-daemon/src/ipc/mod.rs +++ b/record-daemon/src/ipc/mod.rs @@ -13,17 +13,32 @@ pub use server::{IpcServer, IpcServerConfig}; use std::path::PathBuf; +/// Whether this run uses a scratch home, which gets a pipe of its own. +fn scratch_home() -> bool { + std::env::var_os(crate::config::HOME_ENV).is_some_and(|value| !value.is_empty()) +} + /// Default socket path for the IPC server. #[cfg(target_os = "linux")] pub fn default_socket_path() -> PathBuf { + let name = if scratch_home() { + "record-daemon-scratch.sock" + } else { + "record-daemon.sock" + }; std::env::var("XDG_RUNTIME_DIR") .map(PathBuf::from) .unwrap_or_else(|_| PathBuf::from("/tmp")) - .join("record-daemon.sock") + .join(name) } /// Default socket path for the IPC server. #[cfg(target_os = "windows")] pub fn default_socket_path() -> PathBuf { + // A scratch home gets its own pipe, so a script cannot take the pipe the installed app + // talks to. + if scratch_home() { + return PathBuf::from(r"\\.\pipe\record-daemon-scratch"); + } PathBuf::from(r"\\.\pipe\record-daemon") } diff --git a/record-daemon/src/main.rs b/record-daemon/src/main.rs index c046c94..c487a74 100644 --- a/record-daemon/src/main.rs +++ b/record-daemon/src/main.rs @@ -712,7 +712,14 @@ async fn main() -> Result<()> { } else { config::load_config()? }; - // Create and run daemon + // Say where the pieces live: the first thing to check when a game records without a video. + info!( + "config: {}, recordings: {}", + config::get_config_dir() + .map(|dir| dir.join(config::CONFIG_FILE_NAME).display().to_string()) + .unwrap_or_else(|| "the working directory".to_string()), + settings.output.path.display() + ); let mut daemon = Daemon::new(settings); #[cfg(unix)] {