diff --git a/CHANGELOG.md b/CHANGELOG.md index 56d49d2..fd4d558 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -81,11 +81,12 @@ - :hammer: 将代码分离为单个文件 - :hammer: 优化解密算法,提高解密效率 - ## [2.8.20] - 2025.8.26 - ### Features :sparkles: - - 自动构建增加upx压缩 +## [2.8.20] - 2025.8.26 +### Features :sparkles: +- 自动构建增加upx压缩 - ## [2.9.20] - 2025.9.4 - ### Features :sparkles: - - 可以手动开关是否输出彩色 \ No newline at end of file +## [2.9.21] - 2025.9.7 +### Fixed :bug: + - 当未指定输入文件时使用`-a`参数仍然可以打开输出目录 + - 更换终端彩色库以支持Windows默认不启用ANSI转义序列的终端 \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index aa8c333..4ab183a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -227,9 +227,9 @@ checksum = "8f1fe948ff07f4bd06c30984e69f5b4899c516a3ef74f34df92a2df2ab535495" [[package]] name = "cc" -version = "1.2.35" +version = "1.2.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "590f9024a68a8c40351881787f1934dc11afd69090f5edb6831464694d836ea3" +checksum = "5252b3d2648e5eedbc1a6f501e3c795e07025c1e93bbf8bbdd6eef7f447a6d54" dependencies = [ "find-msvc-tools", "jobserver", @@ -327,15 +327,6 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" -[[package]] -name = "colored" -version = "3.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fde0e0ec90c9dfb3b4b1a0891a7dcd0e2bffde2f7efed5fe7c9bb00e5bfb915e" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "console" version = "0.16.0" @@ -349,6 +340,15 @@ dependencies = [ "windows-sys 0.60.2", ] +[[package]] +name = "convert_case" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb402b8d4c85569410425650ce3eddc7d698ed96d39a73f941b08fb63082f1e7" +dependencies = [ + "unicode-segmentation", +] + [[package]] name = "core-foundation-sys" version = "0.8.7" @@ -407,6 +407,33 @@ version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" +[[package]] +name = "crossterm" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8b9f2e4c67f833b660cdb0a3523065869fb35570177239812ed4c905aeff87b" +dependencies = [ + "bitflags", + "crossterm_winapi", + "derive_more", + "document-features", + "mio", + "parking_lot", + "rustix", + "signal-hook", + "signal-hook-mio", + "winapi", +] + +[[package]] +name = "crossterm_winapi" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acdd7c62a3665c7f6830a51635d9ac9b23ed385797f70a83bb8bafe9c572ab2b" +dependencies = [ + "winapi", +] + [[package]] name = "crunchy" version = "0.2.4" @@ -423,6 +450,36 @@ dependencies = [ "typenum", ] +[[package]] +name = "derive_more" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "093242cf7570c207c83073cf82f79706fe7b8317e98620a47d5be7c3d8497678" +dependencies = [ + "derive_more-impl", +] + +[[package]] +name = "derive_more-impl" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda628edc44c4bb645fbe0f758797143e4e07926f7ebf4e9bdfbd3d2ce621df3" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "document-features" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95249b50c6c185bee49034bcb378a49dc2b5dff0be90ff6616d31d64febab05d" +dependencies = [ + "litrs", +] + [[package]] name = "either" version = "1.15.0" @@ -480,6 +537,16 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" +[[package]] +name = "errno" +version = "0.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "778e2ac28f6c47af28e4907f13ffd1e1ddbd400980a9abd7c8df189bf578a5ad" +dependencies = [ + "libc", + "windows-sys 0.60.2", +] + [[package]] name = "exr" version = "1.73.0" @@ -526,9 +593,9 @@ dependencies = [ [[package]] name = "find-msvc-tools" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e178e4fba8a2726903f6ba98a6d221e76f9c12c650d5dc0e6afdc50677b49650" +checksum = "7fd99930f64d146689264c637b5af2f0233a933bef0d8570e2526bf9e083192d" [[package]] name = "flate2" @@ -570,7 +637,7 @@ dependencies = [ "cfg-if", "libc", "r-efi", - "wasi 0.14.3+wasi-0.2.4", + "wasi 0.14.4+wasi-0.2.4", ] [[package]] @@ -768,9 +835,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.77" +version = "0.3.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" +checksum = "0c0b063578492ceec17683ef2f8c5e89121fbd0b172cbc280635ab7567db2738" dependencies = [ "once_cell", "wasm-bindgen", @@ -784,9 +851,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "lebe" -version = "0.5.2" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8" +checksum = "7a79a3332a6609480d7d0c9eab957bca6b455b91bb84e66d19f5ff66294b85b8" [[package]] name = "libc" @@ -804,6 +871,28 @@ dependencies = [ "cc", ] +[[package]] +name = "linux-raw-sys" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12" + +[[package]] +name = "litrs" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5e54036fe321fd421e10d732f155734c4e4afd610dd556d9a82833ab3ee0bed" + +[[package]] +name = "lock_api" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96936507f153605bddfcda068dd804796c84324ed2510809e5b2a624c81da765" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "log" version = "0.4.28" @@ -861,6 +950,18 @@ dependencies = [ "simd-adler32", ] +[[package]] +name = "mio" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78bed444cc8a2160f01cbcf811ef18cac863ad68ae8ca62092e8db51d51c761c" +dependencies = [ + "libc", + "log", + "wasi 0.11.1+wasi-snapshot-preview1", + "windows-sys 0.59.0", +] + [[package]] name = "moxcms" version = "0.7.5" @@ -896,8 +997,8 @@ dependencies = [ "base64", "chrono", "clap", - "colored", "crossbeam-channel", + "crossterm", "env_logger", "image", "indicatif", @@ -1004,6 +1105,29 @@ version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad" +[[package]] +name = "parking_lot" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70d58bf43669b5795d1576d0641cfb6fbb2057bf629506267a92807158584a13" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc838d2a56b5b1a6c25f55575dfc605fabb63bb2365f6c2353ef9159aa69e4a5" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.52.6", +] + [[package]] name = "paste" version = "1.0.15" @@ -1074,9 +1198,9 @@ dependencies = [ [[package]] name = "pxfm" -version = "0.1.20" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e790881194f6f6e86945f0a42a6981977323669aeb6c40e9c7ec253133b96f8" +checksum = "f55f4fedc84ed39cb7a489322318976425e42a147e2be79d8f878e2884f94e84" dependencies = [ "num-traits", ] @@ -1217,12 +1341,34 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08ad765b21a08b1a8e5cdce052719188a23772bcbefb3c439f0baaf62c56ceac" +[[package]] +name = "redox_syscall" +version = "0.5.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5407465600fb0548f1442edf71dd20683c6ed326200ace4b1ef0763521bb3b77" +dependencies = [ + "bitflags", +] + [[package]] name = "rgb" version = "0.8.52" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c6a884d2998352bb4daf0183589aec883f16a6da1f4dde84d8e2e9a5409a1ce" +[[package]] +name = "rustix" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11181fbabf243db407ef8df94a6ce0b2f9a733bd8be4ad02b4eda9602296cac8" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.60.2", +] + [[package]] name = "rustversion" version = "1.0.22" @@ -1244,6 +1390,12 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + [[package]] name = "serde" version = "1.0.219" @@ -1291,6 +1443,36 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" +[[package]] +name = "signal-hook" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d881a16cf4426aa584979d30bd82cb33429027e42122b169753d6ef1085ed6e2" +dependencies = [ + "libc", + "signal-hook-registry", +] + +[[package]] +name = "signal-hook-mio" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34db1a06d485c9142248b7a054f034b349b212551f3dfd19c94d45a754a217cd" +dependencies = [ + "libc", + "mio", + "signal-hook", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2a4719bff48cee6b39d12c020eeb490953ad2443b7055bd0b21fca26bd8c28b" +dependencies = [ + "libc", +] + [[package]] name = "simd-adler32" version = "0.3.7" @@ -1428,6 +1610,12 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" +[[package]] +name = "unicode-segmentation" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" + [[package]] name = "unicode-width" version = "0.2.1" @@ -1487,30 +1675,31 @@ checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" [[package]] name = "wasi" -version = "0.14.3+wasi-0.2.4" +version = "0.14.4+wasi-0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a51ae83037bdd272a9e28ce236db8c07016dd0d50c27038b3f407533c030c95" +checksum = "88a5f4a424faf49c3c2c344f166f0662341d470ea185e939657aaff130f0ec4a" dependencies = [ "wit-bindgen", ] [[package]] name = "wasm-bindgen" -version = "0.2.100" +version = "0.2.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" +checksum = "7e14915cadd45b529bb8d1f343c4ed0ac1de926144b746e2710f9cd05df6603b" dependencies = [ "cfg-if", "once_cell", "rustversion", "wasm-bindgen-macro", + "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.100" +version = "0.2.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" +checksum = "e28d1ba982ca7923fd01448d5c30c6864d0a14109560296a162f80f305fb93bb" dependencies = [ "bumpalo", "log", @@ -1522,9 +1711,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.100" +version = "0.2.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" +checksum = "7c3d463ae3eff775b0c45df9da45d68837702ac35af998361e2c84e7c5ec1b0d" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1532,9 +1721,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.100" +version = "0.2.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" +checksum = "7bb4ce89b08211f923caf51d527662b75bdc9c9c7aab40f86dcb9fb85ac552aa" dependencies = [ "proc-macro2", "quote", @@ -1545,9 +1734,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.100" +version = "0.2.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" +checksum = "f143854a3b13752c6950862c906306adb27c7e839f7414cec8fea35beab624c1" dependencies = [ "unicode-ident", ] @@ -1568,6 +1757,22 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a751b3277700db47d3e574514de2eced5e54dc8a5436a3bf7a0b248b2cee16f3" +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + [[package]] name = "winapi-util" version = "0.1.10" @@ -1577,6 +1782,12 @@ dependencies = [ "windows-sys 0.60.2", ] +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + [[package]] name = "windows-core" version = "0.61.2" @@ -1794,24 +2005,24 @@ dependencies = [ [[package]] name = "wit-bindgen" -version = "0.45.0" +version = "0.45.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "052283831dbae3d879dc7f51f3d92703a316ca49f91540417d38591826127814" +checksum = "5c573471f125075647d03df72e026074b7203790d41351cd6edc96f46bcccd36" [[package]] name = "zerocopy" -version = "0.8.26" +version = "0.8.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1039dd0d3c310cf05de012d8a39ff557cb0d23087fd44cad61df08fc31907a2f" +checksum = "0894878a5fa3edfd6da3f88c4805f4c8558e2b996227a3d864f47fe11e38282c" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.26" +version = "0.8.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181" +checksum = "88d2b8d9c68ad2b9e4340d7832716a4d21a22a1154777ad56ea55c51a9cf3831" dependencies = [ "proc-macro2", "quote", @@ -1835,9 +2046,9 @@ dependencies = [ [[package]] name = "zune-jpeg" -version = "0.4.20" +version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc1f7e205ce79eb2da3cd71c5f55f3589785cb7c79f6a03d1c8d1491bda5d089" +checksum = "29ce2c8a9384ad323cf564b67da86e21d3cfdff87908bc1223ed5c99bc792713" dependencies = [ "zune-core", ] diff --git a/Cargo.toml b/Cargo.toml index bcd4a7a..b417481 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,8 +17,8 @@ audiotags = { version = "0.5.0", default-features = false } base64 = { version = "0.22.*" } chrono = { version = "0.4.*", features = ["clock"], default-features = false } clap = { version = "4.5.*", features = ["derive", "std"] } -colored = { version = "3.0.0", default-features = false } crossbeam-channel = "0.5.15" +crossterm = "0.29.0" env_logger = { version = "0.11.7", default-features = false } image = "0.25.*" indicatif = "0.18.*" diff --git a/src/apperror.rs b/src/apperror.rs index d420408..9938cd6 100644 --- a/src/apperror.rs +++ b/src/apperror.rs @@ -14,6 +14,7 @@ pub enum AppError { FileDataError, SaveError, SystemTimeError, + CannotCreateDir, } impl std::error::Error for AppError {} @@ -34,8 +35,8 @@ impl std::fmt::Display for AppError { Self::FileDataError => "处理文件数据时出错", Self::SaveError => "保存文件出错", Self::SystemTimeError => "获取时间戳失败", - // _ => "未知错误", + Self::CannotCreateDir => "无法创建父级目录", // _ => "未知错误", }; write!(f, "{}", result) } -} \ No newline at end of file +} diff --git a/src/logger.rs b/src/logger.rs index 3af2b75..8a45164 100644 --- a/src/logger.rs +++ b/src/logger.rs @@ -1,5 +1,4 @@ -use colored::Color::{Cyan, Green, Red, Yellow,Magenta}; -use colored::Colorize; +use crossterm::style::{Color, Stylize}; //防止windows终端乱码 use indicatif::MultiProgress; use log::{Log, Metadata, Record, SetLoggerError}; use std::sync::Arc; @@ -16,6 +15,15 @@ impl Log for MultiProgressLogger { fn log(&self, record: &Record) { if self.enabled(record.metadata()) { + #[cfg(target_os = "windows")] + let level = match record.level() { + log::Level::Error => ("Error").with(Color::Red), + log::Level::Warn => ("Warn").with(Color::Yellow), + log::Level::Info => ("Info").with(Color::Green), + log::Level::Debug => ("Debug").with(Color::Magenta), + log::Level::Trace => ("Trace").with(Color::Cyan), + }; + #[cfg(not(target_os = "windows"))] let level = match record.level() { log::Level::Error => ("Error").color(Red), log::Level::Warn => ("Warn").color(Yellow), @@ -23,6 +31,7 @@ impl Log for MultiProgressLogger { log::Level::Debug => ("Debug").color(Magenta), log::Level::Trace => ("Trace").color(Cyan), }; + let message = format!( "[{}][{}] {}", chrono::Local::now().format("%H:%M:%S"), @@ -42,6 +51,6 @@ pub fn init_logger() -> Result<(), SetLoggerError> { mp: crate::MP.clone(), }; log::set_boxed_logger(Box::new(logger))?; - + Ok(()) } diff --git a/src/main.rs b/src/main.rs index 7b2cc79..e95b612 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ use ::clap::Parser; -use colored::{Color, Colorize}; use crossbeam_channel::{bounded, Sender}; +use crossterm::style::{Color, Stylize}; //防止windows终端乱码 use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; use lazy_static::lazy_static; use log::{error, info, warn, LevelFilter}; @@ -23,16 +23,7 @@ use apperror::AppError; use ncmdump::Ncmfile; use time::TimeCompare; - fn main() -> Result<(), AppError> { - let timer = match TimeCompare::new() { - Ok(t) => t, - Err(e) => { - error!("无法初始化时间戳系统。{}", e); - exit(1) - } - }; - // 初始化日志系统 match logger::init_logger() { Ok(_) => (), @@ -41,11 +32,22 @@ fn main() -> Result<(), AppError> { } }; + let timer = match TimeCompare::new() { + Ok(t) => t, + Err(e) => { + error!("无法初始化时间戳系统。{}", e); + exit(1) + } + }; + let cli = clap::Cli::parse(); //设置彩色输出 - let if_colorful = !cli.nocolor; - colored::control::set_override(if_colorful); + // let if_colorful = !cli.nocolor; + // colored::control::set_override(if_colorful); + // crossterm::terminal::enable_raw_mode() + //FIXME 更改颜色库 + //TODO控制颜色输出,更改为使用环境变量 //获取cpu核心数 let cpus = num_cpus::get(); @@ -58,7 +60,7 @@ fn main() -> Result<(), AppError> { 1 } } - None => cpus,//默认使用cpu核心数作为线程数 + None => cpus, //默认使用cpu核心数作为线程数 }; //输入目录 let input = cli.input; @@ -67,7 +69,7 @@ fn main() -> Result<(), AppError> { // 强制覆盖 let forcesave = cli.forcesave; if forcesave { - warn!("文件{}已开启!", "强制覆盖".bright_red()) + warn!("文件{}已开启!", "强制覆盖".with(Color::Red)) } let level = match cli.debug { 0 | 3 => LevelFilter::Info, @@ -77,7 +79,7 @@ fn main() -> Result<(), AppError> { 5 => LevelFilter::Trace, _ => LevelFilter::Off, }; - info!("日志等级:{}", level.to_string()); + info!("日志等级:{}", level); log::set_max_level(level); let undumpfile = pathparse::pathparse(input); // 该列表将存入文件的路径 @@ -88,16 +90,22 @@ fn main() -> Result<(), AppError> { let mut failure_count = 0; //发生错误的 if taskcount == 0 { - error!("没有找到有效文件。使用-i参数输入需要解密的文件或文件夹。"); + if cli.autoopen { + opendir::autoopen(cli.autoopen, outputdir); + } else { + error!("没有找到有效文件。使用-i参数输入需要解密的文件或文件夹。使用-a参数自动打开输出文件夹。"); + } + exit(2); }; + // 创建完整的父目录 + if std::fs::create_dir_all(&outputdir).is_err() { + return Err(AppError::CannotCreateDir); + } // 初始化线程池 let pool = threadpool::Pool::new(max_workers); - info!( - "将启用{}线程", - max_workers.to_string().color(Color::BrightGreen) - ); + info!("将启用{}线程", max_workers.to_string().with(Color::Green)); // 初始化通讯 // let (tx, rx) = mpsc::channel(); let (tx, rx) = bounded(taskcount * 6); @@ -145,7 +153,7 @@ fn main() -> Result<(), AppError> { Signals::Err(_) => failure_count += 1, _ => (), } - if (success_count+ignore_count+failure_count) < taskcount { + if (success_count + ignore_count + failure_count) < taskcount { progressbar.inc(1); // messages.log(); //发送log } else { @@ -164,19 +172,14 @@ fn main() -> Result<(), AppError> { }; info!( "成功解密{}个文件,跳过{}个文件,{}个文件解密失败,{}", - success_count.to_string().bright_green(), - ignore_count.to_string().purple(), - failure_count.to_string().bright_red(), + success_count.to_string().with(Color::Green), + ignore_count.to_string().with(Color::Magenta), + failure_count.to_string().with(Color::Red), showtime() ); // 自动打开输出文件夹 - if cli.autoopen { - info!("自动打开文件夹:[{}]", outputdir.cyan()); - opendir::opendir(outputdir.into()); - } else { - info!("输出文件夹:[{}]", outputdir.cyan()); - }; + opendir::autoopen(cli.autoopen, outputdir); Ok(()) } diff --git a/src/messager.rs b/src/messager.rs index 175167f..a08f3e8 100644 --- a/src/messager.rs +++ b/src/messager.rs @@ -1,5 +1,3 @@ - - use crate::{messager, AppError}; use std::fmt::Debug; // use diff --git a/src/ncmdump.rs b/src/ncmdump.rs index 7ba3393..91a40d3 100644 --- a/src/ncmdump.rs +++ b/src/ncmdump.rs @@ -5,13 +5,13 @@ use aes::cipher::{generic_array::GenericArray, BlockDecrypt, KeyInit}; use aes::Aes128; use audiotags::{MimeType, Picture, Tag}; use base64::{self, Engine}; -use colored::*; +use crossterm::style::{Color, Stylize}; //防止windows终端乱码 use log::{debug, info, trace}; use messager::Signals; use serde_derive::{Deserialize, Serialize}; use serde_json::{self, Value}; use std::fmt::Debug; -use std::fs::{self, File}; +use std::fs::File; use std::io::{BufReader, BufWriter, Read, Seek, SeekFrom, Write}; use std::path::{Path, PathBuf}; use std::str::from_utf8; @@ -132,7 +132,7 @@ impl Ncmfile { let mut buf: Vec = vec![0; (self.size - self.position) as usize]; let _ = reader.read_exact(&mut buf); self.position += length; - buf[..].to_vec() + buf[..].to_vec() } } else { let mut reader = BufReader::new(&self.file); @@ -154,7 +154,7 @@ impl Ncmfile { } ///按字节进行0x64异或。 fn parse_key(key: &mut [u8]) -> &[u8] { - for item in &mut *key { + for item in &mut *key { *item ^= 0x64; } key @@ -186,6 +186,15 @@ impl Ncmfile { fn unpad(data: &[u8]) -> Vec { data[..data.len() - data[data.len() - 1] as usize].to_vec() } + + fn get_filename(&self) -> &str { + &self.filename + } + + #[allow(dead_code)] + fn get_fullfilename(&self) -> &str { + &self.fullfilename + } } impl Ncmfile { @@ -273,23 +282,25 @@ impl Ncmfile { //处理文件路径 trace!("拼接文件路径"); let path = { - let filename = format!( + let output_filename = &format!( "{}.{}", - self.filename, + self.get_filename(), meta_data .get("format") .ok_or(AppError::CannotReadMetaInfo)? .as_str() .ok_or(AppError::CannotReadMetaInfo)? - ); + )[..]; - // let filename = standardize_filename(filename); - debug!("文件名:{}", filename.yellow()); + // let output_filename = standardize_filename(output_filename); + debug!("文件名:{}", output_filename.with(Color::Yellow)); + + //已在程序开头创建,无需浪费性能 //链级创建输出目录 - if fs::create_dir_all(outputdir).is_err() { - return Err(AppError::FileWriteError); - } - outputdir.join(filename) + // if fs::create_dir_all(outputdir).is_err() { + // return Err(AppError::FileWriteError); + // } + outputdir.join(output_filename) }; debug!("文件路径: {:?}", path); @@ -392,13 +403,13 @@ impl Ncmfile { info!( "[{}] 文件已保存到: {}", - self.filename.yellow(), - path.to_str().ok_or(AppError::SaveError)?.bright_cyan() + self.get_filename().with(Color::Yellow), + path.to_str().ok_or(AppError::SaveError)?.with(Color::Cyan) ); info!( "[{}]{}", - self.fullfilename.yellow(), - "解密成功".bright_green() + self.get_filename().with(Color::Yellow), + "解密成功".with(Color::Green) ); let _ = messager.send(Signals::End); Ok(()) diff --git a/src/opendir.rs b/src/opendir.rs index f19be65..3efbdb2 100644 --- a/src/opendir.rs +++ b/src/opendir.rs @@ -1,11 +1,13 @@ -use log::error; -use std::{path::PathBuf, process::Command}; +use crossterm::style::{Color, Stylize}; +use log::{error, info}; +use std::{path::PathBuf, process::Command}; //防止windows终端乱码 #[cfg(target_os = "windows")] pub fn opendir(dir: PathBuf) { if Command::new("explorer") .arg(&dir) // <- Specify the directory you'd like to open. - .spawn().is_err() + .spawn() + .is_err() { error!("无法打开输出文件夹:[{}]", dir.display()) } @@ -15,7 +17,8 @@ pub fn opendir(dir: PathBuf) { pub fn opendir(dir: PathBuf) { if Command::new("open") .arg(&dir) // <- Specify the directory you'd like to open. - .spawn().is_err() + .spawn() + .is_err() { error!("无法打开输出文件夹:[{}]", dir.display()) } @@ -24,8 +27,20 @@ pub fn opendir(dir: PathBuf) { pub fn opendir(dir: PathBuf) { if Command::new("open") .arg(&dir) // <- Specify the directory you'd like to open. - .spawn().is_err() + .spawn() + .is_err() { error!("无法打开输出文件夹:[{}]", dir.display()) } } + +// 自动打开输出文件夹的跨平台函数 +pub fn autoopen(if_auto_open: bool, path: String) { + let styled_path = (&path[..]).with(Color::Cyan); + if if_auto_open { + info!("自动打开文件夹:[{}]", styled_path); + opendir(path.into()); + } else { + info!("输出文件夹:[{}]", styled_path); + }; +}