Skip to content

Instantly share code, notes, and snippets.

@WeaponMan
Created July 11, 2020 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WeaponMan/152fd45d2c34bc96eaf834b46bf1aa87 to your computer and use it in GitHub Desktop.
Save WeaponMan/152fd45d2c34bc96eaf834b46bf1aa87 to your computer and use it in GitHub Desktop.
Windows Resources version rust
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
#[cfg(any(windows))]
fn main() {
use std::path::Path;
use std::fs::File;
use std::io::Write;
let file = "Resources.rc";
let file_path = Path::new(file);
let major = env!("CARGO_PKG_VERSION_MAJOR");
let minor = env!("CARGO_PKG_VERSION_MINOR");
let patch = env!("CARGO_PKG_VERSION_PATCH");
let mut src = File::create(&file_path).unwrap();
let new_resource = format!(r#"
#define RT_MANIFEST 24
#define APP_VERSION "{}.{}.{}.0"
#define APP_VERSION_2 {},{},{},0
1 RT_MANIFEST "app-name.exe.manifest"
1 VERSIONINFO
FILEVERSION APP_VERSION_2
PRODUCTVERSION APP_VERSION_2
FILEOS 0x4
FILETYPE 0x1
{{
BLOCK "StringFileInfo"
{{
BLOCK "000004b0"
{{
VALUE "Comments", ""
VALUE "CompanyName", "Company ltd"
VALUE "FileDescription", "App description"
VALUE "FileVersion", APP_VERSION
VALUE "InternalName", "app-name.exe"
VALUE "LegalCopyright", "Copyright \xA9"
VALUE "LegalTrademarks", ""
VALUE "OriginalFilename", "app-name.exe"
VALUE "ProductName", "App product name"
VALUE "ProductVersion", APP_VERSION
VALUE "Assembly Version", APP_VERSION
}}
}}
BLOCK "VarFileInfo"
{{
VALUE "Translation", 0x0000 0x04B0
}}
}}
"#, major, minor, patch, major, minor, patch);
src.write_all(new_resource.as_bytes()).unwrap();
src.flush().unwrap();
drop(src);
embed_resource::compile("Resources.rc");
}
#[cfg(not(windows))]
fn main() {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment