1
0
mirror of https://github.com/Tim-Paik/neutauri.git synced 2024-10-12 23:29:41 +00:00

Ready to integrate rcedit on windows

This commit is contained in:
2022-05-01 16:41:32 +08:00
parent 9117dc841f
commit d31ddba08a
3 changed files with 57 additions and 9 deletions

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()?;