fn main() -> std::io::Result<()> {
    println!("cargo:rerun-if-changed=build.rs");
    let target_os = std::env::var("CARGO_CFG_TARGET_OS");
    if target_os.as_deref() == Ok("windows") {
        let name = "Avii's Virtual Airline Manager";
        let version = env!("CARGO_PKG_VERSION");
        let mut sv = version.split('.').collect::<Vec<_>>();
        while sv.len() < 4 {
            sv.push("0");
        }
        let file_version = format!("{}, {}, {}, {}", sv[0], sv[1], sv[2], sv[3]);
        windres::Build::new()
            .define(
                "THE_FILE",
                Some(format!(r#""{name} Client Module""#).as_str()),
            )
            .define("THE_PROJECT", Some(format!(r#""{name}""#).as_str()))
            .define("THE_VERSION", Some(format!(r#""{version}""#).as_str()))
            .define("THE_FILEVERSION", Some(file_version.as_str()))
            .compile("res/resource.rc")?;
        for entry in std::fs::read_dir("res")? {
            let entry = entry?;
            println!("cargo:rerun-if-changed={}", entry.path().display());
        }
    }
    Ok(())
}
