use mcvm_auth::mc::ClientId;
use mcvm_shared::UpdateDepth;
use crate::util::secrets::get_ms_client_id;
macro_rules! builder_method {
($name:ident, $ty:ty, $doc:literal) => {
#[doc = $doc]
pub fn $name(mut self, $name: $ty) -> Self {
self.config.$name = $name;
self
}
};
}
pub struct Configuration {
pub(crate) ms_client_id: ClientId,
pub(crate) update_depth: UpdateDepth,
pub(crate) censor_secrets: bool,
pub(crate) disable_hardlinks: bool,
pub(crate) branding: BrandingProperties,
}
impl Default for Configuration {
fn default() -> Self {
Self::new()
}
}
impl Configuration {
pub fn new() -> Self {
Self {
ms_client_id: get_ms_client_id(),
update_depth: UpdateDepth::Full,
censor_secrets: true,
disable_hardlinks: false,
branding: BrandingProperties::default(),
}
}
pub fn builder() -> ConfigBuilder {
ConfigBuilder::new()
}
}
pub struct ConfigBuilder {
config: Configuration,
}
impl ConfigBuilder {
pub fn new() -> Self {
Self {
config: Configuration::new(),
}
}
pub fn build(self) -> Configuration {
self.config
}
builder_method!(
ms_client_id,
ClientId,
"Set the Microsoft client ID to use for Microsoft / Xbox Live authentication"
);
builder_method!(
update_depth,
UpdateDepth,
"Set the depth at which to update files and versions"
);
builder_method!(
censor_secrets,
bool,
"Set whether to censor user credentials in output messages and logs"
);
builder_method!(
disable_hardlinks,
bool,
"Set whether to disable the use of hardlinks"
);
builder_method!(branding, BrandingProperties, "Set the branding properties");
}
impl Default for ConfigBuilder {
fn default() -> Self {
Self::new()
}
}
pub struct BrandingProperties {
pub(crate) launcher_name: String,
pub(crate) launcher_version: String,
}
impl Default for BrandingProperties {
fn default() -> Self {
Self {
launcher_name: "mcvm_core".into(),
launcher_version: env!("CARGO_PKG_VERSION").into(),
}
}
}
impl BrandingProperties {
pub fn new(name: String, version: String) -> Self {
Self {
launcher_name: name,
launcher_version: version,
}
}
}