2023-10-05 12:09:05 -04:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
pub struct Config {
|
2024-05-11 13:41:00 -04:00
|
|
|
#[serde(default)]
|
2024-06-29 14:06:44 -04:00
|
|
|
pub worlds_open: bool,
|
|
|
|
|
|
|
|
#[serde(default)]
|
|
|
|
pub login_open: bool,
|
2024-05-11 13:41:00 -04:00
|
|
|
|
|
|
|
#[serde(default = "default_supported_platforms")]
|
|
|
|
pub supported_platforms: Vec<String>,
|
2024-06-29 14:44:13 -04:00
|
|
|
|
|
|
|
#[serde(default)]
|
|
|
|
pub boot_patches_location: String
|
2024-05-11 13:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Config {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
2024-06-29 14:06:44 -04:00
|
|
|
worlds_open: false,
|
|
|
|
login_open: false,
|
2024-06-29 14:44:13 -04:00
|
|
|
boot_patches_location: String::new(),
|
2024-05-11 13:41:00 -04:00
|
|
|
supported_platforms: default_supported_platforms()
|
2024-05-11 13:13:03 -04:00
|
|
|
}
|
|
|
|
}
|
2024-05-11 13:41:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Config {
|
|
|
|
pub fn supports_platform(&self, platform: &String) -> bool {
|
|
|
|
self.supported_platforms.contains(platform)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn default_supported_platforms() -> Vec<String> {
|
|
|
|
vec!["win32".to_string()]
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_config() -> Config {
|
|
|
|
if let Ok(data) = std::fs::read_to_string("config.json") {
|
|
|
|
serde_json::from_str(&data).expect("Failed to parse")
|
|
|
|
} else {
|
|
|
|
Config::default()
|
|
|
|
}
|
2023-10-05 12:09:05 -04:00
|
|
|
}
|