forked from mxre/winres
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Use embed-resource crate to compile resources (#9)
* refactor: Use embed-resource for compilation * fix: use rc path instead of output. use rc path in compile call * let's try canonicalize to get absolute icon paths * reorder imports * update readme * clean up example
- Loading branch information
1 parent
db468ec
commit 3aa8411
Showing
7 changed files
with
149 additions
and
411 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"winres": patch | ||
--- | ||
|
||
Added `compile_for` function to select which binaries to apply the resource to. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"winres": patch | ||
--- | ||
|
||
Use https://github.com/nabijaczleweli/rust-embed-resource to compile the resource for better cross-platform compilation support. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use std::{ | ||
collections::HashMap, | ||
env, | ||
fs::File, | ||
io::{self, Read}, | ||
path::Path, | ||
}; | ||
|
||
pub(crate) fn parse_cargo_toml(props: &mut HashMap<String, String>) -> io::Result<()> { | ||
let cargo = Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap()).join("Cargo.toml"); | ||
let mut f = File::open(cargo)?; | ||
let mut cargo_toml = String::new(); | ||
f.read_to_string(&mut cargo_toml)?; | ||
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("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.tauri-winres.{} is not a string", k); | ||
} | ||
} | ||
} else { | ||
println!("package.metadata.tauri-winres is not a table"); | ||
} | ||
} else { | ||
println!("package.metadata.tauri-winres does not exist"); | ||
} | ||
} else { | ||
println!("package.metadata does not exist"); | ||
} | ||
} else { | ||
println!("package does not exist"); | ||
} | ||
} else { | ||
println!("TOML parsing error") | ||
} | ||
Ok(()) | ||
} | ||
|
||
pub(crate) fn escape_string(string: &str) -> String { | ||
let mut escaped = String::new(); | ||
for chr in string.chars() { | ||
// In quoted RC strings, double-quotes are escaped by using two | ||
// consecutive double-quotes. Other characters are escaped in the | ||
// usual C way using backslashes. | ||
match chr { | ||
'"' => escaped.push_str("\"\""), | ||
'\'' => escaped.push_str("\\'"), | ||
'\\' => escaped.push_str("\\\\"), | ||
'\n' => escaped.push_str("\\n"), | ||
'\t' => escaped.push_str("\\t"), | ||
'\r' => escaped.push_str("\\r"), | ||
_ => escaped.push(chr), | ||
}; | ||
} | ||
escaped | ||
} |
Oops, something went wrong.