-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
40 lines (33 loc) · 988 Bytes
/
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
use std::{
env,
error::Error,
fs::File,
io::{BufWriter, Write},
};
fn main() -> Result<(), Box<dyn Error>> {
let mut config_file =
BufWriter::new(File::create(format!("{}/config.rs", env::var("OUT_DIR")?))?);
write!(
config_file,
r#"pub const EXTENSION: &str = "{}";"#,
String::from("qs")
)?;
#[cfg(windows)]
windows_part()?;
Ok(())
}
#[cfg(windows)]
fn windows_part() -> Result<(), Box<dyn Error>> {
use std::{path::PathBuf, str::FromStr};
let mut resources = winres::WindowsResource::new();
println!("cargo:rerun-if-changed=resources/icon.png");
if PathBuf::from_str("resources/icon.png")?.exists() {
let image = image::open("resources/icon.png")?;
image
.thumbnail(256, 256)
.save(format!("{}/icon.ico", env::var("OUT_DIR")?))?;
resources.set_icon(&format!("{}/icon.ico", env::var("OUT_DIR")?));
};
resources.compile()?;
Ok(())
}