Skip to main content

libobs_bootstrapper/
options.rs

1use std::path::PathBuf;
2
3use semver::Version;
4
5/// OBS ABI version that this release of libobs-rs is built against.
6///
7/// This crate intentionally does not depend on the native `libobs` crate: a
8/// bootstrap helper must be able to start before `obs.dll`/`libobs.framework`
9/// exists. Keep this value synchronized with `libobs/headers/obs/obs-config.h`.
10pub const DEFAULT_OBS_VERSION: &str = "32.1.0";
11pub const GITHUB_REPO: &str = "obsproject/obs-studio";
12
13#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
14pub enum UpdateTargetMode {
15    /// Provision the exact OBS version configured in `target_version`.
16    #[default]
17    Exact,
18    /// Resolve the newest stable release with the same OBS major version.
19    LatestCompatibleSameMajor,
20    /// Resolve the newest stable patch release with the same major/minor.
21    LatestCompatibleSameMajorMinor,
22}
23
24#[derive(Debug, Clone)]
25pub struct ObsBootstrapperOptions {
26    pub(crate) repository: String,
27    pub(crate) update: bool,
28    pub(crate) update_target_mode: UpdateTargetMode,
29    pub(crate) install_dir: Option<PathBuf>,
30    pub(crate) cache_dir: Option<PathBuf>,
31    pub(crate) target_version: Version,
32}
33
34impl ObsBootstrapperOptions {
35    pub fn new() -> Self {
36        Self {
37            repository: GITHUB_REPO.to_string(),
38            update: true,
39            update_target_mode: UpdateTargetMode::Exact,
40            install_dir: None,
41            cache_dir: None,
42            target_version: Version::parse(DEFAULT_OBS_VERSION)
43                .expect("DEFAULT_OBS_VERSION must be valid semver"),
44        }
45    }
46
47    /// Selects the GitHub repository used for runtime provisioning.
48    ///
49    /// The default is the official `obsproject/obs-studio` repository. Changing
50    /// this is an explicit trust decision by the caller.
51    pub fn set_repository(mut self, repository: &str) -> Self {
52        self.repository = repository.to_string();
53        self
54    }
55
56    pub fn get_repository(&self) -> &str {
57        &self.repository
58    }
59
60    /// Controls whether an existing older/incompatible runtime may be replaced.
61    /// A missing runtime is still installed even when this is `false`.
62    pub fn set_update(mut self, update: bool) -> Self {
63        self.update = update;
64        self
65    }
66
67    pub fn get_update(&self) -> bool {
68        self.update
69    }
70
71    pub fn set_update_target_mode(mut self, update_target_mode: UpdateTargetMode) -> Self {
72        self.update_target_mode = update_target_mode;
73        self
74    }
75
76    pub fn get_update_target_mode(&self) -> UpdateTargetMode {
77        self.update_target_mode
78    }
79
80    /// Overrides the directory where the prepared OBS runtime is installed.
81    /// Defaults to the executable directory.
82    pub fn set_install_dir<P: Into<PathBuf>>(mut self, install_dir: P) -> Self {
83        self.install_dir = Some(install_dir.into());
84        self
85    }
86
87    pub fn get_install_dir(&self) -> Option<&PathBuf> {
88        self.install_dir.as_ref()
89    }
90
91    /// Overrides the cache used for downloaded/extracted OBS release assets.
92    pub fn set_cache_dir<P: Into<PathBuf>>(mut self, cache_dir: P) -> Self {
93        self.cache_dir = Some(cache_dir.into());
94        self
95    }
96
97    pub fn get_cache_dir(&self) -> Option<&PathBuf> {
98        self.cache_dir.as_ref()
99    }
100
101    /// Overrides the OBS version this application is built against.
102    pub fn set_target_version(mut self, version: Version) -> Self {
103        self.target_version = version;
104        self
105    }
106
107    pub fn get_target_version(&self) -> &Version {
108        &self.target_version
109    }
110
111    /// Compatibility no-op retained from the old updater-script design.
112    /// Runtime provisioning no longer spawns or restarts the application.
113    #[deprecated(note = "runtime bootstrap no longer restarts the application")]
114    pub fn set_no_restart(self) -> Self {
115        self
116    }
117}
118
119impl Default for ObsBootstrapperOptions {
120    fn default() -> Self {
121        Self::new()
122    }
123}