Struct winres::WindowsResource
[−]
[src]
pub struct WindowsResource { // some fields omitted }
Methods
impl WindowsResource
[src]
fn toolkit() -> Toolkit
fn new() -> Self
Create a new resource with version info struct
We initialize the resource file with values provided by cargo
Field | Cargo / Values |
---|---|
"FileVersion" |
package.version |
"ProductVersion" |
package.version |
"ProductName" |
package.name |
"FileDescription" |
package.description |
Furthermore if a section package.metadata.winres
exists
in Cargo.toml it will be parsed. Values in this section take precedence
over the values provided natively by cargo. Only the string table
of the version struct can be set this way.
[package.metadata.winres]
OriginalFilename = "testing.exe"
FileDescription = "⛄❤☕"
LegalCopyright = "Copyright © 2016"
The version info struct is set to some values sensible for creating an executable file.
Property | Cargo / Values |
---|---|
FILEVERSION |
package.version |
PRODUCTVERSION |
package.version |
FILEOS |
VOS_NT_WINDOWS32 (0x40004) |
FILETYPE |
VFT_APP (0x1) |
FILESUBTYPE |
VFT2_UNKNOWN (0x0) |
FILEFLAGSMASK |
VS_FFI_FILEFLAGSMASK (0x3F) |
FILEFLAGS |
0x0 |
Additionally, the language field is set to neutral (0), and no icon is set.
fn set<'a>(&mut self, name: &'a str, value: &'a str) -> &mut Self
Set string properties of the version info struct.
Possible field names are:
"FileVersion"
"FileDescription"
"ProductVersion"
"ProductName"
"OriginalFilename"
"LegalCopyright"
"LegalTrademark"
"CompanyName"
"Comments"
"InternalName"
Additionally there exists
"PrivateBuild"
, "SpecialBuild"
which should only be set, when the FILEFLAGS
property is set to
VS_FF_PRIVATEBUILD(0x08)
or VS_FF_SPECIALBUILD(0x20)
It is possible to use arbirtrary field names, but Windows Explorer and other tools might not show them.
fn set_toolkit_path<'a>(&mut self, path: &'a str) -> &mut Self
Set the correct path for the toolkit.
For the GNU toolkit this has to be the path where MinGW
put windres.exe
and ar.exe
. This could be something like:
"C:\Program Files\mingw-w64\x86_64-5.3.0-win32-seh-rt_v4-rev0\mingw64\bin"
For MSVC the Windows SDK has to be installed. It comes with the resource compiler
rc.exe
. This should be set to the root directory of the Windows SDK, e.g.,
"C:\Program Files (x86)\Windows Kits\10
fn set_language(&mut self, language: u16) -> &mut Self
Set the user interface language of the file
For possible values take a look at the MSDN page for resource files, we only included some values here.
Language | Value |
---|---|
Neutral | 0x0000 |
English | 0x0009 |
English (US) | 0x0409 |
English (GB) | 0x0809 |
German | 0x0407 |
German (AT) | 0x0c07 |
French | 0x000c |
French (FR) | 0x040c |
Catalan | 0x0003 |
Basque | 0x042d |
Breton | 0x007e |
Scottish Gaelic | 0x0091 |
Romansch | 0x0017 |
I know that some of these languages are used less often, but they were not included in many other lists.
fn set_icon<'a>(&mut self, path: &'a str) -> &mut Self
Set an icon filename
This icon need to be in ico
format. The filename can be absolute
or relative to the projects root.
fn set_version_info(&mut self, field: VersionInfo, value: u64) -> &mut Self
Set a version info struct property Currently we only support numeric values, you have to look them up.
fn set_manifest<'a>(&mut self, manifest: &'a str) -> &mut Self
Set the embedded manifest file
Example
The following manifest will brand the exe as requesting administrator privileges. Thus every time it is executed, a Windows UAC dialog will apear.
let mut res = winres::WindowsResource::new(); res.set_manifest(" <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>");
fn set_manifest_file<'a>(&mut self, file: &'a str) -> &mut Self
Some as set_manifest()
but a filename can be provided and
file is included by the resource compieler itself.
This method works the same way as set_icon()
fn write_resource_file<P: AsRef<Path>>(&self, path: P) -> Result<()>
Write a resource file with the set values
fn set_resource_file<'a>(&mut self, path: &'a str) -> &mut Self
Set a path to an already existing resource file.
We will neither modify this file nor parse its contents. This function simply replaces the internaly generated resource file that is passed to the compiler. You can use this function to write a resource file yourself.
fn set_output_directory<'a>(&mut self, path: &'a str) -> &mut Self
Override the output directoy.
As a default, we use %OUT_DIR%
set by cargo, but it can be necessary to override the
the setting.
fn compile(&self) -> Result<()>
Run the resource compiler
This function generates a resource file from the settings, or uses an existing resource file and passes it to the resource compiler of your toolkit.
Further more we will print the correct statements for
cargo:rustc-link-lib=
and cargo:rustc-link-search
on the console,
so that the cargo build script can link the compiled resource file.