handle non existent file
This commit is contained in:
parent
498a780854
commit
56e3138405
2 changed files with 8 additions and 2 deletions
|
@ -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()))
|
||||
|
|
|
@ -99,7 +99,13 @@ use ini::Ini;
|
|||
pub async fn get_games() -> Result<Vec<GameOption>, 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())?;
|
||||
|
||||
|
|
Loading…
Reference in a new issue