-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
57 lines (54 loc) · 2.07 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
55
56
57
use std::fs::{ read_dir, read_to_string, write, File };
use std::io::Write;
use std::env;
use std::path::Path;
use blake2::{ Blake2b512, Digest };
use bmp_rust::bmp::BMP;
fn font_chars_to_alphas(dir: &str) {
for entry in read_dir(dir).unwrap() {
let path = entry.unwrap().path();
let file_name = path.file_name().unwrap().to_str().unwrap().to_string();
let file_name: Vec<&str> = file_name.split(".").collect();
if file_name[1] == "bmp" {
if !path.is_dir() {
let mut ch: Vec<Vec<String>> = Vec::new();
let b = BMP::new_from_file(&path.clone().into_os_string().into_string().unwrap());
let dib_header = b.get_dib_header().unwrap();
let width = dib_header.width as usize;
let height = dib_header.height as usize;
for y in 0..height {
let mut row = Vec::new();
for x in 0..width {
let pixel_color = b.get_color_of_px(x, y).unwrap();
//if black, true
row.push(pixel_color[3].to_string()); //push alpha channel
}
ch.push(row);
}
let ch: Vec<String> = ch.into_iter().map(|row| {
row.join(",")
}).collect();
let chars: Vec<char> = file_name[0].chars().collect();
File::create(dir.to_string() + "/" + &chars[0].to_string() + ".alpha").unwrap().write_all(
(chars[1].to_string() + "\n" + &ch.join("\n")).as_bytes()
).unwrap();
}
}
}
}
fn main() {
//hash + "salt" password and add to build
let password = read_to_string("password.txt").unwrap_or("password".to_string()).replace("\n", "") + "salt?sorrycryptographers";
let mut hasher = Blake2b512::new();
hasher.update(password.as_bytes());
let out_dir = env::var_os("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("password.rs");
write(&dest_path, format!("pub const PASSWORD_HASH: [u8; 64] = {:?};", hasher.finalize())).unwrap();
//process bmps
for entry in read_dir("./bmps").unwrap() {
let path = entry.unwrap().path();
if path.is_dir() {
font_chars_to_alphas(path.to_str().unwrap());
}
}
}