record-daemon: keep a changed recordings folder usable
A folder typed into the settings screen was saved but never made. OBS does not create directories, so the next recording failed at its output and no timeline reached history. The daemon now makes the folder when settings are saved and again before each recording starts, rejects a folder it cannot use, and resolves it to an absolute path so both programs name the same place. Timelines now store the absolute path of their video next to the file name, so a clip stays reachable after the recording folder changes.
This commit is contained in:
1 parent
f3e44a2132
commit
86fc7cea2f
7 files changed
+82
-5
No files matched your search
@@ -124,7 +124,8 @@ The configuration file is stored at:
|
||||
- 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.
|
||||
Timelines go to `recordings/timelines` next to that `config` folder. Videos go to the `output.path`
|
||||
set below, which defaults to `recordings` beside it.
|
||||
|
||||
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.
|
||||
|
||||
@@ -14,7 +14,7 @@ pub use presets::{
|
||||
};
|
||||
pub use settings::{OutputSettings, Settings, VideoSettings};
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
/// Default configuration file name.
|
||||
pub const CONFIG_FILE_NAME: &str = "config.toml";
|
||||
@@ -51,3 +51,37 @@ pub fn get_data_dir() -> Option<PathBuf> {
|
||||
pub fn get_default_output_dir() -> Option<PathBuf> {
|
||||
get_data_dir().map(|dir| dir.join("recordings"))
|
||||
}
|
||||
|
||||
/// Resolve the recordings folder and make it, returning the absolute path.
|
||||
///
|
||||
/// The app and the daemon can run from different working directories, so a relative path
|
||||
/// would name two different folders. The daemon resolves it once and keeps the result, so
|
||||
/// both ends look in the same place.
|
||||
pub fn prepare_output_dir(path: &Path) -> std::io::Result<PathBuf> {
|
||||
let path = if path.as_os_str().is_empty() {
|
||||
get_default_output_dir().unwrap_or_else(|| PathBuf::from("./recordings"))
|
||||
} else {
|
||||
path.to_path_buf()
|
||||
};
|
||||
let path = std::path::absolute(path)?;
|
||||
std::fs::create_dir_all(&path)?;
|
||||
Ok(path)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn preparing_a_folder_makes_it_absolute_and_creates_it() {
|
||||
let dir = std::env::temp_dir().join(format!("record-daemon-{}", uuid::Uuid::new_v4()));
|
||||
let nested = dir.join("nested");
|
||||
let path = prepare_output_dir(&nested).unwrap();
|
||||
|
||||
assert!(path.is_absolute());
|
||||
assert!(path.is_dir());
|
||||
assert!(path.ends_with("nested"));
|
||||
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
}
|
||||
@@ -94,7 +94,19 @@ impl IpcHandlers {
|
||||
crate::error::IpcError::InvalidCommand("Missing settings payload".to_string())
|
||||
})?;
|
||||
|
||||
let new_settings: Settings = serde_json::from_value(payload)?;
|
||||
let mut new_settings: Settings = serde_json::from_value(payload)?;
|
||||
|
||||
// Make the folder now, not on the first game. OBS cannot create it, so a path typed
|
||||
// into the settings screen that does not exist would only fail once a game starts,
|
||||
// with no clip to show for it. Resolving it here also gives the app the absolute path
|
||||
// the daemon will write to, rather than one relative to a different working directory.
|
||||
let folder = new_settings.output.path.clone();
|
||||
new_settings.output.path = crate::config::prepare_output_dir(&folder).map_err(|e| {
|
||||
crate::error::ConfigError::InvalidConfig(format!(
|
||||
"the recordings folder {} cannot be used: {e}",
|
||||
folder.display()
|
||||
))
|
||||
})?;
|
||||
|
||||
// Validate settings
|
||||
if new_settings.video.frame_rate == 0 || new_settings.video.frame_rate > 240 {
|
||||
|
||||
@@ -707,11 +707,21 @@ async fn main() -> Result<()> {
|
||||
}
|
||||
}
|
||||
// Load configuration
|
||||
let settings = if let Some(config_path) = args.config {
|
||||
let mut settings = if let Some(config_path) = args.config {
|
||||
config::ConfigPersistence::new(config_path).load()?
|
||||
} else {
|
||||
config::load_config()?
|
||||
};
|
||||
|
||||
// Name the recordings folder the way the app will name it. A relative path in a
|
||||
// hand-written config would otherwise mean one folder here and another in the app.
|
||||
match config::prepare_output_dir(&settings.output.path) {
|
||||
Ok(path) => settings.output.path = path,
|
||||
Err(e) => warn!(
|
||||
"recordings folder {} cannot be used: {e}",
|
||||
settings.output.path.display()
|
||||
),
|
||||
}
|
||||
// Say where the pieces live: the first thing to check when a game records without a video.
|
||||
info!(
|
||||
"config: {}, recordings: {}",
|
||||
|
||||
@@ -100,6 +100,14 @@ impl RecordingEngine {
|
||||
let filename = self.generate_filename(game_id, champion);
|
||||
let output_path = settings.output.path.join(&filename);
|
||||
|
||||
// The settings screen can change the folder while this process runs, so the folder
|
||||
// made when OBS started is not necessarily this one. OBS does not create directories:
|
||||
// without this, a new folder makes every start fail and no clip is written.
|
||||
if let Some(dir) = output_path.parent() {
|
||||
std::fs::create_dir_all(dir)
|
||||
.map_err(|e| RecordingError::OutputDirError(format!("{}: {e}", dir.display())))?;
|
||||
}
|
||||
|
||||
let context = self
|
||||
.context
|
||||
.as_mut()
|
||||
|
||||
@@ -8,6 +8,7 @@ pub use store::{MetadataUpdate, RecordingMetadata, TimelineStore, TimestampedEve
|
||||
|
||||
use chrono::{DateTime, Duration, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::PathBuf;
|
||||
use uuid::Uuid;
|
||||
|
||||
/// A timeline of events for a recording.
|
||||
@@ -48,6 +49,13 @@ pub struct Timeline {
|
||||
/// Video file name (just the filename, not the full path).
|
||||
#[serde(default)]
|
||||
pub video_file: Option<String>,
|
||||
/// Full path the video was written to, when the recorder knew it.
|
||||
///
|
||||
/// The app looks a clip up by name in the recordings folder it knows. That folder can
|
||||
/// change while older clips stay where they were, so the absolute path travels with the
|
||||
/// timeline and a clip stays playable after the setting moves.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub video_path: Option<PathBuf>,
|
||||
/// What each audio track of the video carries, in the order the file holds them.
|
||||
#[serde(default)]
|
||||
pub audio_tracks: Vec<String>,
|
||||
@@ -77,6 +85,7 @@ impl Timeline {
|
||||
raw_live_client_data: None,
|
||||
raw_end_game_stats: None,
|
||||
video_file: None,
|
||||
video_path: None,
|
||||
audio_tracks: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -342,6 +342,7 @@ impl TimelineStore {
|
||||
raw_live_client_data: metadata.raw_live_client_data.clone(),
|
||||
raw_end_game_stats: metadata.raw_end_game_stats.clone(),
|
||||
video_file: metadata.video_file.clone(),
|
||||
video_path: metadata.file_path.clone(),
|
||||
audio_tracks: metadata.audio_tracks.clone(),
|
||||
})
|
||||
}
|
||||
@@ -387,6 +388,7 @@ impl TimelineStore {
|
||||
raw_live_client_data: metadata.raw_live_client_data,
|
||||
raw_end_game_stats: metadata.raw_end_game_stats,
|
||||
video_file: metadata.video_file,
|
||||
video_path: metadata.file_path,
|
||||
audio_tracks: metadata.audio_tracks,
|
||||
};
|
||||
|
||||
@@ -424,6 +426,7 @@ impl TimelineStore {
|
||||
let raw_live_client_data = timeline.raw_live_client_data;
|
||||
let raw_end_game_stats = timeline.raw_end_game_stats;
|
||||
let video_file = timeline.video_file;
|
||||
let video_path = timeline.video_path;
|
||||
let audio_tracks = timeline.audio_tracks;
|
||||
let events = timeline.events;
|
||||
|
||||
@@ -439,7 +442,7 @@ impl TimelineStore {
|
||||
start_time,
|
||||
end_time,
|
||||
duration,
|
||||
file_path: None,
|
||||
file_path: video_path,
|
||||
video_file,
|
||||
audio_tracks,
|
||||
file_size: None,
|
||||
|
||||
Reference in new issue
Block a user