diff --git a/backend/src/planetwars/mod.rs b/backend/src/planetwars/mod.rs index f76666c..aad2c55 100644 --- a/backend/src/planetwars/mod.rs +++ b/backend/src/planetwars/mod.rs @@ -193,7 +193,7 @@ impl game::Controller for PlanetWarsGame { fn is_done(&mut self) -> bool { if self.state.is_finished() { - let mut f = match OpenOptions::new().append(true).open("games.ini") { Err(_) => return true, Ok(f) => f }; + let mut f = match OpenOptions::new().create(true).append(true).open("games.ini") { Err(_) => return true, Ok(f) => f }; let mut conf = Ini::new(); conf.with_section(Some(self.log_file_loc.clone())) diff --git a/backend/src/util.rs b/backend/src/util.rs index c21e921..b3fe487 100644 --- a/backend/src/util.rs +++ b/backend/src/util.rs @@ -99,7 +99,13 @@ use ini::Ini; pub async fn get_games() -> Result, String> { let mut games = Vec::new(); - let content = fs::read_to_string("games.ini").await.map_err(|_| "IO error".to_string())?; + let content = match fs::read_to_string("games.ini").await { + Ok(v) => v, + Err(_) => { + fs::File::create("games.ini").await.map_err(|_| "IO Error".to_string())?; + String::new() + } + }; let i = Ini::load_from_str(&content).map_err(|_| "Corrupt ini file".to_string())?;