diff --git a/src/conf.rs b/src/conf.rs index 15a4619..dbb0f87 100644 --- a/src/conf.rs +++ b/src/conf.rs @@ -2,19 +2,27 @@ use std::fs::File; use std::io::prelude::*; use std::path::Path; +mod defaltConf; -pub fn check(fileLocation: str){ + +pub fn checkAndCreateIfNeeded(fileLocation: str) -> File{ let confPath = Path::new(fileLocation); let confDisplay = confPath.display(); let mut confFile = match File::open(&confPath){ - Err(why) => - - } + Err(why) => createConf(fileLocation), + Ok(conf) => confFile, + }; } fn createConf(fileLocation: str){ - - + let confPath = Path::new(fileLocation); + let confDisplay = confPath.display(); + let mut confFile = match File::create(&path){ + Err(why) => panic!("couldn't create {}: {}", display, why), + Ok(file) => file, + }; + match confFile.write_all(defaltConf::getDefaultConf()); + return checkAndCreateIfNeeded(); } \ No newline at end of file diff --git a/src/defaultConf.rs b/src/defaultConf.rs new file mode 100644 index 0000000..447ef4e --- /dev/null +++ b/src/defaultConf.rs @@ -0,0 +1,11 @@ +static DEFAULTCONF &str = " + + + + +" + + +pub fn getDefaultConf() -> str{ + return DEFAULTCONF; +} \ No newline at end of file