Use internal macro system for including files, without alot of the bulk

This commit is contained in:
James 2018-05-03 21:50:44 +10:00
parent 79fa12043d
commit 16b984d87b
12 changed files with 105 additions and 108 deletions

90
Cargo.lock generated
View File

@ -284,13 +284,13 @@ dependencies = [
"futures 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)",
"hyper 0.11.15 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.11.15 (registry+https://github.com/rust-lang/crates.io-index)",
"hyper-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "hyper-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"mime_guess 1.8.3 (registry+https://github.com/rust-lang/crates.io-index)", "mime_guess 1.8.3 (registry+https://github.com/rust-lang/crates.io-index)",
"nfd 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "nfd 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"number_prefix 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", "number_prefix 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
"phf 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)",
"phf_macros 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
"reqwest 0.8.4 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.8.4 (registry+https://github.com/rust-lang/crates.io-index)",
"rust-embed 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
@ -353,8 +353,8 @@ version = "1.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"phf 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)", "phf 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)",
"phf_codegen 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)", "phf_codegen 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)",
"unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@ -364,8 +364,8 @@ version = "2.0.0-alpha.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"mime 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "mime 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"phf 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)", "phf 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)",
"phf_codegen 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)", "phf_codegen 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)",
"unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@ -513,33 +513,42 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "phf" name = "phf"
version = "0.7.21" version = "0.7.22"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"phf_shared 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)", "phf_shared 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
name = "phf_codegen" name = "phf_codegen"
version = "0.7.21" version = "0.7.22"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"phf_generator 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)", "phf_generator 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)",
"phf_shared 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)", "phf_shared 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
name = "phf_generator" name = "phf_generator"
version = "0.7.21" version = "0.7.22"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"phf_shared 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)", "phf_shared 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.3.20 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "phf_macros"
version = "0.7.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"phf_generator 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)",
"phf_shared 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
name = "phf_shared" name = "phf_shared"
version = "0.7.21" version = "0.7.22"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"siphasher 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "siphasher 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -570,6 +579,16 @@ dependencies = [
"libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "rand"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "redox_syscall" name = "redox_syscall"
version = "0.1.37" version = "0.1.37"
@ -623,30 +642,11 @@ dependencies = [
"uuid 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "uuid 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "rust-embed"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)",
"walkdir 2.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "safemem" name = "safemem"
version = "0.2.0" version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "same-file"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "schannel" name = "schannel"
version = "0.1.10" version = "0.1.10"
@ -960,15 +960,6 @@ name = "void"
version = "1.0.2" version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "walkdir"
version = "2.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"same-file 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "web-view" name = "web-view"
version = "0.1.2" version = "0.1.2"
@ -1090,22 +1081,22 @@ dependencies = [
"checksum openssl 0.9.23 (registry+https://github.com/rust-lang/crates.io-index)" = "169a4b9160baf9b9b1ab975418c673686638995ba921683a7f1e01470dcb8854" "checksum openssl 0.9.23 (registry+https://github.com/rust-lang/crates.io-index)" = "169a4b9160baf9b9b1ab975418c673686638995ba921683a7f1e01470dcb8854"
"checksum openssl-sys 0.9.24 (registry+https://github.com/rust-lang/crates.io-index)" = "14ba54ac7d5a4eabd1d5f2c1fdeb7e7c14debfa669d94b983d01b465e767ba9e" "checksum openssl-sys 0.9.24 (registry+https://github.com/rust-lang/crates.io-index)" = "14ba54ac7d5a4eabd1d5f2c1fdeb7e7c14debfa669d94b983d01b465e767ba9e"
"checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831"
"checksum phf 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)" = "cb325642290f28ee14d8c6201159949a872f220c62af6e110a56ea914fbe42fc" "checksum phf 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)" = "7d37a244c75a9748e049225155f56dbcb98fe71b192fd25fd23cb914b5ad62f2"
"checksum phf_codegen 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)" = "d62594c0bb54c464f633175d502038177e90309daf2e0158be42ed5f023ce88f" "checksum phf_codegen 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)" = "4e4048fe7dd7a06b8127ecd6d3803149126e9b33c7558879846da3a63f734f2b"
"checksum phf_generator 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)" = "6b07ffcc532ccc85e3afc45865469bf5d9e4ef5bfcf9622e3cfe80c2d275ec03" "checksum phf_generator 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)" = "05a079dd052e7b674d21cb31cbb6c05efd56a2cd2827db7692e2f1a507ebd998"
"checksum phf_shared 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)" = "07e24b0ca9643bdecd0632f2b3da6b1b89bbb0030e0b992afc1113b23a7bc2f2" "checksum phf_macros 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)" = "ce6cfe846605e58552e1324c566bfb5bd5ac032245c9ae05c859f042e81c03b5"
"checksum phf_shared 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)" = "c2261d544c2bb6aa3b10022b0be371b9c7c64f762ef28c6f5d4f1ef6d97b5930"
"checksum pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3a8b4c6b8165cd1a1cd4b9b120978131389f64bdaf456435caa41e630edba903" "checksum pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3a8b4c6b8165cd1a1cd4b9b120978131389f64bdaf456435caa41e630edba903"
"checksum podio 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "780fb4b6698bbf9cf2444ea5d22411cef2953f0824b98f33cf454ec5615645bd" "checksum podio 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "780fb4b6698bbf9cf2444ea5d22411cef2953f0824b98f33cf454ec5615645bd"
"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" "checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
"checksum rand 0.3.20 (registry+https://github.com/rust-lang/crates.io-index)" = "512870020642bb8c221bf68baa1b2573da814f6ccfe5c9699b1c303047abe9b1" "checksum rand 0.3.20 (registry+https://github.com/rust-lang/crates.io-index)" = "512870020642bb8c221bf68baa1b2573da814f6ccfe5c9699b1c303047abe9b1"
"checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5"
"checksum redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "0d92eecebad22b767915e4d529f89f28ee96dbbf5a4810d2b844373f136417fd" "checksum redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "0d92eecebad22b767915e4d529f89f28ee96dbbf5a4810d2b844373f136417fd"
"checksum regex 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "744554e01ccbd98fff8c457c3b092cd67af62a555a43bfe97ae8a0451f7799fa" "checksum regex 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "744554e01ccbd98fff8c457c3b092cd67af62a555a43bfe97ae8a0451f7799fa"
"checksum regex-syntax 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8e931c58b93d86f080c734bfd2bce7dd0079ae2331235818133c8be7f422e20e" "checksum regex-syntax 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8e931c58b93d86f080c734bfd2bce7dd0079ae2331235818133c8be7f422e20e"
"checksum relay 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f301bafeb60867c85170031bdb2fcf24c8041f33aee09e7b116a58d4e9f781c5" "checksum relay 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f301bafeb60867c85170031bdb2fcf24c8041f33aee09e7b116a58d4e9f781c5"
"checksum reqwest 0.8.4 (registry+https://github.com/rust-lang/crates.io-index)" = "449c45f593ce9af9417c91e22f274fb8cea013bcf3d37ec1b5fb534b623bc708" "checksum reqwest 0.8.4 (registry+https://github.com/rust-lang/crates.io-index)" = "449c45f593ce9af9417c91e22f274fb8cea013bcf3d37ec1b5fb534b623bc708"
"checksum rust-embed 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "399b86082734a2ce9f80a58377431da7f4f57712d9947cf9036d93c8098d2b79"
"checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f" "checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f"
"checksum same-file 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "cfb6eded0b06a0b512c8ddbcf04089138c9b4362c2f696f3c3d76039d68f3637"
"checksum schannel 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "acece75e0f987c48863a6c792ec8b7d6c4177d4a027f8ccc72f849794f437016" "checksum schannel 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "acece75e0f987c48863a6c792ec8b7d6c4177d4a027f8ccc72f849794f437016"
"checksum scoped-tls 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f417c22df063e9450888a7561788e9bd46d3bb3c1466435b4eccb903807f147d" "checksum scoped-tls 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f417c22df063e9450888a7561788e9bd46d3bb3c1466435b4eccb903807f147d"
"checksum security-framework 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "dfa44ee9c54ce5eecc9de7d5acbad112ee58755239381f687e564004ba4a2332" "checksum security-framework 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "dfa44ee9c54ce5eecc9de7d5acbad112ee58755239381f687e564004ba4a2332"
@ -1145,7 +1136,6 @@ dependencies = [
"checksum vcpkg 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9e0a7d8bed3178a8fb112199d466eeca9ed09a14ba8ad67718179b4fd5487d0b" "checksum vcpkg 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9e0a7d8bed3178a8fb112199d466eeca9ed09a14ba8ad67718179b4fd5487d0b"
"checksum version_check 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6b772017e347561807c1aa192438c5fd74242a670a6cffacc40f2defd1dc069d" "checksum version_check 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6b772017e347561807c1aa192438c5fd74242a670a6cffacc40f2defd1dc069d"
"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
"checksum walkdir 2.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "63636bd0eb3d00ccb8b9036381b526efac53caf112b7783b730ab3f8e44da369"
"checksum web-view 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "92f76092d2f039a4989ea946e195366dae806bdeb9be01779af2b96c3cffb90d" "checksum web-view 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "92f76092d2f039a4989ea946e195366dae806bdeb9be01779af2b96c3cffb90d"
"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
"checksum winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "04e3bd221fcbe8a271359c04f21a76db7d0c6028862d1bb5512d85e1e2eb5bb3" "checksum winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "04e3bd221fcbe8a271359c04f21a76db7d0c6028862d1bb5512d85e1e2eb5bb3"

View File

@ -19,8 +19,8 @@ url = "*"
reqwest = "0.8.4" reqwest = "0.8.4"
number_prefix = "0.2.7" number_prefix = "0.2.7"
rust-embed = "1.1.1" phf = "0.7.22"
log = "*" # Used by rust-embed's macros phf_macros = "0.7.22"
serde = "1.0.27" serde = "1.0.27"
serde_derive = "1.0.27" serde_derive = "1.0.27"

View File

@ -23,7 +23,7 @@ Add your logo to `static/img/logo.png`, modify the configuration file, then run:
cargo build cargo build
``` ```
LiftInstall should build on both Stable and Nightly Rust. LiftInstall should build on both ~~Stable and~~ Nightly Rust.
Contributing Contributing
------------ ------------

View File

@ -3,9 +3,26 @@ extern crate mime_guess;
use assets::mime_guess::{get_mime_type, octet_stream}; use assets::mime_guess::{get_mime_type, octet_stream};
#[derive(RustEmbed)] macro_rules! include_files_as_assets {
#[folder("static/")] ( $field_name:ident, $( $file_name:expr ),* ) => {
struct Assets; static $field_name: phf::Map<&'static str, &'static [u8]> = phf_map!(
$(
$file_name => include_bytes!(concat!("../static/", $file_name)),
)*
);
}
}
include_files_as_assets!(
ASSETS,
"/index.html",
"/css/bulma.css",
"/css/main.css",
"/img/logo.png",
"/js/helpers.js",
"/js/vue.js",
"/js/vue.min.js"
);
/// Returns a static file based upon a given String as a Path. /// Returns a static file based upon a given String as a Path.
/// ///
@ -22,5 +39,5 @@ pub fn file_from_string(file_path: &str) -> Option<(String, Vec<u8>)> {
let string_mime = guessed_mime.to_string(); let string_mime = guessed_mime.to_string();
Some((string_mime, Assets::get(file_path)?)) Some((string_mime, (*ASSETS.get(file_path)?).to_owned()))
} }

View File

@ -1,20 +1,20 @@
/// config.rs /// config.rs
/// ///
/// Contains Config structures, as well as means of serialising them. /// Contains Config structures, as well as means of serialising them.
use toml; use toml;
use toml::de::Error as TomlError; use toml::de::Error as TomlError;
use serde_json::{self, Error as SerdeError}; use serde_json::{self, Error as SerdeError};
use sources::types::Release;
use sources::get_by_name; use sources::get_by_name;
use sources::types::Release;
/// Description of the source of a package. /// Description of the source of a package.
#[derive(Debug, Deserialize, Serialize, Clone)] #[derive(Debug, Deserialize, Serialize, Clone)]
pub struct PackageSource { pub struct PackageSource {
pub name: String, pub name: String,
#[serde(rename = "match")] pub match_regex: String, #[serde(rename = "match")]
pub match_regex: String,
pub config: toml::Value, pub config: toml::Value,
} }

View File

@ -1,7 +1,6 @@
/// http.rs /// http.rs
/// ///
/// A simple wrapper around Hyper's HTTP client. /// A simple wrapper around Hyper's HTTP client.
use hyper::header::ContentLength; use hyper::header::ContentLength;
use reqwest; use reqwest;

View File

@ -1,7 +1,6 @@
/// installer.rs /// installer.rs
/// ///
/// Contains the main installer structure, as well as high-level means of controlling it. /// Contains the main installer structure, as well as high-level means of controlling it.
use regex::Regex; use regex::Regex;
use zip::ZipArchive; use zip::ZipArchive;
@ -14,20 +13,20 @@ use std::fs::create_dir_all;
use std::fs::read_dir; use std::fs::read_dir;
use std::fs::File; use std::fs::File;
use std::env::consts::OS;
use std::env::current_exe;
use std::env::home_dir; use std::env::home_dir;
use std::env::var; use std::env::var;
use std::env::current_exe;
use std::env::consts::OS;
use std::path::Path; use std::path::Path;
use std::path::PathBuf; use std::path::PathBuf;
use std::io::Cursor;
use std::io::copy; use std::io::copy;
use std::io::Cursor;
use std::sync::mpsc::Sender;
use std::sync::Arc; use std::sync::Arc;
use std::sync::Mutex; use std::sync::Mutex;
use std::sync::mpsc::Sender;
use config::Config; use config::Config;
@ -50,7 +49,7 @@ pub struct InstallerFramework {
config: Config, config: Config,
database: Vec<LocalInstallation>, database: Vec<LocalInstallation>,
install_path: Option<PathBuf>, install_path: Option<PathBuf>,
preexisting_install: bool preexisting_install: bool,
} }
/// Contains basic properties on the status of the session. Subset of InstallationFramework. /// Contains basic properties on the status of the session. Subset of InstallationFramework.
@ -58,7 +57,7 @@ pub struct InstallerFramework {
pub struct InstallationStatus { pub struct InstallationStatus {
database: Vec<LocalInstallation>, database: Vec<LocalInstallation>,
install_path: Option<String>, install_path: Option<String>,
preexisting_install: bool preexisting_install: bool,
} }
/// Used to track the amount of data that has been downloaded during a HTTP request. /// Used to track the amount of data that has been downloaded during a HTTP request.
@ -102,12 +101,12 @@ impl InstallerFramework {
&mut self, &mut self,
items: Vec<String>, items: Vec<String>,
messages: &Sender<InstallMessage>, messages: &Sender<InstallMessage>,
fresh_install: bool fresh_install: bool,
) -> Result<(), String> { ) -> Result<(), String> {
// We have to have a install path for us to be able to do anything // We have to have a install path for us to be able to do anything
let path = match self.install_path.clone() { let path = match self.install_path.clone() {
Some(v) => v, Some(v) => v,
None => return Err(format!("No install directory for installer")) None => return Err(format!("No install directory for installer")),
}; };
println!("Framework: Installing {:?} to {:?}", items, path); println!("Framework: Installing {:?} to {:?}", items, path);
@ -366,8 +365,7 @@ impl InstallerFramework {
let new_app = path.join(platform_extension); let new_app = path.join(platform_extension);
let mut file_metadata = OpenOptions::new(); let mut file_metadata = OpenOptions::new();
file_metadata.write(true) file_metadata.write(true).create_new(true);
.create_new(true);
#[cfg(unix)] #[cfg(unix)]
{ {
@ -394,7 +392,7 @@ impl InstallerFramework {
// We have to have a install path for us to be able to do anything // We have to have a install path for us to be able to do anything
let path = match self.install_path.clone() { let path = match self.install_path.clone() {
Some(v) => v, Some(v) => v,
None => return Err(format!("No install directory for installer")) None => return Err(format!("No install directory for installer")),
}; };
let metadata_path = path.join("metadata.json"); let metadata_path = path.join("metadata.json");
@ -413,7 +411,7 @@ impl InstallerFramework {
/// Configures this installer to install to the specified location. /// Configures this installer to install to the specified location.
/// If there was a currently configured install path, this will be left as-is. /// If there was a currently configured install path, this will be left as-is.
pub fn set_install_dir(&mut self, dir : &str) { pub fn set_install_dir(&mut self, dir: &str) {
self.install_path = Some(Path::new(dir).to_owned()); self.install_path = Some(Path::new(dir).to_owned());
} }
@ -423,9 +421,9 @@ impl InstallerFramework {
database: self.database.clone(), database: self.database.clone(),
install_path: match self.install_path.clone() { install_path: match self.install_path.clone() {
Some(v) => Some(v.display().to_string()), Some(v) => Some(v.display().to_string()),
None => None None => None,
}, },
preexisting_install: self.preexisting_install preexisting_install: self.preexisting_install,
} }
} }
@ -433,15 +431,15 @@ impl InstallerFramework {
pub fn new(config: Config) -> Self { pub fn new(config: Config) -> Self {
InstallerFramework { InstallerFramework {
config, config,
database : Vec::new(), database: Vec::new(),
install_path : None, install_path: None,
preexisting_install : false preexisting_install: false,
} }
} }
/// Creates a new instance of the Installer Framework with a specified Config, managing /// Creates a new instance of the Installer Framework with a specified Config, managing
/// a pre-existing installation. /// a pre-existing installation.
pub fn new_with_db(config: Config, install_path : &Path) -> Result<Self, String> { pub fn new_with_db(config: Config, install_path: &Path) -> Result<Self, String> {
let path = install_path.to_owned(); let path = install_path.to_owned();
let metadata_path = path.join("metadata.json"); let metadata_path = path.join("metadata.json");
let metadata_file = match File::open(metadata_path) { let metadata_file = match File::open(metadata_path) {
@ -449,7 +447,7 @@ impl InstallerFramework {
Err(v) => return Err(format!("Unable to open file handle: {:?}", v)), Err(v) => return Err(format!("Unable to open file handle: {:?}", v)),
}; };
let database : Vec<LocalInstallation> = match serde_json::from_reader(metadata_file) { let database: Vec<LocalInstallation> = match serde_json::from_reader(metadata_file) {
Ok(v) => v, Ok(v) => v,
Err(v) => return Err(format!("Unable to read metadata file: {:?}", v)), Err(v) => return Err(format!("Unable to read metadata file: {:?}", v)),
}; };
@ -457,8 +455,8 @@ impl InstallerFramework {
Ok(InstallerFramework { Ok(InstallerFramework {
config, config,
database, database,
install_path : Some(path), install_path: Some(path),
preexisting_install : true preexisting_install: true,
}) })
} }
} }

View File

@ -1,5 +1,7 @@
#![windows_subsystem = "windows"] #![windows_subsystem = "windows"]
#![feature(attr_literals)] #![feature(extern_prelude)]
#![feature(plugin)]
#![plugin(phf_macros)]
extern crate web_view; extern crate web_view;
@ -11,10 +13,7 @@ extern crate tokio_core;
extern crate number_prefix; extern crate number_prefix;
extern crate reqwest; extern crate reqwest;
#[macro_use] extern crate phf;
extern crate rust_embed;
#[macro_use]
extern crate log;
extern crate serde; extern crate serde;
#[macro_use] #[macro_use]
@ -28,11 +27,11 @@ extern crate semver;
extern crate zip; extern crate zip;
mod assets; mod assets;
mod rest;
mod config; mod config;
mod installer;
mod sources;
mod http; mod http;
mod installer;
mod rest;
mod sources;
use web_view::*; use web_view::*;

View File

@ -9,36 +9,35 @@ use self::nfd::Response as NfdResponse;
use serde_json; use serde_json;
use futures::Stream;
use futures::Future;
use futures::future; use futures::future;
use futures::Future;
use futures::Sink; use futures::Sink;
use futures::Stream;
use hyper::{self, Error as HyperError, Get, Post, StatusCode};
use hyper::header::{ContentLength, ContentType}; use hyper::header::{ContentLength, ContentType};
use hyper::server::{Http, Request, Response, Service}; use hyper::server::{Http, Request, Response, Service};
use hyper::{self, Error as HyperError, Get, Post, StatusCode};
use self::url::form_urlencoded; use self::url::form_urlencoded;
use std::collections::HashMap;
use std::net::{IpAddr, Ipv4Addr, SocketAddr}; use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::thread::{self, JoinHandle};
use std::process::exit; use std::process::exit;
use std::sync::mpsc::channel;
use std::sync::Arc; use std::sync::Arc;
use std::sync::RwLock; use std::sync::RwLock;
use std::sync::mpsc::channel; use std::thread::{self, JoinHandle};
use std::collections::HashMap;
use assets; use assets;
use installer::InstallerFramework;
use installer::InstallMessage; use installer::InstallMessage;
use installer::InstallerFramework;
#[derive(Serialize)] #[derive(Serialize)]
struct FileSelection { struct FileSelection {
path: Option<String>, path: Option<String>,
} }
/// Acts as a communication mechanism between the Hyper WebService and the rest of the /// Acts as a communication mechanism between the Hyper WebService and the rest of the
/// application. /// application.
pub struct WebServer { pub struct WebServer {
@ -108,10 +107,8 @@ impl Service for WebService {
(&Get, "/api/config") => { (&Get, "/api/config") => {
let framework = self.framework.read().unwrap(); let framework = self.framework.read().unwrap();
let file = enscapsulate_json( let file =
"config", enscapsulate_json("config", &framework.get_config().to_json_str().unwrap());
&framework.get_config().to_json_str().unwrap(),
);
Response::<hyper::Body>::new() Response::<hyper::Body>::new()
.with_header(ContentLength(file.len() as u64)) .with_header(ContentLength(file.len() as u64))

View File

@ -1,14 +1,13 @@
/// github/mod.rs /// github/mod.rs
use futures::{Future, Stream}; use futures::{Future, Stream};
use tokio_core::reactor::Core; use tokio_core::reactor::Core;
use hyper::header::UserAgent;
use hyper::Client; use hyper::Client;
use hyper::Uri;
use hyper::Method; use hyper::Method;
use hyper::Request; use hyper::Request;
use hyper::header::UserAgent; use hyper::Uri;
use hyper_tls::HttpsConnector; use hyper_tls::HttpsConnector;

View File

@ -1,7 +1,6 @@
/// sources/mod.rs /// sources/mod.rs
/// ///
/// Contains backends to various release distribution services. /// Contains backends to various release distribution services.
pub mod types; pub mod types;
pub mod github; pub mod github;

View File

@ -1,7 +1,6 @@
/// types.rs /// types.rs
/// ///
/// Contains traits that should be implemented by sources, as well as corresponding types. /// Contains traits that should be implemented by sources, as well as corresponding types.
use std::cmp::Ordering; use std::cmp::Ordering;
pub use semver::Version as SemverVersion; pub use semver::Version as SemverVersion;