From 94b2c6f8ddca1254da457b56680ac902ab2714f8 Mon Sep 17 00:00:00 2001 From: H2Sxxa Date: Sat, 3 Aug 2024 11:50:34 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=96=20v0.2.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/datatypes.rs | 32 ++++++++++++++++++++++++-------- src/main.rs | 38 ++++++++++++++++++++++++++++---------- 4 files changed, 54 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e0dd27d..7371951 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -271,7 +271,7 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "jsbp" -version = "0.1.1" +version = "0.2.0" dependencies = [ "clap", "serde", diff --git a/Cargo.toml b/Cargo.toml index c621a5c..468e52e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "jsbp" -version = "0.1.1" +version = "0.2.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/datatypes.rs b/src/datatypes.rs index e317c72..fb8803f 100644 --- a/src/datatypes.rs +++ b/src/datatypes.rs @@ -19,6 +19,7 @@ pub struct CliArgs { /// The path to the config of patch /// 修补的配置文件路径 /// Example(config.yml) + /// /// ```yaml /// classes: /// - path/to/the/target.class @@ -34,27 +35,42 @@ pub struct CliArgs { #[arg(short, long, verbatim_doc_comment)] pub target: String, - /// The path to the `jar.exe` in `%JAVA_HOME%/bin` - /// `%JAVA_HOME%` 中的 `jar.exe` 的路径 - #[arg(short, long, default_value_t = format!("jar"),verbatim_doc_comment)] - pub jartool: String, + /// The tool to update file in jar + /// 用来更新jar中文件的工具 + #[arg(long, value_name = "jar/7zip", default_value_t = format!("jar"), verbatim_doc_comment)] + pub tool: String, + + /// The path to `7zip` executable file + /// `%JAVA_HOME%` 中的 `7zip` 的路径 + #[arg(long, default_value_t = format!("7z"), verbatim_doc_comment)] + pub _7zip: String, + + /// The path to `jar` executable file + /// 可执行文件 `jar` 的路径 + #[arg(long, default_value_t = format!("jar"), verbatim_doc_comment)] + pub jar: String, + + /// The path to ouput file + /// 输出的文件路径 + #[arg(short, long, default_value_t = format!("%origin%.patch"), verbatim_doc_comment)] + pub output: String, /// Always used to restore the patch /// 通常用来恢复修补 #[arg(short, long, verbatim_doc_comment)] pub reverse: bool, - /// Save the log of `jar.exe` - /// 保存 `jar.exe` 日志 + /// Save the log of patch tool + /// 保存修补工具日志 #[arg(short, long, verbatim_doc_comment)] pub log: bool, /// Overlaid target jar file /// 覆盖目标文件 - #[arg(short, long, verbatim_doc_comment)] + #[arg(long, verbatim_doc_comment)] pub overlaid: bool, - /// Enable Async Patch + /// Enable asynchronous patch /// 启用异步修补 #[arg(short, long, verbatim_doc_comment)] pub asynchronous: bool, diff --git a/src/main.rs b/src/main.rs index 8a4496b..2675d22 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,7 +29,7 @@ async fn main() { if args.overlaid { filepath = Path::new(&args.target); } else { - patchname = format!("{}.patch", args.target); + patchname = args.output.replace("%origin%", &args.target); copy(&args.target, &patchname).unwrap(); filepath = Path::new(&patchname); } @@ -40,6 +40,8 @@ async fn main() { let archive: Arc>>>> = Arc::new(Mutex::new( ZipArchive::new(Cursor::new(read(&filename).unwrap())).unwrap(), )); + + println!("Clean cache dir..."); let _ = remove_dir_all("cache"); create_dir("cache").unwrap(); @@ -73,26 +75,42 @@ async fn main() { } println!("Waiting to executing jartool..."); - let output = Command::new(args.jartool) - .current_dir("cache") - .args(["-uvf", filename.as_str(), "*"]) - .output() - .expect("Failed in append"); + let output = match args.tool.as_str() { + "jar" => Command::new(args.jar) + .args(["-uvf", filename.as_str(), "*"]) + .current_dir("cache") + .output() + .expect("Failed in append"), + "7zip" => Command::new(args._7zip) + .args(["u", filename.as_str(), "*"]) + .current_dir("cache") + .output() + .expect("Failed in append"), + _ => { + println!("Unknown tool! default to `jar`"); + Command::new(args.jar) + .args(["-uvf", filename.as_str(), "*"]) + .current_dir("cache") + .output() + .expect("Failed in append") + } + }; let _ = stdout().write_all(&output.stdout); let _ = stderr().write_all(&output.stderr); if args.log { - File::create("jartool-stdout.log") + File::create("tool-stdout.log") .unwrap() .write_all(&output.stdout) .unwrap(); - File::create("jartool-stderr.log") + File::create("tool-stderr.log") .unwrap() - .write_all(&output.stdout) + .write_all(&output.stderr) .unwrap(); } - println!("Patch Successfully!"); + + println!("Patch Done!"); } #[test]