From 9cfc997d627afdad7631666868ab1ff3e002b005 Mon Sep 17 00:00:00 2001 From: dark0dave Date: Fri, 6 Oct 2023 02:40:47 +0100 Subject: [PATCH] feat(readability): Users can now see errors and prompts, correctly Signed-off-by: dark0dave --- src/main.rs | 5 ++--- src/weidu.rs | 14 +++++++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 53c6ab9..344c552 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,7 +10,7 @@ use crate::{ copy_mod_folder, create_weidu_log_if_not_exists, mod_folder_present_in_game_directory, search_mod_folders, }, - weidu::{generate_args, install}, + weidu::install, }; mod args; @@ -48,8 +48,7 @@ fn main() { ); copy_mod_folder(&args.game_directory, mod_folder) } - let weidu_args = generate_args(&weidu_mod, &args.language); - install(&args.weidu_binary, &args.game_directory, weidu_args); + install(&args.weidu_binary, &args.game_directory, &weidu_mod, &args.language); log::info!("Installed mod {:?}", &weidu_mod); } } diff --git a/src/weidu.rs b/src/weidu.rs index 73a76a1..9ab4ff1 100644 --- a/src/weidu.rs +++ b/src/weidu.rs @@ -15,12 +15,12 @@ pub fn get_user_input() -> String { input.to_string() } -pub fn generate_args(weidu_mod: &ModComponent, language: &str) -> Vec { +fn generate_args(weidu_mod: &ModComponent, language: &str) -> Vec { format!("{mod_name}/{mod_tp_file} --quick-log --yes --ask-only {component} --use-lang {game_lang} --language {mod_lang}", mod_name = weidu_mod.name, mod_tp_file = weidu_mod.tp_file, component = weidu_mod.component, mod_lang = weidu_mod.lang, game_lang = language).split(' ').map(|x|x.to_string()).collect() } -pub fn install(weidu_binary: &PathBuf, game_directory: &PathBuf, weidu_args: Vec) { - log::trace!("{:#?}", weidu_args); +pub fn install(weidu_binary: &PathBuf, game_directory: &PathBuf, weidu_mod: &ModComponent, language: &str) { + let weidu_args = generate_args(&weidu_mod, language); let mut command = Command::new(weidu_binary); let weidu_process = command.current_dir(game_directory).args(weidu_args.clone()); @@ -38,8 +38,10 @@ pub fn install(weidu_binary: &PathBuf, game_directory: &PathBuf, weidu_args: Vec while child.stderr.is_none() { let mut text = String::new(); if reader.read_line(&mut text).is_ok() { - if !text.is_empty() && !failure_flag { + if !text.is_empty() && !failure_flag && !choice_flag { log::trace!("{}", text); + } else if choice_flag { + log::info!("{}", text); } else { log::error!("{}", text); } @@ -53,7 +55,7 @@ pub fn install(weidu_binary: &PathBuf, game_directory: &PathBuf, weidu_args: Vec panic!(); } - match text { + match text.clone() { // Choice _ if choice_flag => { if !text.chars().nth(1).unwrap_or_default().is_numeric() { @@ -74,6 +76,7 @@ pub fn install(weidu_binary: &PathBuf, game_directory: &PathBuf, weidu_args: Vec || x.trim_end().starts_with("Enter ")) && !x.to_ascii_lowercase().starts_with("[r]e-install") => { + log::info!("{}", text); log::trace!("Choice found"); choice_flag = true; } @@ -87,6 +90,7 @@ pub fn install(weidu_binary: &PathBuf, game_directory: &PathBuf, weidu_args: Vec // Install x if x.starts_with("Install") => { + log::info!("{}", text); stdin .write_all("\n".as_bytes()) .expect("Failed to write to stdin");