mirror of
https://github.com/yuzu-emu/liftinstall.git
synced 2024-12-22 19:05:27 +00:00
Use proper logging solution
This commit is contained in:
parent
a9e51af7e0
commit
66fc287770
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -3,3 +3,5 @@
|
|||
|
||||
/target/
|
||||
**/*.rs.bk
|
||||
|
||||
*.log
|
||||
|
|
38
Cargo.lock
generated
38
Cargo.lock
generated
|
@ -77,6 +77,16 @@ name = "cfg-if"
|
|||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "chrono"
|
||||
version = "0.4.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-traits 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation"
|
||||
version = "0.2.3"
|
||||
|
@ -115,6 +125,14 @@ dependencies = [
|
|||
"cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fern"
|
||||
version = "0.5.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "flate2"
|
||||
version = "1.0.1"
|
||||
|
@ -292,8 +310,11 @@ dependencies = [
|
|||
name = "liftinstall"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"chrono 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"fern 0.5.6 (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.27 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"mime_guess 1.8.6 (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)",
|
||||
|
@ -470,11 +491,24 @@ dependencies = [
|
|||
"gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-integer"
|
||||
version = "0.1.39"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"num-traits 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.1.42"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "num_cpus"
|
||||
version = "1.8.0"
|
||||
|
@ -1072,11 +1106,13 @@ dependencies = [
|
|||
"checksum bzip2-sys 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2c5162604199bbb17690ede847eaa6120a3f33d5ab4dcc8e7c25b16d849ae79b"
|
||||
"checksum cc 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "deaf9ec656256bb25b404c51ef50097207b9cbb29c933d31f92cae5a8a0ffee0"
|
||||
"checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de"
|
||||
"checksum chrono 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e48d85528df61dc964aa43c5f6ca681a19cfa74939b2348d204bd08a981f2fb0"
|
||||
"checksum core-foundation 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "25bfd746d203017f7d5cbd31ee5d8e17f94b6521c7af77ece6c9e4b2d4b16c67"
|
||||
"checksum core-foundation-sys 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "065a5d7ffdcbc8fa145d6f0746f3555025b9097a9e9cda59f7467abae670c78d"
|
||||
"checksum crc 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bd5d02c0aac6bd68393ed69e00bbc2457f3e89075c6349db7189618dc4ddc1d7"
|
||||
"checksum dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab"
|
||||
"checksum encoding_rs 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "98fd0f24d1fb71a4a6b9330c8ca04cbd4e7cc5d846b54ca74ff376bc7c9f798d"
|
||||
"checksum fern 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "57915fe00a83af935983eb2d00b0ecc62419c4741b28c207ecbf98fd4a1b94c8"
|
||||
"checksum flate2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9fac2277e84e5e858483756647a9d0aa8d9a2b7cba517fd84325a0aaa69a0909"
|
||||
"checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3"
|
||||
"checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
|
||||
|
@ -1115,7 +1151,9 @@ dependencies = [
|
|||
"checksum native-tls 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f74dbadc8b43df7864539cedb7bc91345e532fdd913cfdc23ad94f4d2d40fbc0"
|
||||
"checksum net2 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)" = "3a80f842784ef6c9a958b68b7516bc7e35883c614004dd94959a4dca1b716c09"
|
||||
"checksum nfd 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8e752e3c216bc8a491c5b59fa46da10f1379ae450b19ac688e07f4bb55042e98"
|
||||
"checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea"
|
||||
"checksum num-traits 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "9936036cc70fe4a8b2d338ab665900323290efb03983c86cbe235ae800ad8017"
|
||||
"checksum num-traits 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "630de1ef5cc79d0cdd78b7e33b81f083cbfe90de0f4b2b2f07f905867c70e9fe"
|
||||
"checksum num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c51a3322e4bca9d212ad9a158a02abc6934d005490c054a2778df73a70aa0a30"
|
||||
"checksum number_prefix 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "59a14be9c211cb9c602bad35ac99f41e9a84b44d71b8cbd3040e3bd02a214902"
|
||||
"checksum openssl 0.9.23 (registry+https://github.com/rust-lang/crates.io-index)" = "169a4b9160baf9b9b1ab975418c673686638995ba921683a7f1e01470dcb8854"
|
||||
|
|
|
@ -33,6 +33,10 @@ regex = "0.2"
|
|||
|
||||
zip = "0.2.8"
|
||||
|
||||
log = "0.4"
|
||||
fern = "0.5"
|
||||
chrono = "0.4.5"
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
# NFD is needed on Windows, as web-view doesn't work correctly here
|
||||
nfd = "0.0.4"
|
||||
|
|
|
@ -86,7 +86,7 @@ impl InstallerFramework {
|
|||
fresh_install: bool,
|
||||
) -> Result<(), String> {
|
||||
// TODO: Uninstall packages that aren't selected
|
||||
println!(
|
||||
info!(
|
||||
"Framework: Installing {:?} to {:?}",
|
||||
items,
|
||||
self.install_path
|
||||
|
@ -103,7 +103,7 @@ impl InstallerFramework {
|
|||
}
|
||||
}
|
||||
|
||||
println!(
|
||||
info!(
|
||||
"Framework: Uninstalling {:?} additionally.",
|
||||
uninstall_items
|
||||
);
|
||||
|
@ -117,12 +117,12 @@ impl InstallerFramework {
|
|||
|
||||
let mut tree = DependencyTree::build(task);
|
||||
|
||||
println!("Dependency tree:\n{}", tree);
|
||||
info!("Dependency tree:\n{}", tree);
|
||||
|
||||
tree.execute(self, &|msg: &str, progress: f32| match messages
|
||||
.send(InstallMessage::Status(msg.to_string(), progress as _))
|
||||
{
|
||||
Err(v) => eprintln!("Failed to submit queue message: {:?}", v),
|
||||
Err(v) => error!("Failed to submit queue message: {:?}", v),
|
||||
_ => {}
|
||||
}).map(|_x| ())
|
||||
}
|
||||
|
@ -137,12 +137,12 @@ impl InstallerFramework {
|
|||
|
||||
let mut tree = DependencyTree::build(task);
|
||||
|
||||
println!("Dependency tree:\n{}", tree);
|
||||
info!("Dependency tree:\n{}", tree);
|
||||
|
||||
tree.execute(self, &|msg: &str, progress: f32| match messages
|
||||
.send(InstallMessage::Status(msg.to_string(), progress as _))
|
||||
{
|
||||
Err(v) => eprintln!("Failed to submit queue message: {:?}", v),
|
||||
Err(v) => error!("Failed to submit queue message: {:?}", v),
|
||||
_ => {}
|
||||
}).map(|_x| ())
|
||||
}
|
||||
|
|
25
src/logging.rs
Normal file
25
src/logging.rs
Normal file
|
@ -0,0 +1,25 @@
|
|||
//! Contains functions to help with logging.
|
||||
|
||||
use fern;
|
||||
use chrono;
|
||||
use log;
|
||||
|
||||
use std::io;
|
||||
|
||||
pub fn setup_logger() -> Result<(), fern::InitError> {
|
||||
fern::Dispatch::new()
|
||||
.format(|out, message, record| {
|
||||
out.finish(format_args!(
|
||||
"{}[{}][{}] {}",
|
||||
chrono::Local::now().format("[%H:%M:%S]"),
|
||||
record.target(),
|
||||
record.level(),
|
||||
message
|
||||
))
|
||||
})
|
||||
.level(log::LevelFilter::Info)
|
||||
.chain(io::stdout())
|
||||
.chain(fern::log_file("installer.log")?)
|
||||
.apply()?;
|
||||
Ok(())
|
||||
}
|
21
src/main.rs
21
src/main.rs
|
@ -28,6 +28,12 @@ extern crate semver;
|
|||
|
||||
extern crate zip;
|
||||
|
||||
extern crate fern;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
extern crate chrono;
|
||||
|
||||
mod assets;
|
||||
mod config;
|
||||
mod http;
|
||||
|
@ -35,6 +41,7 @@ mod installer;
|
|||
mod rest;
|
||||
mod sources;
|
||||
mod tasks;
|
||||
mod logging;
|
||||
|
||||
use web_view::*;
|
||||
|
||||
|
@ -62,20 +69,22 @@ enum CallbackType {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
logging::setup_logger().expect("Unable to setup logging!");
|
||||
|
||||
let config = Config::from_toml_str(RAW_CONFIG).unwrap();
|
||||
|
||||
let app_name = config.general.name.clone();
|
||||
|
||||
println!("{} installer", app_name);
|
||||
info!("{} installer", app_name);
|
||||
|
||||
let current_exe = std::env::current_exe().unwrap();
|
||||
let current_path = current_exe.parent().unwrap();
|
||||
let metadata_file = current_path.join("metadata.json");
|
||||
let framework = if metadata_file.exists() {
|
||||
println!("Using pre-existing metadata file: {:?}", metadata_file);
|
||||
info!("Using pre-existing metadata file: {:?}", metadata_file);
|
||||
InstallerFramework::new_with_db(config, current_path).unwrap()
|
||||
} else {
|
||||
println!("Starting fresh install");
|
||||
info!("Starting fresh install");
|
||||
InstallerFramework::new(config)
|
||||
};
|
||||
|
||||
|
@ -106,7 +115,7 @@ fn main() {
|
|||
let server = WebServer::with_addr(framework.clone(), address).unwrap();
|
||||
|
||||
let addr = server.get_addr();
|
||||
println!("Server: {:?}", addr);
|
||||
debug!("Server: {:?}", addr);
|
||||
|
||||
http_address = Some(addr);
|
||||
|
||||
|
@ -136,7 +145,7 @@ fn main() {
|
|||
let command: CallbackType =
|
||||
serde_json::from_str(msg).expect(&format!("Unable to parse string: {:?}", msg));
|
||||
|
||||
println!("Incoming payload: {:?}", command);
|
||||
debug!("Incoming payload: {:?}", command);
|
||||
|
||||
match command {
|
||||
CallbackType::SelectInstallDir { callback_name } => {
|
||||
|
@ -155,7 +164,7 @@ fn main() {
|
|||
let result =
|
||||
serde_json::to_string(&result).expect("Unable to serialize response");
|
||||
let command = format!("{}({});", callback_name, result);
|
||||
println!("Injecting response: {}", command);
|
||||
debug!("Injecting response: {}", command);
|
||||
wv.eval(&command);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -165,7 +165,7 @@ impl Service for WebService {
|
|||
|
||||
match framework.uninstall(&sender) {
|
||||
Err(v) => {
|
||||
eprintln!("Uninstall error occurred: {:?}", v);
|
||||
error!("Uninstall error occurred: {:?}", v);
|
||||
sender.send(InstallMessage::Error(v)).unwrap();
|
||||
},
|
||||
_ => {}
|
||||
|
@ -238,7 +238,7 @@ impl Service for WebService {
|
|||
|
||||
match framework.install(to_install, &sender, new_install) {
|
||||
Err(v) => {
|
||||
eprintln!("Install error occurred: {:?}", v);
|
||||
error!("Install error occurred: {:?}", v);
|
||||
sender.send(InstallMessage::Error(v)).unwrap();
|
||||
},
|
||||
_ => {}
|
||||
|
|
|
@ -34,7 +34,7 @@ impl Task for DownloadPackageTask {
|
|||
for element in &context.database {
|
||||
if element.name == self.name {
|
||||
if element.version == version {
|
||||
println!("{:?} is already up to date.", self.name);
|
||||
info!("{:?} is already up to date.", self.name);
|
||||
return Ok(TaskParamType::Break);
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -109,7 +109,7 @@ impl Task for InstallPackageTask {
|
|||
continue;
|
||||
}
|
||||
|
||||
println!("Creating file: {:?}", target_path);
|
||||
info!("Creating file: {:?}", target_path);
|
||||
|
||||
installed_files.push(filename.to_string());
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ impl Task for ResolvePackageTask {
|
|||
.next()
|
||||
.unwrap();
|
||||
|
||||
println!("Selected file: {:?}", latest_file);
|
||||
info!("Selected file: {:?}", latest_file);
|
||||
|
||||
Ok(TaskParamType::File(latest_version, latest_file))
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ impl Task for UninstallPackageTask {
|
|||
for file in package.files {
|
||||
let name = file.clone();
|
||||
let file = path.join(file);
|
||||
println!("Deleting {:?}", file);
|
||||
info!("Deleting {:?}", file);
|
||||
|
||||
messenger(
|
||||
&format!("Deleting {} ({} of {})", name, i + 1, max),
|
||||
|
@ -75,7 +75,7 @@ impl Task for UninstallPackageTask {
|
|||
};
|
||||
|
||||
match result {
|
||||
Err(v) => eprintln!("Failed to delete file: {:?}", v),
|
||||
Err(v) => error!("Failed to delete file: {:?}", v),
|
||||
_ => {}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue