libobs_bootstrapper/
options.rs1use std::path::PathBuf;
2
3use semver::Version;
4
5pub 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 #[default]
17 Exact,
18 LatestCompatibleSameMajor,
20 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 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 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 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 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 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 #[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}