2018-08-03 11:52:31 +00:00
|
|
|
//! main.rs
|
|
|
|
//!
|
|
|
|
//! The main entrypoint for the application. Orchestrates the building of the installation
|
|
|
|
//! framework, and opens necessary HTTP servers/frontends.
|
|
|
|
|
2018-01-27 03:27:41 +00:00
|
|
|
#![windows_subsystem = "windows"]
|
2018-01-26 12:29:28 +00:00
|
|
|
|
2018-08-03 11:49:38 +00:00
|
|
|
#[cfg(windows)]
|
|
|
|
extern crate nfd;
|
|
|
|
|
2018-01-26 12:29:28 +00:00
|
|
|
extern crate web_view;
|
2018-01-27 11:56:36 +00:00
|
|
|
|
2018-07-28 05:33:06 +00:00
|
|
|
extern crate futures;
|
2018-08-03 07:50:17 +00:00
|
|
|
extern crate hyper;
|
2018-08-03 11:52:31 +00:00
|
|
|
extern crate url;
|
2018-01-29 10:27:54 +00:00
|
|
|
|
2018-01-30 04:53:28 +00:00
|
|
|
extern crate number_prefix;
|
2018-01-30 04:54:44 +00:00
|
|
|
extern crate reqwest;
|
2018-01-30 04:53:28 +00:00
|
|
|
|
2018-01-27 03:27:41 +00:00
|
|
|
extern crate serde;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate serde_derive;
|
|
|
|
extern crate serde_json;
|
|
|
|
extern crate toml;
|
|
|
|
|
2018-01-29 12:28:14 +00:00
|
|
|
extern crate regex;
|
2018-01-29 12:37:17 +00:00
|
|
|
extern crate semver;
|
2018-01-29 07:21:37 +00:00
|
|
|
|
2018-01-30 07:29:34 +00:00
|
|
|
extern crate zip;
|
|
|
|
|
2018-01-26 12:29:28 +00:00
|
|
|
mod assets;
|
2018-01-27 03:27:41 +00:00
|
|
|
mod config;
|
2018-05-03 11:50:44 +00:00
|
|
|
mod http;
|
2018-01-27 03:27:41 +00:00
|
|
|
mod installer;
|
2018-05-03 11:50:44 +00:00
|
|
|
mod rest;
|
2018-01-29 07:21:37 +00:00
|
|
|
mod sources;
|
2018-08-03 07:50:17 +00:00
|
|
|
mod tasks;
|
2018-01-26 12:29:28 +00:00
|
|
|
|
|
|
|
use web_view::*;
|
|
|
|
|
2018-01-27 03:27:41 +00:00
|
|
|
use config::Config;
|
|
|
|
|
|
|
|
use installer::InstallerFramework;
|
2018-01-26 12:29:28 +00:00
|
|
|
|
2018-08-03 11:49:38 +00:00
|
|
|
use nfd::Response;
|
2018-01-27 03:27:41 +00:00
|
|
|
use rest::WebServer;
|
|
|
|
|
|
|
|
// TODO: Fetch this over a HTTP request?
|
2018-01-27 11:58:56 +00:00
|
|
|
static RAW_CONFIG: &'static str = include_str!("../config.toml");
|
2018-01-26 12:29:28 +00:00
|
|
|
|
2018-08-03 11:49:38 +00:00
|
|
|
#[derive(Deserialize, Debug)]
|
|
|
|
enum CallbackType {
|
|
|
|
SelectInstallDir { callback_name: String },
|
|
|
|
}
|
|
|
|
|
2018-01-26 12:29:28 +00:00
|
|
|
fn main() {
|
2018-01-27 03:27:41 +00:00
|
|
|
let config = Config::from_toml_str(RAW_CONFIG).unwrap();
|
|
|
|
|
2018-01-27 04:33:15 +00:00
|
|
|
let app_name = config.general.name.clone();
|
|
|
|
|
2018-08-03 10:59:43 +00:00
|
|
|
println!("{} installer", app_name);
|
|
|
|
|
2018-05-03 04:14:44 +00:00
|
|
|
let current_exe = std::env::current_exe().unwrap();
|
|
|
|
let current_path = current_exe.parent().unwrap();
|
|
|
|
let metadata_file = current_path.join("metadata.json");
|
2018-05-03 03:30:58 +00:00
|
|
|
let framework = if metadata_file.exists() {
|
2018-08-03 10:59:43 +00:00
|
|
|
println!("Using pre-existing metadata file: {:?}", metadata_file);
|
2018-05-03 04:14:44 +00:00
|
|
|
InstallerFramework::new_with_db(config, current_path).unwrap()
|
2018-05-03 03:30:58 +00:00
|
|
|
} else {
|
2018-08-03 10:59:43 +00:00
|
|
|
println!("Starting fresh install");
|
2018-05-03 03:30:58 +00:00
|
|
|
InstallerFramework::new(config)
|
|
|
|
};
|
2018-01-27 03:27:41 +00:00
|
|
|
|
|
|
|
let server = WebServer::new(framework).unwrap();
|
|
|
|
|
2018-01-26 12:29:28 +00:00
|
|
|
// Startup HTTP server for handling the web view
|
2018-01-27 03:27:41 +00:00
|
|
|
let http_address = format!("http://{}", server.get_addr());
|
|
|
|
|
2018-01-26 12:29:28 +00:00
|
|
|
// Init the web view
|
2018-08-03 12:04:06 +00:00
|
|
|
let size = (1024, 500);
|
2018-01-26 12:29:28 +00:00
|
|
|
let resizable = false;
|
|
|
|
let debug = true;
|
|
|
|
|
|
|
|
run(
|
2018-01-27 04:33:15 +00:00
|
|
|
&format!("{} Installer", app_name),
|
2018-05-03 13:08:26 +00:00
|
|
|
Content::Url(http_address),
|
2018-01-26 12:29:28 +00:00
|
|
|
Some(size),
|
|
|
|
resizable,
|
|
|
|
debug,
|
2018-01-29 07:21:37 +00:00
|
|
|
|_| {},
|
2018-07-28 05:33:06 +00:00
|
|
|
|wv, msg, _| {
|
2018-08-03 11:49:38 +00:00
|
|
|
let command: CallbackType =
|
|
|
|
serde_json::from_str(msg).expect(&format!("Unable to parse string: {:?}", msg));
|
|
|
|
|
|
|
|
println!("Incoming payload: {:?}", command);
|
|
|
|
|
|
|
|
match command {
|
|
|
|
CallbackType::SelectInstallDir { callback_name } => {
|
|
|
|
#[cfg(windows)]
|
|
|
|
let result =
|
|
|
|
match nfd::open_pick_folder(None).expect("Unable to open folder dialog") {
|
|
|
|
Response::Okay(v) => v,
|
|
|
|
_ => return,
|
|
|
|
};
|
|
|
|
|
|
|
|
#[cfg(not(windows))]
|
|
|
|
let result =
|
|
|
|
wv.dialog(Dialog::ChooseDirectory, "Select a install directory...", "");
|
|
|
|
|
|
|
|
if result.len() > 0 {
|
|
|
|
let result =
|
|
|
|
serde_json::to_string(&result).expect("Unable to serialize response");
|
|
|
|
let command = format!("{}({});", callback_name, result);
|
|
|
|
println!("Injecting response: {}", command);
|
|
|
|
wv.eval(&command);
|
|
|
|
}
|
|
|
|
}
|
2018-07-28 05:33:06 +00:00
|
|
|
}
|
|
|
|
},
|
2018-01-29 07:21:37 +00:00
|
|
|
(),
|
2018-01-26 12:29:28 +00:00
|
|
|
);
|
|
|
|
}
|