Files
JoyD/Windows/CS/Framework4.0/Updater/build.rs
2026-05-07 10:45:18 +08:00

26 lines
1.0 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

use winresource::VersionInfo;
extern crate winresource;
fn main() {
let version_str = "1.0.0.5";
let mut res = winresource::WindowsResource::new();
// 字符串表(文件属性对话框显示的值)
res.set("FileVersion", version_str);
res.set("ProductVersion", version_str);
// 从字符串自动解析版本号到二进制结构
let mut parts = version_str.split('.');
let major: u64 = parts.next().and_then(|s| s.parse().ok()).unwrap_or(0);
let minor: u64 = parts.next().and_then(|s| s.parse().ok()).unwrap_or(0);
let patch: u64 = parts.next().and_then(|s| s.parse().ok()).unwrap_or(0);
let pre: u64 = parts.next().and_then(|s| s.parse().ok()).unwrap_or(0);
// 二进制结构VERSIONINFO 的 FILEVERSION / PRODUCTVERSION
// 格式: Major<<48 | Minor<<32 | Patch<<16 | Pre
let ver: u64 = (major << 48) | (minor << 32) | (patch << 16) | pre;
res.set_version_info(VersionInfo::FILEVERSION, ver);
res.set_version_info(VersionInfo::PRODUCTVERSION, ver);
res.compile().unwrap();
}