Advertisement
Guest User

Untitled

a guest
Nov 1st, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 1.90 KB | None | 0 0
  1. /*
  2. Set locations for config file and search / wordgen plugin dirs
  3. */
  4.  
  5. use std::env::{var, current_dir};
  6. use std::fs::{create_dir_all, File};
  7. use std::io::{Write, ErrorKind::NotFound};
  8. use std::path::Path;
  9.  
  10. fn main() {
  11.     // you can change where plugins / config live and their names by editing the values below:
  12.  
  13.     let PATH: &str = &current_dir().unwrap().to_str().unwrap().to_owned(); // where these live
  14.     let PLUG: &str = "crabwalk"; // plugin dir name
  15.     let SRCH: &str = "searches"; // search dir name
  16.     let WGEN: &str = "wordgen";  // wordgen dir name
  17.     let CONF: &str = "conf.txt"; // config file name
  18.  
  19.     let out_dir = var("OUT_DIR").unwrap();
  20.  
  21.     // generate build files - these will be used by the precompiler to set the locations of
  22.     // the stuff we're creating. if you want to change anything about the plug dirs or
  23.     // config file, you're in the wrong place.
  24.     let pout_dir = Path::new(&out_dir);
  25.     File::create(&pout_dir.join("path")).unwrap().write_all(PATH.as_bytes()).unwrap();
  26.     File::create(&pout_dir.join("plug")).unwrap().write_all(PLUG.as_bytes()).unwrap();
  27.     File::create(&pout_dir.join("srch")).unwrap().write_all(SRCH.as_bytes()).unwrap();
  28.     File::create(&pout_dir.join("wgen")).unwrap().write_all(WGEN.as_bytes()).unwrap();
  29.     File::create(&pout_dir.join("conf")).unwrap().write_all(CONF.as_bytes()).unwrap();
  30.  
  31.     // generate plugin dirs if they don't exist
  32.     let ppath = Path::new(PATH);
  33.     create_dir_all(&ppath.join(PLUG).join(SRCH)).unwrap();
  34.     create_dir_all(&ppath.join(PLUG).join(WGEN)).unwrap();
  35.  
  36.     // generate configuration file if it doesn't exist (this is the place to change the default file contents)
  37.     let pconf = Path::new(PATH).join(CONF);
  38.     if let Err(e) = File::open(&pconf) {
  39.         if e.kind() == NotFound {
  40.             File::create(&pconf).unwrap().write_all(
  41.                 b""
  42.             );
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement