Skip to content

Commit

Permalink
🔖 v0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
H2Sxxa committed Aug 3, 2024
1 parent 224ded8 commit 94b2c6f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
32 changes: 24 additions & 8 deletions src/datatypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub struct CliArgs {
/// The path to the config of patch
/// 修补的配置文件路径
/// Example(config.yml)
///
/// ```yaml
/// classes:
/// - path/to/the/target.class
Expand All @@ -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,
Expand Down
38 changes: 28 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -40,6 +40,8 @@ async fn main() {
let archive: Arc<Mutex<ZipArchive<Cursor<Vec<u8>>>>> = 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();

Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 94b2c6f

Please sign in to comment.