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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use re_entity_db::{StoreBundle, StoreLoadError};

#[derive(thiserror::Error, Debug)]
enum BlueprintLoadError {
    #[error("Failed to open file: {0}")]
    FileOpen(#[from] std::io::Error),

    #[error(transparent)]
    StoreLoad(#[from] StoreLoadError),
}

/// Try to load the given `.blueprint` file.
///
/// The file must be of a matching version of rerun.
#[must_use]
pub fn load_blueprint_file(
    path: &std::path::Path,
    with_notifications: bool,
) -> Option<StoreBundle> {
    fn load_file_path_impl(path: &std::path::Path) -> Result<StoreBundle, BlueprintLoadError> {
        re_tracing::profile_function!();

        let file = std::fs::File::open(path)?;
        let file = std::io::BufReader::new(file);

        // Blueprint files change often. Be strict about the version, and then ignore any errors.
        // See https://github.com/rerun-io/rerun/issues/2830
        let version_policy = re_log_encoding::decoder::VersionPolicy::Error;

        Ok(StoreBundle::from_rrd(version_policy, file)?)
    }

    match load_file_path_impl(path) {
        Ok(mut rrd) => {
            if with_notifications {
                re_log::info!("Loaded {path:?}");
            }

            for entity_db in rrd.entity_dbs_mut() {
                entity_db.data_source =
                    Some(re_smart_channel::SmartChannelSource::File(path.into()));
            }
            Some(rrd)
        }
        Err(err) => {
            let msg = format!("Failed loading {path:?}: {err}");

            if with_notifications {
                re_log::error!("{msg}");
                rfd::MessageDialog::new()
                    .set_level(rfd::MessageLevel::Error)
                    .set_description(&msg)
                    .show();
            } else {
                // Silently ignore
                re_log::debug!("{msg}");
            }
            None
        }
    }
}