From 6a136ac842dd601ce7f68566c27b5262d221872c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Wed, 21 Oct 2020 00:57:37 +0200 Subject: default cfg is option None if the file doesn't exist --- mumd/src/state.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'mumd') diff --git a/mumd/src/state.rs b/mumd/src/state.rs index 08724dd..0dbf9c5 100644 --- a/mumd/src/state.rs +++ b/mumd/src/state.rs @@ -22,7 +22,7 @@ pub enum StatePhase { } pub struct State { - config: Config, + config: Option, server: Option, audio: Audio, @@ -39,7 +39,7 @@ impl State { ) -> Self { let audio = Audio::new(); let mut state = Self { - config: mumlib::config::read_default_cfg().expect("format error in config file"), + config: mumlib::config::read_default_cfg(), server: None, audio, packet_sender, @@ -208,12 +208,16 @@ impl State { } pub fn reload_config(&mut self) { - self.config = mumlib::config::read_default_cfg() - .expect("format error in config file"); - if let Some(audio_config) = &self.config.audio { - if let Some(input_volume) = audio_config.input_volume { - self.audio.set_input_volume(input_volume); + if let Some(config) = mumlib::config::read_default_cfg() { + self.config = Some(config); + let config = &self.config.as_ref().unwrap(); + if let Some(audio_config) = &config.audio { + if let Some(input_volume) = audio_config.input_volume { + self.audio.set_input_volume(input_volume); + } } + } else { + warn!("config file not found"); } } @@ -224,10 +228,6 @@ impl State { .unwrap(); } - pub fn config(&self) -> &Config { - &self.config - } - pub fn audio(&self) -> &Audio { &self.audio } -- cgit v1.2.1