aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-assets/src/startup_movies.rs
blob: d2a590fef53eca517daf88495dab63aa975ac8b5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//! Intro movie paths declared in the installed shell configuration.

use crate::ui_configuration::{field, object, read};
use fparkan_path::{normalize_relative, NormalizedPath, PathPolicy};
use fparkan_vfs::Vfs;

/// Resolves the shell's logo and splash entries in playback order.
pub fn movie_paths(vfs: &dyn Vfs) -> Result<Vec<NormalizedPath>, String> {
    parse_movies(&read(vfs, "ui/shell_ctrls.cfg")?)
}

fn parse_movies(bytes: &[u8]) -> Result<Vec<NormalizedPath>, String> {
    let text = String::from_utf8_lossy(bytes);
    let common = object(&text, "common").ok_or("missing shell common configuration")?;
    let mut paths = Vec::new();
    for slot in ["LOGO1_PARAM", "LOGO2_PARAM", "SPLASH_PARAM"] {
        if !common.contains_key(slot) {
            continue;
        }
        let path = field(&common, slot)?;
        if !path.is_empty() {
            paths.push(
                normalize_relative(path.as_bytes(), PathPolicy::StrictLegacy)
                    .map_err(|error| format!("{slot}: {error}"))?,
            );
        }
    }
    Ok(paths)
}

#[cfg(test)]
#[test]
fn keeps_logo_order_and_skips_empty_slots() {
    let paths = parse_movies(
        b"object common\nsplash_param = \"data\\end.avi\"\nlogo2_param = \"DATA\\begin.avi\"\nlogo1_param = \"\"\nend",
    ).unwrap();
    assert_eq!(
        paths.iter().map(NormalizedPath::as_str).collect::<Vec<_>>(),
        ["DATA/begin.avi", "data/end.avi"]
    );
    assert!(parse_movies(b"object common\nlogo1_param = \"..\\video.avi\"\nend").is_err());
}