自动打印输出文件夹
Some checks failed
Release / Publish to Github Releases (, macos-latest, aarch64-apple-darwin, true) (push) Has been cancelled
Release / Publish to Github Releases (, macos-latest, x86_64-apple-darwin) (push) Has been cancelled
Release / Publish to Github Releases (, ubuntu-latest, aarch64-unknown-linux-musl, true) (push) Has been cancelled
Release / Publish to Github Releases (, ubuntu-latest, arm-unknown-linux-musleabihf, true) (push) Has been cancelled
Release / Publish to Github Releases (, ubuntu-latest, armv7-unknown-linux-musleabihf, true) (push) Has been cancelled
Release / Publish to Github Releases (, ubuntu-latest, i686-unknown-linux-musl, true) (push) Has been cancelled
Release / Publish to Github Releases (, ubuntu-latest, x86_64-unknown-linux-musl, true) (push) Has been cancelled
Release / Publish to Github Releases (, windows-latest, aarch64-pc-windows-msvc, true) (push) Has been cancelled
Release / Publish to Github Releases (, windows-latest, i686-pc-windows-msvc, true) (push) Has been cancelled
Release / Publish to Github Releases (, windows-latest, x86_64-pc-windows-msvc) (push) Has been cancelled
Release / Publish to crates.io (push) Has been cancelled

This commit is contained in:
Lkhsss
2025-03-23 01:05:07 +08:00
parent a6f37a961c
commit f1ee83bf79
8 changed files with 76 additions and 41 deletions

View File

@ -21,6 +21,6 @@ pub struct Cli {
pub forcesave: bool,
/// 自动打开输出目录
#[arg(short,long,name="自动打开输出目录")]
pub autoopen:bool,
#[arg(short, long, name = "自动打开输出目录")]
pub autoopen: bool,
}

View File

@ -3,6 +3,7 @@ use colored::{Color, Colorize};
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
use lazy_static::lazy_static;
use log::{error, info, warn};
use messager::Message;
use std::time::Duration;
use std::{
path::Path,
@ -16,13 +17,13 @@ mod clap;
mod logger;
mod messager;
mod ncmdump;
mod opendir;
mod pathparse;
mod test;
mod threadpool;
mod opendir;
use ncmdump::Ncmfile;
const DEFAULT_MAXWORKER:usize = 8;
const DEFAULT_MAXWORKER: usize = 8;
fn main() {
let timer = ncmdump::TimeCompare::new();
@ -54,7 +55,9 @@ fn main() {
let undumpfile = pathparse::pathparse(input); // 该列表将存入文件的路径
let taskcount = undumpfile.len();
let successful = Arc::new(Mutex::new(0));
let mut success_count = 0; //成功任务数
if taskcount == 0 {
error!("没有找到有效文件。使用-i参数输入需要解密的文件或文件夹。")
} else {
@ -70,17 +73,20 @@ fn main() {
// 循环开始
for filepath in undumpfile {
let output = outputdir.clone();
let successful = Arc::clone(&successful);
let sender: Sender<messager::Message> = tx.clone();
let senderin: Sender<messager::Message> = tx.clone();
let senderon: Sender<messager::Message> = tx.clone();
pool.execute(move || match Ncmfile::new(filepath.as_str()) {
Ok(mut n) => match n.dump(Path::new(&output), sender, forcesave) {
Ok(_) => {
let mut num = successful.lock().unwrap();
*num += 1;
Ok(mut n) => match n.dump(Path::new(&output), senderin, forcesave) {
Ok(_) => {}
Err(e) => {
let messager = messager::Messager::new(n.fullfilename, senderon);
messager.send(messager::Signals::Err(e));
}
Err(e) => error!("[{}] 解密失败: {}", filepath.yellow(), e),
},
Err(e) => error!("[{}] 解密失败: {}", filepath.yellow(), e),
Err(e) => {
let messager = messager::Messager::new(filepath, senderon);
messager.send(messager::Signals::Err(e));
}
});
}
//循环到此结束
@ -96,13 +102,21 @@ fn main() {
)
.with_message("解密中");
let progressbar = MP.add(pb);
//接受消息
//定义计数器
// 接受消息!!!!!!!!!!
for messages in rx {
progressbar.inc(1);
messages.log(); //发送log
match messages.signal{
messager::Signals::End|messager::Signals::Err(_)=>{success_count+=1},
_=>()
}
if success_count < taskcount {
progressbar.inc(1);
messages.log(); //发送log
} else {
break;
}
}
progressbar.finish_and_clear();
}
let timecount = timer.compare();
@ -113,20 +127,20 @@ fn main() {
format!("共计用时{}毫秒", timecount)
}
};
let successful = *successful.lock().unwrap();
info!(
"成功解密{}个文件,{}个文件解密失败,{}",
successful.to_string().bright_green(),
(taskcount - successful).to_string().bright_red(),
success_count.to_string().bright_green(),
(taskcount - success_count).to_string().bright_red(),
showtime()
);
// 自动打开输出文件夹
if cli.autoopen{
if cli.autoopen {
info!("自动打开文件夹:[{}]", outputdir.cyan());
opendir::opendir(outputdir.into());
} else {
info!("输出文件夹:[{}]", outputdir.cyan());
};
}
lazy_static! {

View File

@ -1,7 +1,7 @@
use colored::Colorize;
use log::info;
use log::{error, info, warn};
use crate::messager;
use crate::{messager, ncmdump};
use std::fmt::Debug;
use std::sync::mpsc;
pub struct Messager {
@ -23,10 +23,19 @@ impl Message {
Signals::Decrypt => "解密歌曲信息",
Signals::Save => "保存文件",
Signals::End => "成功!",
Signals::Err(e)=>&e.to_string(),
};
info!("[{}] {}", self.name.cyan(), loginfo)
match &self.signal{
Signals::Err(e)=>{match e{
ncmdump::NcmError::ProtectFile=>warn!("[{}] {}", self.name.cyan(), loginfo),
_=>error!("[{}] {}", self.name.cyan(), loginfo),
}},
_=>info!("[{}] {}", self.name.cyan(), loginfo)
}
}
}
#[derive(PartialEq)]
pub enum Signals {
Start,
GetMetaInfo,
@ -34,6 +43,7 @@ pub enum Signals {
Decrypt,
Save,
End,
Err(ncmdump::NcmError),
}
impl Messager {
@ -56,6 +66,8 @@ impl Debug for Message {
Signals::End => "破解完成",
Signals::GetMetaInfo => "获取元数据",
Signals::GetCover => "获取封面",
Signals::Err(e)=>&e.to_string(),
};
write!(f, "[{}] {}", self.name, message)
}

View File

@ -559,7 +559,7 @@ fn unpad(data: &[u8]) -> Vec<u8> {
data[..data.len() - data[data.len() - 1] as usize].to_vec()
}
#[derive(Debug)]
#[derive(Debug,PartialEq)]
#[allow(dead_code)]
pub enum NcmError {
NotNcmFile,