Skip to content

A fast file manager for Windows and macOS that never freezes: tabs, dual panes, archives as folders, Quick Look-style previews. A File Explorer and Finder alternative written in Rust.

1.8 KB
Raw Blame
// The version resource of rustyfiles-shellguard.exe.
fn main() {
    #[cfg(windows)]
    version_resource("rustyfiles shell guard", "rustyfiles-shellguard.exe");
}

/// The version resource (Properties > Details, and what code signing checks: every signed file names the product and its version).
/// Written into OUT_DIR with the crate's version, as rf-app does for rustyfiles.exe.
#[cfg(windows)]
fn version_resource(description: &str, file: &str) {
    let out = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap());
    let ver = std::env::var("CARGO_PKG_VERSION").unwrap();
    let n: Vec<u32> = ver.split(['.', '-', '+']).take(3).map(|p| p.parse().unwrap_or(0)).collect();
    let commas = format!("{},{},{},0", n.first().unwrap_or(&0), n.get(1).unwrap_or(&0), n.get(2).unwrap_or(&0));
    let rc = format!(
        "1 VERSIONINFO\nFILEVERSION {commas}\nPRODUCTVERSION {commas}\nFILEOS 0x40004\nFILETYPE {kind}\nBEGIN\n  BLOCK \"StringFileInfo\"\n  BEGIN\n    BLOCK \"040904B0\"\n    BEGIN\n      VALUE \"CompanyName\", \"Gelen Medya\"\n      VALUE \"FileDescription\", \"{description}\"\n      VALUE \"ProductName\", \"rustyfiles\"\n      VALUE \"FileVersion\", \"{ver}\"\n      VALUE \"ProductVersion\", \"{ver}\"\n      VALUE \"OriginalFilename\", \"{file}\"\n      VALUE \"LegalCopyright\", \"MIT License\"\n    END\n  END\n  BLOCK \"VarFileInfo\"\n  BEGIN\n    VALUE \"Translation\", 0x0409, 0x04B0\n  END\nEND\n",
        kind = if file.ends_with(".dll") { "0x2" } else { "0x1" },
    );
    let path = out.join("version.rc");
    std::fs::write(&path, rc).expect("write version.rc");
    // (the program only, not the library other crates link)
    embed_resource::compile_for(&path, ["rustyfiles-shellguard"], embed_resource::NONE).manifest_optional().expect("embed the version resource");
}