forked from max-niederman/ttyper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
54 lines (45 loc) · 1.58 KB
/
build.rs
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use std::env;
use std::fs;
use std::path::{Path, PathBuf};
fn copy<U: AsRef<Path>, V: AsRef<Path>>(from: U, to: V) -> std::io::Result<()> {
let mut stack = vec![PathBuf::from(from.as_ref())];
let output_root = PathBuf::from(to.as_ref());
let input_root = PathBuf::from(from.as_ref()).components().count();
while let Some(working_path) = stack.pop() {
// Generate a relative path
let src: PathBuf = working_path.components().skip(input_root).collect();
// Create a destination if missing
let dest = if src.components().count() == 0 {
output_root.clone()
} else {
output_root.join(&src)
};
if fs::metadata(&dest).is_err() {
fs::create_dir_all(&dest)?;
}
for entry in fs::read_dir(working_path)? {
let entry = entry?;
let path = entry.path();
if path.is_dir() {
stack.push(path);
} else if let Some(filename) = path.file_name() {
let dest_path = dest.join(filename);
fs::copy(&path, &dest_path)?;
}
}
}
Ok(())
}
#[allow(unused_must_use)]
fn main() -> std::io::Result<()> {
let install_path = dirs::config_dir()
.expect("Couldn't find a configuration directory to install to.")
.join("ttyper");
fs::create_dir_all(&install_path);
let resources_path = env::current_dir()
.expect("Couldn't find the source directory.")
.join("resources")
.join("runtime");
copy(resources_path, &install_path);
Ok(())
}