colorful and better interaction

Use colored texts.
Default enable feature clone.
Add panic hook to avoid program exit.
This commit is contained in:
2025-03-30 21:20:05 +08:00
parent 9d703833e4
commit ad98236e06
4 changed files with 35 additions and 12 deletions

2
.gitignore vendored
View File

@@ -1 +1,3 @@
/target /target
*.exe
*.zip

12
Cargo.lock generated
View File

@@ -60,6 +60,15 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "colored"
version = "3.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fde0e0ec90c9dfb3b4b1a0891a7dcd0e2bffde2f7efed5fe7c9bb00e5bfb915e"
dependencies = [
"windows-sys",
]
[[package]] [[package]]
name = "console" name = "console"
version = "0.15.11" version = "0.15.11"
@@ -295,8 +304,9 @@ checksum = "30bde2b3dc3671ae49d8e2e9f044c7c005836e7a023ee57cffa25ab82764bb9e"
[[package]] [[package]]
name = "mhws-tex-decompressor" name = "mhws-tex-decompressor"
version = "0.1.2" version = "0.1.3"
dependencies = [ dependencies = [
"colored",
"dialoguer", "dialoguer",
"eyre", "eyre",
"indicatif", "indicatif",

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "mhws-tex-decompressor" name = "mhws-tex-decompressor"
version = "0.1.2" version = "0.1.3"
edition = "2024" edition = "2024"
[dependencies] [dependencies]
@@ -16,3 +16,4 @@ eyre = "0.6"
indicatif = "0.17" indicatif = "0.17"
rayon = "1.10" rayon = "1.10"
parking_lot = "0.12" parking_lot = "0.12"
colored = "3.0"

View File

@@ -9,6 +9,7 @@ use std::{
time::Duration, time::Duration,
}; };
use colored::Colorize;
use dialoguer::{Input, Select, theme::ColorfulTheme}; use dialoguer::{Input, Select, theme::ColorfulTheme};
use indicatif::{HumanBytes, ProgressBar, ProgressStyle}; use indicatif::{HumanBytes, ProgressBar, ProgressStyle};
use parking_lot::Mutex; use parking_lot::Mutex;
@@ -24,16 +25,24 @@ use ree_pak_core::{
const FILE_NAME_LIST: &[u8] = include_bytes!("../assets/MHWs_STM_Release.list.zst"); const FILE_NAME_LIST: &[u8] = include_bytes!("../assets/MHWs_STM_Release.list.zst");
fn main() { fn main() {
std::panic::set_hook(Box::new(panic_hook));
println!("Version v{} - Tool by @Eigeen", env!("CARGO_PKG_VERSION")); println!("Version v{} - Tool by @Eigeen", env!("CARGO_PKG_VERSION"));
if let Err(e) = main_entry() { if let Err(e) = main_entry() {
eprintln!("Error: {e}"); eprintln!("{}: {}", "Error".red().bold(), e);
wait_for_exit(); wait_for_exit();
std::process::exit(1); std::process::exit(1);
} }
wait_for_exit(); wait_for_exit();
} }
fn panic_hook(info: &std::panic::PanicHookInfo) {
eprintln!("{}: {}", "Panic".red().bold(), info);
wait_for_exit();
std::process::exit(1);
}
fn main_entry() -> eyre::Result<()> { fn main_entry() -> eyre::Result<()> {
let input: String = Input::with_theme(&ColorfulTheme::default()) let input: String = Input::with_theme(&ColorfulTheme::default())
.show_default(true) .show_default(true)
@@ -52,9 +61,7 @@ fn main_entry() -> eyre::Result<()> {
const FALSE_TRUE_SELECTION: [&str; 2] = ["False", "True"]; const FALSE_TRUE_SELECTION: [&str; 2] = ["False", "True"];
let use_full_package_mode = Select::with_theme(&ColorfulTheme::default()) let use_full_package_mode = Select::with_theme(&ColorfulTheme::default())
.with_prompt( .with_prompt("Package all files, including non-tex files (for replacing original files)")
"Package all files, including non-tex parts (suitable for replacing original files)",
)
.default(0) .default(0)
.items(&FALSE_TRUE_SELECTION) .items(&FALSE_TRUE_SELECTION)
.interact() .interact()
@@ -62,8 +69,8 @@ fn main_entry() -> eyre::Result<()> {
let use_full_package_mode = use_full_package_mode == 1; let use_full_package_mode = use_full_package_mode == 1;
let use_feature_clone = Select::with_theme(&ColorfulTheme::default()) let use_feature_clone = Select::with_theme(&ColorfulTheme::default())
.with_prompt("Clone feature flags from original file? (experimental)") .with_prompt("Clone feature flags from original file?")
.default(0) .default(1)
.items(&FALSE_TRUE_SELECTION) .items(&FALSE_TRUE_SELECTION)
.interact() .interact()
.unwrap(); .unwrap();
@@ -176,10 +183,12 @@ fn main_entry() -> eyre::Result<()> {
}; };
bar.finish(); bar.finish();
println!("Done!"); println!("{}", "Done!".cyan().bold());
println!( if !use_full_package_mode {
"You should rename the output file like `re_chunk_000.pak.sub_000.pak.patch_xxx.pak`, or manage it by your favorite mod manager." println!(
); "You should rename the output file like `re_chunk_000.pak.sub_000.pak.patch_xxx.pak`, or manage it by your favorite mod manager."
);
}
Ok(()) Ok(())
} }
@@ -212,6 +221,7 @@ where
fn wait_for_exit() { fn wait_for_exit() {
let _: String = Input::with_theme(&ColorfulTheme::default()) let _: String = Input::with_theme(&ColorfulTheme::default())
.with_prompt("Press Enter to exit")
.allow_empty(true) .allow_empty(true)
.interact_text() .interact_text()
.unwrap(); .unwrap();