From b6fba6108037b374b63f37d3732574f636b3add5 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 8 Aug 2018 21:19:46 +1000 Subject: [PATCH] Feed winres data from the bootstrap config file --- Cargo.toml | 8 ++++---- README.md | 1 - build.rs | 45 ++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index eccd58d..b8f5c40 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,10 +7,6 @@ documentation = "https://liftinstall.jselby.net" description = "An adaptable installer for your application." build = "build.rs" -[package.metadata.winres] -ProductName = "yuzu Installer" -FileDescription = "An interactive installer for yuzu" - [dependencies] web-view = {git = "https://github.com/Boscop/web-view.git", rev = "555f422d09cbb94e82a728d47e9e07ca91963f6e"} @@ -53,3 +49,7 @@ nfd = "0.0.4" winres = "0.1" bindgen = "0.26.3" cc = "1.0" + +serde = "1.0.27" +serde_derive = "1.0.27" +toml = "0.4" diff --git a/README.md b/README.md index 0f166b9..2d2588b 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,6 @@ In order to build yourself an installer, as a bare minimum, you need to: - Add your favicon to `static/favicon.ico` - Modify the bootstrap configuration file as needed (`config.PLATFORM.toml`). - Have the main configuration file somewhere useful, reachable over HTTP. -- Tweak `package.metadata.winres` metadata in `Cargo.toml` - Run: ```bash diff --git a/build.rs b/build.rs index 231a70e..30b9c59 100644 --- a/build.rs +++ b/build.rs @@ -1,4 +1,5 @@ extern crate walkdir; + #[cfg(windows)] extern crate winres; @@ -8,6 +9,11 @@ extern crate bindgen; #[cfg(windows)] extern crate cc; +extern crate serde; +#[macro_use] +extern crate serde_derive; +extern crate toml; + use walkdir::WalkDir; use std::env; @@ -19,16 +25,33 @@ use std::fs::File; use std::io::BufRead; use std::io::BufReader; +use std::io::Read; use std::io::Write; use std::env::consts::OS; const FILES_TO_PREPROCESS: &'static [&'static str] = &["helpers.js", "views.js"]; +/// Describes the application itself. +#[derive(Debug, Deserialize)] +pub struct BaseAttributes { + pub name: String, + pub target_url: String, +} + #[cfg(windows)] -fn handle_binary() { +fn handle_binary(config: &BaseAttributes) { let mut res = winres::WindowsResource::new(); res.set_icon("static/favicon.ico"); + res.set( + "FileDescription", + &format!("Interactive installer for {}", config.name), + ); + res.set("ProductName", &format!("{} installer", config.name)); + res.set( + "OriginalFilename", + &format!("{}_installer.exe", config.name), + ); res.compile().expect("Failed to generate metadata"); let bindings = bindgen::Builder::default() @@ -48,11 +71,9 @@ fn handle_binary() { } #[cfg(not(windows))] -fn handle_binary() {} +fn handle_binary(config: &BaseAttributes) {} fn main() { - handle_binary(); - let output_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); let os = OS.to_lowercase(); @@ -68,7 +89,21 @@ fn main() { ); } - copy(target_config, output_dir.join("config.toml")).expect("Unable to copy config file"); + // Read in the config for our own purposes + let file_contents = { + let mut file = File::open(&target_config).expect("Unable to open config file"); + let mut buf = Vec::new(); + file.read_to_end(&mut buf) + .expect("Unable to read config file contents"); + buf + }; + + let config: BaseAttributes = + toml::from_slice(&file_contents).expect("Unable to parse config file"); + handle_binary(&config); + + // Copy for the main build + copy(&target_config, output_dir.join("config.toml")).expect("Unable to copy config file"); // Copy files from static/ to build dir for entry in WalkDir::new("static") {