Ready to integrate rcedit on windows

This commit is contained in:
Tim-Paik 2022-05-01 16:41:32 +08:00
parent 9117dc841f
commit d31ddba08a
Signed by: Tim-Paik
GPG Key ID: DC36A050DB42566D
3 changed files with 57 additions and 9 deletions

25
Cargo.lock generated
View File

@ -1176,6 +1176,7 @@ dependencies = [
"gumdrop",
"image",
"new_mime_guess",
"rcedit",
"serde",
"toml",
"wry",
@ -1518,6 +1519,24 @@ dependencies = [
"num_cpus",
]
[[package]]
name = "rcedit"
version = "0.1.0"
source = "git+https://github.com/Tim-Paik/rcedit-rs.git#8d323d1015ad6ff2c111d902e9d60b75668fa781"
dependencies = [
"rcedit-sys",
"thiserror",
"widestring",
]
[[package]]
name = "rcedit-sys"
version = "0.1.0"
source = "git+https://github.com/Tim-Paik/rcedit-rs.git#8d323d1015ad6ff2c111d902e9d60b75668fa781"
dependencies = [
"cc",
]
[[package]]
name = "redox_syscall"
version = "0.2.10"
@ -2093,6 +2112,12 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8b77fdfd5a253be4ab714e4ffa3c49caf146b4de743e97510c0656cf90f1e8e"
[[package]]
name = "widestring"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17882f045410753661207383517a6f62ec3dbeb6a4ed2acce01f0728238d1983"
[[package]]
name = "winapi"
version = "0.3.9"

View File

@ -12,3 +12,6 @@ new_mime_guess = "4.0"
serde = {version = "1.0", features = ["derive"]}
toml = "0.5"
wry = {version = "0.15", features = ["devtools"]}
[target.'cfg(windows)'.dependencies]
rcedit = {git = "https://github.com/Tim-Paik/rcedit-rs.git"}

View File

@ -1,10 +1,9 @@
use crate::data;
use std::{fs, io::Write};
#[cfg(windows)]
const RUNTIME_DATA: &[u8] = include_bytes!("../../target/release/neutauri_runtime.exe");
#[cfg(not(windows))]
const RUNTIME_DATA: &[u8] = include_bytes!("../../target/release/neutauri_runtime");
use std::{
env, fs,
hash::{Hash, Hasher},
io::{self, Write},
};
fn options() -> fs::OpenOptions {
#[cfg(not(windows))]
@ -18,10 +17,31 @@ fn options() -> fs::OpenOptions {
options
}
pub fn bundle(config_path: String) -> std::io::Result<()> {
#[cfg(not(windows))]
fn get_runtime_data() -> io::Result<Vec<u8>> {
Ok(include_bytes!("../../target/release/neutauri_runtime").to_vec())
}
#[cfg(windows)]
fn get_runtime_data() -> io::Result<Vec<u8>> {
let mut hasher = std::collections::hash_map::DefaultHasher::new();
hasher.write(b"neutauri_runtime");
std::time::SystemTime::now().hash(&mut hasher);
println!("Hash is {:x}!", hasher.finish());
let temp_path = env::temp_dir().join(format!("{:x}.exe", hasher.finish()));
fs::write(
&temp_path,
include_bytes!("../../target/release/neutauri_runtime.exe"),
)?;
// let mut updater = rcedit::ResourceUpdater::new();
// updater.load(&temp_path).unwrap(); // TODO: handle error
fs::read(&temp_path)
}
pub fn bundle(config_path: String) -> io::Result<()> {
let config_path = std::path::Path::new(&config_path).canonicalize()?;
let config: data::Config = toml::from_str(fs::read_to_string(&config_path)?.as_str())
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
let source = match config_path.parent() {
Some(path) => path.join(&config.source).canonicalize()?,
None => config.source.canonicalize()?,
@ -42,7 +62,7 @@ pub fn bundle(config_path: String) -> std::io::Result<()> {
}
let data = data::Data::build_from_dir(source, config.window_attr()?, config.webview_attr()?)?;
let mut f = options().open(&target)?;
f.write_all(RUNTIME_DATA)?;
f.write_all(&get_runtime_data()?)?;
f.write_all(&data)?;
f.sync_all()?;
f.flush()?;