commit d51286b2d1ea4f5be109ed6d76f006a0637d1873 from: the xhr date: Tue Oct 19 14:53:58 2021 UTC More string work commit - 6e9ad3b1d5f0edc4e4faa842bbdbf49a91f09569 commit + d51286b2d1ea4f5be109ed6d76f006a0637d1873 blob - 44bc31887f4caf96315ba36c23d1c25f8b560ae2 blob + 5fbe349ec64c01c5da245119913a5f43f9972142 --- src/main.rs +++ src/main.rs @@ -1,6 +1,7 @@ #[macro_use] extern crate log; extern crate env_logger; +use std::fs; use rustyline::error::ReadlineError; use rustyline::Editor; use std::env; @@ -41,7 +42,7 @@ impl Game { } fn init_path(&mut self) { - let home = match env::var("XDG_HOME") { + let mut home = match env::var("XDG_HOME") { Ok(val) => val, Err(_) => match env::var("HOME") { Ok(val) => val, @@ -49,17 +50,27 @@ impl Game { }, }; - log::info!("var is set to {}", home); + self.sfpath = home + "/.sflogbook/"; + log::info!("sfpath is set to {}", self.sfpath); + + let attr = match fs::metadata(self.sfpath.as_str()) { + Ok(_) => log::info!("home directory exists"), + Err(_) => match fs::create_dir_all(self.sfpath.as_str()) { + Ok(_) => log::info!("Successfully created {}", self.sfpath), + Err(e) => log::error!("Cannot create {}: {}", self.sfpath, e), + }, + }; } fn load_history(&mut self) { - if self.rl.load_history("history.txt").is_err() { + let hp = self.sfpath.push_str("history"); + if self.rl.load_history(hp).is_err() { println!("No previous history."); } } fn shutdown(&mut self) { - self.rl.save_history("history.txt").unwrap(); + self.rl.save_history("history").unwrap(); std::process::exit(0) } @@ -68,7 +79,6 @@ impl Game { fn main() { env_logger::init(); let mut game = Game::new(); - log::info!("Hallo"); game.init();