mirror of
https://github.com/tauri-apps/winres.git
synced 2026-01-31 00:45:22 +01:00
rename crate and update readme
This commit is contained in:
@@ -1,10 +0,0 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
charset = utf-8
|
||||
|
||||
[*.rs]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
15
Cargo.toml
15
Cargo.toml
@@ -1,18 +1,21 @@
|
||||
[package]
|
||||
name = "winres"
|
||||
name = "tauri-winres"
|
||||
description = "Create and set windows icons and metadata for executables"
|
||||
version = "0.1.11"
|
||||
authors = ["Max Resch <resch.max@gmail.com>"]
|
||||
version = "0.1.0"
|
||||
authors = [
|
||||
"Tauri Programme within The Commons Conservancy",
|
||||
"Max Resch <resch.max@gmail.com>"
|
||||
]
|
||||
license = "MIT"
|
||||
repository = "https://github.com/mxre/winres"
|
||||
documentation= "https://docs.rs/winres/*/winres/"
|
||||
repository = "https://github.com/tauri-apps/winres"
|
||||
documentation= "https://docs.rs/tauri-winres/"
|
||||
|
||||
[lib]
|
||||
path = "lib.rs"
|
||||
|
||||
[dependencies]
|
||||
toml = "0.5"
|
||||
version_check = "0.9.4"
|
||||
version_check = "0.9"
|
||||
|
||||
[dev-dependencies]
|
||||
# used for tests
|
||||
|
||||
5
LICENSE
5
LICENSE
@@ -1,4 +1,7 @@
|
||||
Copyright 2016 Max Resch
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2023 - Present Tauri Apps Contributors
|
||||
Copyright (c) 2016 Max Resch
|
||||
|
||||
Permission is hereby granted, free of charge, to any
|
||||
person obtaining a copy of this software and associated
|
||||
|
||||
86
README.md
86
README.md
@@ -1,28 +1,28 @@
|
||||
# winres
|
||||
# tauri-winres
|
||||
|
||||
A simple library to facilitate adding metainformation and icons to windows
|
||||
executables and dynamic libraries.
|
||||
A simple library to facilitate adding [Resources](<https://en.wikipedia.org/wiki/Resource_(Windows)>) (metainformation and icons) to [Portable Executables](https://en.wikipedia.org/wiki/Portable_Executable) (Windows executables and dynamic libraries).
|
||||
|
||||
[Documentation](https://docs.rs/winres/*/winres/)
|
||||
Note: `tauri-winres` is a fork of [winres](https://github.com/mxre/winres) which no longer works on Rust 1.61 or higher and has been [left unmaintained](https://github.com/mxre/winres/issues/40).
|
||||
|
||||
[Documentation](https://docs.rs/tauri-winres/)
|
||||
|
||||
## Toolkit
|
||||
|
||||
Before we begin you need to have the approptiate tools installed.
|
||||
- `rc.exe` from the [Windows SDK]
|
||||
- `windres.exe` and `ar.exe` from [minGW64]
|
||||
|
||||
[Windows SDK]: https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk
|
||||
[minGW64]: http://mingw-w64.org
|
||||
Before we begin you need to have the appropriate tools installed.
|
||||
|
||||
If you are using Rust with the MSVC ABI you will need the Windows SDK
|
||||
for the GNU ABI you'll need minGW64.
|
||||
- `rc.exe` from the [Windows SDK]
|
||||
- `windres.exe` and `ar.exe` from [minGW64]
|
||||
|
||||
[windows sdk]: https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk
|
||||
[mingw64]: http://mingw-w64.org
|
||||
|
||||
If you are using Rust with the MSVC ABI you will need the Windows SDK for the GNU ABI you'll need minGW64.
|
||||
|
||||
Windows SDK can be found in the registry, minGW64 has to be in the path.
|
||||
|
||||
## Using winres
|
||||
## Using tauri-winres
|
||||
|
||||
First, you will need to add a build script to your crate (`build.rs`)
|
||||
by adding it to your crate's `Cargo.toml` file:
|
||||
First, you will need to add a build script to your crate (`build.rs`) by adding it to your crate's `Cargo.toml` file:
|
||||
|
||||
```toml
|
||||
[package]
|
||||
@@ -30,36 +30,26 @@ by adding it to your crate's `Cargo.toml` file:
|
||||
build = "build.rs"
|
||||
|
||||
[build-dependencies]
|
||||
winres = "0.1"
|
||||
tauri-winres = "0.1"
|
||||
```
|
||||
|
||||
Next, you have to write a build script. A short
|
||||
example is shown below.
|
||||
Next, you have to write a build script. A short example is shown below.
|
||||
|
||||
```rust
|
||||
// build.rs
|
||||
|
||||
extern crate winres;
|
||||
|
||||
fn main() {
|
||||
if cfg!(target_os = "windows") {
|
||||
let mut res = winres::WindowsResource::new();
|
||||
if std::env::var("CARGO_CFG_TARGET_OS").unwrap() == "windows" {
|
||||
let mut res = tauri_winres::WindowsResource::new();
|
||||
res.set_icon("test.ico");
|
||||
res.compile().unwrap();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Thats it. The file `test.ico` should be located in the same directory as `build.rs`.
|
||||
Metainformation (like program version and description) is taken from `Cargo.toml`'s `[package]`
|
||||
section.
|
||||
That's it. The file `test.ico` should be located in the same directory as `build.rs`. Metainformation (like program version and description) is taken from `Cargo.toml`'s `[package]` section.
|
||||
|
||||
Note that using this crate on non windows platform is undefined behavior. It does not contain
|
||||
safeguards against doing so. None-the-less it will compile; however `build.rs`, as shown above, should contain
|
||||
a `cfg` option.
|
||||
|
||||
Another possibility is using `cfg` as a directive to avoid building `winres` on unix platforms
|
||||
alltogether. This will save build time. So the example from before could look like this
|
||||
Note that support for using this crate on non windows platforms is experimental. It is recommended to only use `tauri-winres` on Windows hosts, by using `cfg` as a directive to avoid building `tauri-winres` on unix platforms alltogether.
|
||||
|
||||
```toml
|
||||
[package]
|
||||
@@ -67,58 +57,48 @@ alltogether. This will save build time. So the example from before could look li
|
||||
build = "build.rs"
|
||||
|
||||
[target.'cfg(windows)'.build-dependencies]
|
||||
winres = "0.1"
|
||||
tauri-winres = "0.1"
|
||||
```
|
||||
|
||||
Next, you have to write a build script. A short
|
||||
example is shown below.
|
||||
Next, you have to write a build script. A short example is shown below.
|
||||
|
||||
```rust
|
||||
// build.rs
|
||||
|
||||
#[cfg(windows)]
|
||||
extern crate winres;
|
||||
|
||||
#[cfg(windows)]
|
||||
fn main() {
|
||||
let mut res = winres::WindowsResource::new();
|
||||
let mut res = tauri_winres::WindowsResource::new();
|
||||
res.set_icon("test.ico");
|
||||
res.compile().unwrap();
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn main() {
|
||||
}
|
||||
fn main() {}
|
||||
```
|
||||
|
||||
## Additional Options
|
||||
|
||||
For added convenience, `winres` parses, `Cargo.toml` for a `package.metadata.winres` section:
|
||||
For added convenience, `tauri-winres` parses `Cargo.toml` for a `package.metadata.tauri-winres` section:
|
||||
|
||||
```toml
|
||||
[package.metadata.winres]
|
||||
[package.metadata.tauri-winres]
|
||||
OriginalFilename = "PROGRAM.EXE"
|
||||
LegalCopyright = "Copyright © 2016"
|
||||
#...
|
||||
```
|
||||
|
||||
This section may contain arbitrary string key-value pairs, to be included
|
||||
in the version info section of the executable/library file.
|
||||
This section may contain arbitrary string key-value pairs, to be included in the version info section of the executable/library file.
|
||||
|
||||
The following keys have special meanings and will be shown in the file properties
|
||||
of the Windows Explorer:
|
||||
The following keys have special meanings and will be shown in the file properties of the Windows Explorer:
|
||||
|
||||
`FileDescription`, `ProductName`, `ProductVersion`, `OriginalFilename` and `LegalCopyright`
|
||||
|
||||
See [MSDN]
|
||||
for more details on the version info section of executables/libraries.
|
||||
See [MSDN] for more details on the version info section of executables/libraries.
|
||||
|
||||
[MSDN]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa381058.aspx
|
||||
[msdn]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa381058.aspx
|
||||
|
||||
## About this project
|
||||
|
||||
I've written this crate chiefly for my personal projects and although I've tested it
|
||||
on my personal computers I have no idea if the behaviour is the same everywhere.
|
||||
The [original author](https://github.com/mxre) and maintainers use this crate for their personal projects and although is has been tested in that context, we have no idea if the behaviour is the same everywhere.
|
||||
|
||||
To be brief, I'm very much reliant on your bug reports and feature suggestions
|
||||
to make this crate better.
|
||||
To be brief, we are very much reliant on your bug reports and feature suggestions to make this crate better.
|
||||
|
||||
@@ -8,7 +8,7 @@ repository = "https://github.com/mxre/winres"
|
||||
documentation = "https://mxre.github.io/winres"
|
||||
build = "build.rs"
|
||||
|
||||
[package.metadata.winres]
|
||||
[package.metadata.tauri-winres]
|
||||
LegalCopyright = "Copyright © 2016-2017"
|
||||
# this FileDescription overrides package.description
|
||||
FileDescription = "Example for \"winres\""
|
||||
@@ -20,4 +20,4 @@ winapi = { version = "0.3", features = [ "winuser" ] }
|
||||
# it won't get pulled for non-windows OSs (saves them resources)
|
||||
[build-dependencies]
|
||||
# winres project
|
||||
winres = { path = ".." }
|
||||
tauri-winres = { path = ".." }
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
extern crate winres;
|
||||
|
||||
fn main() {
|
||||
// only run if target os is windows
|
||||
if std::env::var("CARGO_CFG_TARGET_OS").unwrap() != "windows" {
|
||||
@@ -9,7 +7,7 @@ fn main() {
|
||||
// only build the resource for release builds
|
||||
// as calling rc.exe might be slow
|
||||
if std::env::var("PROFILE").unwrap() == "release" {
|
||||
let mut res = winres::WindowsResource::new();
|
||||
let mut res = tauri_winres::WindowsResource::new();
|
||||
if cfg!(unix) {
|
||||
// paths for X64 on archlinux
|
||||
res.set_toolkit_path("/usr/x86_64-w64-mingw32/bin");
|
||||
|
||||
28
lib.rs
28
lib.rs
@@ -10,16 +10,15 @@
|
||||
//! # Example
|
||||
//!
|
||||
//! ```rust
|
||||
//! # extern crate winres;
|
||||
//! # use std::io;
|
||||
//! # fn test_main() -> io::Result<()> {
|
||||
//! if cfg!(target_os = "windows") {
|
||||
//! let mut res = winres::WindowsResource::new();
|
||||
//! let mut res = tauri_winres::WindowsResource::new();
|
||||
//! res.set_icon("test.ico")
|
||||
//! # .set_output_directory(".")
|
||||
//! .set("InternalName", "TEST.EXE")
|
||||
//! // manually set version 1.0.0.0
|
||||
//! .set_version_info(winres::VersionInfo::PRODUCTVERSION, 0x0001000000000000);
|
||||
//! .set_version_info(tauri_winres::VersionInfo::PRODUCTVERSION, 0x0001000000000000);
|
||||
//! res.compile()?;
|
||||
//! }
|
||||
//! # Ok(())
|
||||
@@ -53,8 +52,6 @@ use std::io::prelude::*;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process;
|
||||
|
||||
extern crate toml;
|
||||
|
||||
/// Version info field names
|
||||
#[derive(PartialEq, Eq, Hash, Debug)]
|
||||
pub enum VersionInfo {
|
||||
@@ -114,7 +111,7 @@ impl WindowsResource {
|
||||
/// | `"ProductName"` | `package.name` |
|
||||
/// | `"FileDescription"` | `package.description` |
|
||||
///
|
||||
/// Furthermore if a section `package.metadata.winres` exists
|
||||
/// Furthermore if a section `package.metadata.tauri-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.
|
||||
@@ -126,7 +123,7 @@ impl WindowsResource {
|
||||
///
|
||||
/// ```,toml
|
||||
/// #Cargo.toml
|
||||
/// [package.metadata.winres]
|
||||
/// [package.metadata.tauri-winres]
|
||||
/// OriginalFilename = "testing.exe"
|
||||
/// FileDescription = "⛄❤☕"
|
||||
/// LegalCopyright = "Copyright © 2016"
|
||||
@@ -316,12 +313,10 @@ impl WindowsResource {
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// extern crate winapi;
|
||||
/// extern crate winres;
|
||||
/// # use std::io;
|
||||
/// fn main() {
|
||||
/// if cfg!(target_os = "windows") {
|
||||
/// let mut res = winres::WindowsResource::new();
|
||||
/// let mut res = tauri_winres::WindowsResource::new();
|
||||
/// # res.set_output_directory(".");
|
||||
/// res.set_language(winapi::um::winnt::MAKELANGID(
|
||||
/// winapi::um::winnt::LANG_ENGLISH,
|
||||
@@ -447,7 +442,7 @@ impl WindowsResource {
|
||||
/// Thus, everytime it is executed, a Windows UAC dialog will appear.
|
||||
///
|
||||
/// ```rust
|
||||
/// let mut res = winres::WindowsResource::new();
|
||||
/// let mut res = tauri_winres::WindowsResource::new();
|
||||
/// res.set_manifest(r#"
|
||||
/// <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
||||
/// <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||
@@ -576,9 +571,8 @@ impl WindowsResource {
|
||||
/// Define a menu resource:
|
||||
///
|
||||
/// ```rust
|
||||
/// # extern crate winres;
|
||||
/// # if cfg!(target_os = "windows") {
|
||||
/// let mut res = winres::WindowsResource::new();
|
||||
/// let mut res = tauri_winres::WindowsResource::new();
|
||||
/// res.append_rc_content(r##"sample MENU
|
||||
/// {
|
||||
/// MENUITEM "&Soup", 100
|
||||
@@ -817,21 +811,21 @@ fn parse_cargo_toml(props: &mut HashMap<String, String>) -> io::Result<()> {
|
||||
if let Ok(ml) = cargo_toml.parse::<toml::Value>() {
|
||||
if let Some(pkg) = ml.get("package") {
|
||||
if let Some(pkg) = pkg.get("metadata") {
|
||||
if let Some(pkg) = pkg.get("winres") {
|
||||
if let Some(pkg) = pkg.get("tauri-winres") {
|
||||
if let Some(pkg) = pkg.as_table() {
|
||||
for (k, v) in pkg {
|
||||
// println!("{} {}", k ,v);
|
||||
if let Some(v) = v.as_str() {
|
||||
props.insert(k.clone(), v.to_string());
|
||||
} else {
|
||||
println!("package.metadata.winres.{} is not a string", k);
|
||||
println!("package.metadata.tauri-winres.{} is not a string", k);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
println!("package.metadata.winres is not a table");
|
||||
println!("package.metadata.tauri-winres is not a table");
|
||||
}
|
||||
} else {
|
||||
println!("package.metadata.winres does not exist");
|
||||
println!("package.metadata.tauri-winres does not exist");
|
||||
}
|
||||
} else {
|
||||
println!("package.metadata does not exist");
|
||||
|
||||
Reference in New Issue
Block a user