mirror of
https://github.com/GyulyVGC/sniffnet.git
synced 2025-12-23 22:29:01 -05:00
first implementation of services load using phf
This commit is contained in:
45
build.rs
45
build.rs
@@ -1,12 +1,45 @@
|
||||
#[cfg(windows)]
|
||||
extern crate winres;
|
||||
|
||||
#[cfg(windows)]
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::io::{BufRead, BufReader, BufWriter, Write};
|
||||
use std::path::Path;
|
||||
|
||||
fn main() {
|
||||
let mut res = winres::WindowsResource::new();
|
||||
res.set_icon("resources/packaging/windows/graphics/sniffnet.ico");
|
||||
res.compile().unwrap();
|
||||
set_icon();
|
||||
|
||||
build_services_phf();
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn main() {}
|
||||
fn set_icon() {
|
||||
#[cfg(windows)]
|
||||
{
|
||||
let mut res = winres::WindowsResource::new();
|
||||
res.set_icon("resources/packaging/windows/graphics/sniffnet.ico");
|
||||
res.compile().unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
fn build_services_phf() {
|
||||
let path = Path::new(&env::var("OUT_DIR").unwrap()).join("services.rs");
|
||||
let mut file = BufWriter::new(File::create(&path).unwrap());
|
||||
|
||||
let mut services_map = phf_codegen::Map::new();
|
||||
|
||||
let input = BufReader::new(File::open("./services.txt").unwrap());
|
||||
for line in input.lines().flatten() {
|
||||
let mut parts = line.split("\t");
|
||||
let service = format!("\"{}\"", parts.next().unwrap());
|
||||
let key = parts.next().unwrap().to_uppercase();
|
||||
services_map.entry(key, &*service);
|
||||
}
|
||||
|
||||
write!(
|
||||
&mut file,
|
||||
"static SERVICES: phf::Map<&'static str, &'static str> = {}",
|
||||
services_map.build()
|
||||
)
|
||||
.unwrap();
|
||||
write!(&mut file, ";\n").unwrap();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user