diff --git a/Cargo.lock b/Cargo.lock index edabc94..8c94b61 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -32,6 +32,7 @@ dependencies = [ name = "alterware-launcher" version = "0.4.8" dependencies = [ + "colored", "http_req", "mslnk", "rand", @@ -137,6 +138,17 @@ dependencies = [ "inout", ] +[[package]] +name = "colored" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2674ec482fbc38012cf31e6c42ba0177b431a0cb6f15fe40efa5aab1bda516f6" +dependencies = [ + "is-terminal", + "lazy_static", + "windows-sys", +] + [[package]] name = "constant_time_eq" version = "0.1.5" @@ -284,6 +296,12 @@ dependencies = [ "wasi", ] +[[package]] +name = "hermit-abi" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" + [[package]] name = "hmac" version = "0.12.1" @@ -323,6 +341,17 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "is-terminal" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" +dependencies = [ + "hermit-abi", + "rustix", + "windows-sys", +] + [[package]] name = "itoa" version = "1.0.6" @@ -372,6 +401,12 @@ dependencies = [ "thiserror", ] +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + [[package]] name = "libc" version = "0.2.147" diff --git a/Cargo.toml b/Cargo.toml index 01b2b83..1f3d1a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,7 @@ serde_json = "1.0.105" rand = "0.8.5" semver = "1.0.18" zip = "0.6.6" +colored = "2.0.4" [target.'cfg(windows)'.dependencies] steamlocate = "2.0.0-alpha.0" diff --git a/src/iw4x.rs b/src/iw4x.rs index 4d03e99..d534a3f 100644 --- a/src/iw4x.rs +++ b/src/iw4x.rs @@ -4,6 +4,7 @@ use crate::http; use crate::misc; use std::{fs, path::Path}; +use colored::*; pub fn local_revision(dir: &Path) -> u16 { if let Ok(revision) = fs::read_to_string(dir.join(".iw4xrevision")) { @@ -25,7 +26,7 @@ pub fn update(dir: &Path) { return; } - println!("Updating IW4x..."); + println!("[{}] {}", "Downloading".bright_yellow(), dir.join("iw4x.dll").display()); http::download_file( &format!( "{}/download/iw4x.dll", diff --git a/src/main.rs b/src/main.rs index 97911e3..36f9593 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,6 +15,7 @@ use mslnk::ShellLink; use std::{fs, path::Path, path::PathBuf}; #[cfg(windows)] use steamlocate::SteamDir; +use colored::*; #[cfg(windows)] fn get_installed_games(games: &Vec) -> Vec<(u32, PathBuf)> { @@ -22,7 +23,7 @@ fn get_installed_games(games: &Vec) -> Vec<(u32, PathBuf)> { let mut steamdir = match SteamDir::locate() { Some(steamdir) => steamdir, None => { - println!("Steam not found."); + println!("{}", "Steam not found!".yellow()); return installed_games; } }; @@ -39,7 +40,7 @@ fn get_installed_games(games: &Vec) -> Vec<(u32, PathBuf)> { #[cfg(windows)] fn setup_client_links(game: &Game, game_dir: &Path) { if game.client.len() > 1 { - println!("Multiple clients installed, use the shortcuts (launch-.lnk in the game directory or desktop shortcuts) to launch a specific client."); + println!("Multiple clients installed, use the shortcuts (launch-.lnk in the game directory or on the desktop) to launch a specific client."); } let target = game_dir.join("alterware-launcher.exe"); @@ -96,7 +97,7 @@ fn auto_install(path: &Path, game: &Game) { #[cfg(windows)] fn windows_launcher_install(games: &Vec) { - println!("No game specified/found. Checking for installed Steam games.."); + println!("{}", "No game specified/found. Checking for installed Steam games..".yellow()); let installed_games = get_installed_games(games); if !installed_games.is_empty() { @@ -186,17 +187,16 @@ fn update_dir(cdn_info: &Vec, remote_dir: &str, dir: &Path) { let sha1_remote = file.hash.to_lowercase(); if sha1_local != sha1_remote { println!( - "Updating {}...\nLocal hash: {}\nRemote hash: {}", - file_path.display(), - sha1_local, - sha1_remote + "[{}] {}", + "Updating".bright_yellow(), + file_path.display() ); http::download_file(&format!("{}/{}", MASTER, file.name), &file_path); } else { - println!("{} is up to date.", file_path.display()); + println!("[{}] {}", "Checked".bright_blue(), file_path.display()); } } else { - println!("Downloading {}...", file_path.display()); + println!("[{}] {}", "Downloading".bright_yellow(), file_path.display()); if let Some(parent) = file_path.parent() { if !parent.exists() { fs::create_dir_all(parent).unwrap(); @@ -235,7 +235,18 @@ fn launch(file_path: &PathBuf) { .expect("Failed to wait for the game process to finish"); } +#[cfg(windows)] +fn setup_env() { + colored::control::set_virtual_terminal(true).unwrap_or_else(|error| { + println!("{:#?}", error); + colored::control::SHOULD_COLORIZE.set_override(false); + }); +} + fn main() { + #[cfg(windows)] + setup_env(); + let mut args: Vec = std::env::args().collect(); let mut cfg = config::load(PathBuf::from("alterware-launcher.json")); @@ -334,7 +345,7 @@ fn main() { #[cfg(not(windows))] manual_install(&games); - println!("Game not found!"); + println!("{}", "Game not found!".bright_red()); println!("Place the launcher in the game folder, if that doesn't work specify the client on the command line (ex. alterware-launcher.exe iw4-sp)"); println!("Press enter to exit..."); std::io::stdin().read_line(&mut String::new()).unwrap();