Use absolute paths when including resources. (Fixes #53)
This commit is contained in:
parent
8d95965d40
commit
e96ec620fb
|
@ -1,6 +1,6 @@
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::Path;
|
use std::path::{Path, PathBuf};
|
||||||
use std::io::BufWriter;
|
use std::io::BufWriter;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
|
@ -15,23 +15,27 @@ fn main() {
|
||||||
let mut file = BufWriter::new(fs::File::create(&dest.join("resources.rs")).unwrap());
|
let mut file = BufWriter::new(fs::File::create(&dest.join("resources.rs")).unwrap());
|
||||||
write!(file, "pub fn get_file(name: &str) -> Option<&'static [u8]> {{\n").unwrap();
|
write!(file, "pub fn get_file(name: &str) -> Option<&'static [u8]> {{\n").unwrap();
|
||||||
write!(file, " match name {{\n").unwrap();
|
write!(file, " match name {{\n").unwrap();
|
||||||
for entry in &out {
|
for path in &out {
|
||||||
let entry = entry.replace("\\", "/");
|
let mut absolute_path = std::env::current_dir().unwrap();
|
||||||
let short = &entry;
|
absolute_path.push(path);
|
||||||
write!(file, " {:?} => Some(include_bytes!(\"../{}\")),\n", short, entry).unwrap();
|
|
||||||
|
let absolute = absolute_path.to_str().unwrap().replace("\\", "/");
|
||||||
|
let relative = path.to_str().unwrap().replace("\\", "/");
|
||||||
|
|
||||||
|
write!(file, " {:?} => Some(include_bytes!(\"{}\")),\n", relative, absolute).unwrap();
|
||||||
}
|
}
|
||||||
write!(file, " _ => None\n }}\n}}\n").unwrap();
|
write!(file, " _ => None\n }}\n}}\n").unwrap();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_map(out: &mut Vec<String>, path: &Path) {
|
fn build_map(out: &mut Vec<PathBuf>, path: &Path) {
|
||||||
let files = fs::read_dir(path).unwrap();
|
let files = fs::read_dir(path).unwrap();
|
||||||
for entry in files {
|
for entry in files {
|
||||||
let entry = entry.unwrap();
|
let entry = entry.unwrap();
|
||||||
if fs::metadata(entry.path()).unwrap().is_dir() {
|
if fs::metadata(entry.path()).unwrap().is_dir() {
|
||||||
build_map(out, &entry.path());
|
build_map(out, &entry.path());
|
||||||
} else {
|
} else {
|
||||||
out.push(entry.path().to_str().unwrap().to_owned());
|
out.push(entry.path());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue