1use nitro_auth::mc::ClientId;
2
3use crate::util::secrets::get_ms_client_id;
4
5macro_rules! builder_method {
6 ($name:ident, $ty:ty, $doc:literal) => {
7 #[doc = $doc]
8 pub fn $name(mut self, $name: $ty) -> Self {
9 self.config.$name = $name;
10 self
11 }
12 };
13}
14
15pub struct Configuration {
17 pub(crate) ms_client_id: ClientId,
19 pub(crate) censor_secrets: bool,
21 pub(crate) disable_hardlinks: bool,
24 pub(crate) branding: BrandingProperties,
26}
27
28impl Default for Configuration {
29 fn default() -> Self {
30 Self::new()
31 }
32}
33
34impl Configuration {
35 pub fn new() -> Self {
37 Self {
38 ms_client_id: get_ms_client_id(),
39 censor_secrets: true,
40 disable_hardlinks: false,
41 branding: BrandingProperties::default(),
42 }
43 }
44
45 pub fn builder() -> ConfigBuilder {
47 ConfigBuilder::new()
48 }
49}
50
51pub struct ConfigBuilder {
53 config: Configuration,
54}
55
56impl ConfigBuilder {
57 pub fn new() -> Self {
59 Self {
60 config: Configuration::new(),
61 }
62 }
63
64 pub fn build(self) -> Configuration {
66 self.config
67 }
68
69 builder_method!(
70 ms_client_id,
71 ClientId,
72 "Set the Microsoft client ID to use for Microsoft / Xbox Live authentication"
73 );
74
75 builder_method!(
76 censor_secrets,
77 bool,
78 "Set whether to censor account credentials in output messages and logs"
79 );
80
81 builder_method!(
82 disable_hardlinks,
83 bool,
84 "Set whether to disable the use of hardlinks"
85 );
86
87 builder_method!(branding, BrandingProperties, "Set the branding properties");
88}
89
90impl Default for ConfigBuilder {
91 fn default() -> Self {
92 Self::new()
93 }
94}
95
96#[derive(Clone)]
98pub struct BrandingProperties {
99 pub(crate) launcher_name: String,
101 pub(crate) launcher_version: String,
103}
104
105impl Default for BrandingProperties {
106 fn default() -> Self {
107 Self {
108 launcher_name: "nitro_core".into(),
109 launcher_version: env!("CARGO_PKG_VERSION").into(),
110 }
111 }
112}
113
114impl BrandingProperties {
115 pub fn new(name: String, version: String) -> Self {
117 Self {
118 launcher_name: name,
119 launcher_version: version,
120 }
121 }
122}