Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Set locations for config file and search / wordgen plugin dirs
- */
- use std::env::{var, current_dir};
- use std::fs::{create_dir_all, File};
- use std::io::{Write, ErrorKind::NotFound};
- use std::path::Path;
- fn main() {
- // you can change where plugins / config live and their names by editing the values below:
- let PATH: &str = ¤t_dir().unwrap().to_str().unwrap().to_owned(); // where these live
- let PLUG: &str = "crabwalk"; // plugin dir name
- let SRCH: &str = "searches"; // search dir name
- let WGEN: &str = "wordgen"; // wordgen dir name
- let CONF: &str = "conf.txt"; // config file name
- let out_dir = var("OUT_DIR").unwrap();
- // generate build files - these will be used by the precompiler to set the locations of
- // the stuff we're creating. if you want to change anything about the plug dirs or
- // config file, you're in the wrong place.
- let pout_dir = Path::new(&out_dir);
- File::create(&pout_dir.join("path")).unwrap().write_all(PATH.as_bytes()).unwrap();
- File::create(&pout_dir.join("plug")).unwrap().write_all(PLUG.as_bytes()).unwrap();
- File::create(&pout_dir.join("srch")).unwrap().write_all(SRCH.as_bytes()).unwrap();
- File::create(&pout_dir.join("wgen")).unwrap().write_all(WGEN.as_bytes()).unwrap();
- File::create(&pout_dir.join("conf")).unwrap().write_all(CONF.as_bytes()).unwrap();
- // generate plugin dirs if they don't exist
- let ppath = Path::new(PATH);
- create_dir_all(&ppath.join(PLUG).join(SRCH)).unwrap();
- create_dir_all(&ppath.join(PLUG).join(WGEN)).unwrap();
- // generate configuration file if it doesn't exist (this is the place to change the default file contents)
- let pconf = Path::new(PATH).join(CONF);
- if let Err(e) = File::open(&pconf) {
- if e.kind() == NotFound {
- File::create(&pconf).unwrap().write_all(
- b""
- );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement