Skip to content

Commit 1e44b8d

Browse files
committed
update deps
1 parent 3d477ee commit 1e44b8d

File tree

2 files changed

+76
-65
lines changed

2 files changed

+76
-65
lines changed

Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[package]
22
name = "binreader-rust"
3-
version = "0.3.0"
3+
version = "0.3.1"
44
authors = ["autergame"]
55

66
[dependencies]
77
byteorder = "1.4.3"
88
json = "0.12.4"
9-
dtoa = "1.0.5"
10-
clap = "4.1.4"
9+
dtoa = "1.0.9"
10+
clap = "4.3.17"
1111
glob = "0.3.1"
1212

1313
[profile]

src/main.rs

+73-62
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ extern crate dtoa;
44
extern crate glob;
55
extern crate json;
66

7-
use std::fs::File;
8-
use std::io::{BufRead, BufReader, Read, Write};
9-
10-
use std::collections::HashMap;
11-
use std::path::Path;
7+
use std::{
8+
collections::HashMap,
9+
fs::File,
10+
io::{BufRead, BufReader, Read, Write},
11+
path::Path,
12+
};
1213

1314
mod hashes;
1415
mod json_reader;
@@ -19,7 +20,7 @@ mod writer;
1920

2021
fn main() {
2122
let matches = clap::Command::new("BinReader-Rust")
22-
.version("0.3.0")
23+
.version(env!("CARGO_PKG_VERSION"))
2324
.author("https://github.com/autergame/")
2425
.about("League Of Legends Bin Reader And Writter")
2526
.arg_required_else_help(true)
@@ -58,66 +59,76 @@ fn main() {
5859
)
5960
.get_matches();
6061

61-
if let Some(matches) = matches.subcommand_matches("decode") {
62-
let input = matches.get_one::<String>("INPUT").unwrap();
63-
let output = matches.get_one::<String>("OUTPUT");
64-
65-
let mut hash_map: HashMap<u64, String> = HashMap::new();
66-
add_to_hash_map(&["path", "patch", "value"], &mut hash_map);
67-
68-
println!("Loading hashes");
69-
let mut lines =
70-
load_hashes_from_file(Path::new("files/hashes.bintypes.txt"), &mut hash_map);
71-
lines += load_hashes_from_file(Path::new("files/hashes.binfields.txt"), &mut hash_map);
72-
lines += load_hashes_from_file(Path::new("files/hashes.binhashes.txt"), &mut hash_map);
73-
lines += load_hashes_from_file(Path::new("files/hashes.binentries.txt"), &mut hash_map);
74-
lines += load_hashes_from_file(Path::new("files/hashes.lcu.txt"), &mut hash_map);
75-
lines += load_hashes_from_file(Path::new("files/hashes.game.txt"), &mut hash_map);
76-
println!("Loaded total of hashes: {lines}");
77-
println!("Finished loading hashes.\n");
78-
79-
if let Some(output) = output {
80-
let contents = read_to_u8(Path::new(input));
81-
let bin_file = reader::read_bin(&contents);
82-
let jsonstr = json_writer::convert_bin_to_json(&bin_file, &mut hash_map);
83-
write_u8(Path::new(output), jsonstr.as_bytes());
84-
} else {
85-
let input_paths = glob::glob(input)
86-
.expect("Failed to read glob pattern")
87-
.filter_map(Result::ok);
88-
89-
for mut input_path in input_paths {
90-
let contents = read_to_u8(&input_path);
91-
let bin_file = reader::read_bin(&contents);
92-
let jsonstr = json_writer::convert_bin_to_json(&bin_file, &mut hash_map);
93-
input_path.set_extension("json");
94-
write_u8(&input_path, jsonstr.as_bytes());
95-
println!();
62+
match matches.subcommand() {
63+
Some(("decode", args)) => {
64+
let input = args.get_one::<String>("INPUT").unwrap();
65+
let output = args.get_one::<String>("OUTPUT");
66+
67+
let mut hash_map: HashMap<u64, String> = HashMap::new();
68+
add_to_hash_map(&["path", "patch", "value"], &mut hash_map);
69+
70+
println!("Loading hashes");
71+
let mut lines =
72+
load_hashes_from_file(Path::new("files/hashes.bintypes.txt"), &mut hash_map);
73+
lines += load_hashes_from_file(Path::new("files/hashes.binfields.txt"), &mut hash_map);
74+
lines += load_hashes_from_file(Path::new("files/hashes.binhashes.txt"), &mut hash_map);
75+
lines += load_hashes_from_file(Path::new("files/hashes.binentries.txt"), &mut hash_map);
76+
lines += load_hashes_from_file(Path::new("files/hashes.lcu.txt"), &mut hash_map);
77+
lines += load_hashes_from_file(Path::new("files/hashes.game.txt"), &mut hash_map);
78+
println!("Loaded total of hashes: {lines}");
79+
println!("Finished loading hashes.\n");
80+
81+
match output {
82+
Some(output) => {
83+
let contents = read_to_u8(Path::new(input));
84+
let bin_file = reader::read_bin(&contents);
85+
let jsonstr = json_writer::convert_bin_to_json(&bin_file, &mut hash_map);
86+
write_u8(Path::new(output), jsonstr.as_bytes());
87+
}
88+
None => {
89+
let input_paths = glob::glob(input)
90+
.expect("Failed to read glob pattern")
91+
.filter_map(Result::ok);
92+
93+
for mut input_path in input_paths {
94+
let contents = read_to_u8(&input_path);
95+
let bin_file = reader::read_bin(&contents);
96+
let jsonstr = json_writer::convert_bin_to_json(&bin_file, &mut hash_map);
97+
input_path.set_extension("json");
98+
write_u8(&input_path, jsonstr.as_bytes());
99+
println!();
100+
}
101+
}
96102
}
97103
}
98-
} else if let Some(matches) = matches.subcommand_matches("encode") {
99-
let input = matches.get_one::<String>("INPUT").unwrap();
100-
let output = matches.get_one::<String>("OUTPUT");
101-
102-
if let Some(output) = output {
103-
let contents = read_string(Path::new(input));
104-
let bin_file = json_reader::convert_json_to_bin(&contents);
105-
let bin = writer::write_bin(&bin_file);
106-
write_u8(Path::new(output), &bin);
107-
} else {
108-
let input_paths = glob::glob(input)
109-
.expect("Failed to read glob pattern")
110-
.filter_map(Result::ok);
111-
112-
for mut input_path in input_paths {
113-
let contents = read_string(&input_path);
114-
let bin_file = json_reader::convert_json_to_bin(&contents);
115-
let bin = writer::write_bin(&bin_file);
116-
input_path.set_extension("bin");
117-
write_u8(&input_path, &bin);
118-
println!();
104+
Some(("encode", args)) => {
105+
let input = args.get_one::<String>("INPUT").unwrap();
106+
let output = args.get_one::<String>("OUTPUT");
107+
108+
match output {
109+
Some(output) => {
110+
let contents = read_string(Path::new(input));
111+
let bin_file = json_reader::convert_json_to_bin(&contents);
112+
let bin = writer::write_bin(&bin_file);
113+
write_u8(Path::new(output), &bin);
114+
}
115+
None => {
116+
let input_paths = glob::glob(input)
117+
.expect("Failed to read glob pattern")
118+
.filter_map(Result::ok);
119+
120+
for mut input_path in input_paths {
121+
let contents = read_string(&input_path);
122+
let bin_file = json_reader::convert_json_to_bin(&contents);
123+
let bin = writer::write_bin(&bin_file);
124+
input_path.set_extension("bin");
125+
write_u8(&input_path, &bin);
126+
println!();
127+
}
128+
}
119129
}
120130
}
131+
_ => {}
121132
}
122133
}
123134

0 commit comments

Comments
 (0)