1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use std;
use std::io::Write;
extern crate glob;
use self::glob::{glob,GlobError};
use std::fs::File;
use std::path::Path;
use std::io::prelude::*;

macro_rules! read_entry {
   ($f: ident, $p: ident) => (
      match $p {
         Ok(path) => {
            let mut in_file = File::open(path.clone()).expect("asset file");
            let mut contents = Vec::new();
            in_file.read_to_end(&mut contents).expect("read file");
            let path = path.strip_prefix("src").expect("src prefix");
            let path = path.to_str().unwrap();
            let path = format!("\"{}\"", path);
            $f.write_all( format!("({},include_bytes!({}).to_vec()),", path, path).as_bytes() ).expect("file write");

         }
         Err(e) => println!("{:?}", e),
      }
   );
}

pub fn with_assets() {
   let mut out_file = File::create("src/assets.in").expect("file open");
   out_file.write_all( b"[" ).expect("file write");
   for entry in glob("src/assets/**/*.png").expect("Failed to read glob pattern") {
      read_entry!(out_file, entry)
   }
   for entry in glob("src/assets/**/*.ttf").expect("Failed to read glob pattern") {
      read_entry!(out_file, entry)
   }
   out_file.write_all( b"]" ).expect("file write");
}
pub fn with_all() {
   with_assets()
}