Clippy fixes
This commit is contained in:
parent
f407176a5e
commit
1bea3f994a
33
src/main.rs
33
src/main.rs
|
@ -17,7 +17,7 @@ impl DatHeader {
|
|||
let mut file_dat: [u8; 2] = [0; 2];
|
||||
let _ = f.read(&mut file_dat);
|
||||
// Create a new DatHeader
|
||||
let mut dat = DatHeader::from_bytes(file_dat);
|
||||
let mut dat = Self::from_bytes(file_dat);
|
||||
// Get parse info about every file
|
||||
for _ in 0..dat.total {
|
||||
let mut file_dat: [u8; 25] = [0; 25];
|
||||
|
@ -35,7 +35,7 @@ impl DatHeader {
|
|||
|
||||
fn from_bytes(buffer: [u8; 2]) -> Self {
|
||||
Self {
|
||||
total: u16::from_le_bytes(buffer.try_into().expect("Slice with incorrect length")),
|
||||
total: u16::from_le_bytes(buffer),
|
||||
files: Vec::new()
|
||||
}
|
||||
}
|
||||
|
@ -93,8 +93,7 @@ struct JsonFile {
|
|||
padding: u32,
|
||||
}
|
||||
|
||||
fn extract_file(rec: &DatFile) {
|
||||
let mut source = File::open("EDEN.DAT").unwrap();
|
||||
fn extract_file(rec: &DatFile, source: &mut File) {
|
||||
let _ = source.seek(SeekFrom::Start(rec.offset as u64)).unwrap();
|
||||
|
||||
let filename = format!("extract/{}", rec.name);
|
||||
|
@ -102,15 +101,15 @@ fn extract_file(rec: &DatFile) {
|
|||
|
||||
let mut contents: Vec<u8> = Vec::new();
|
||||
let _ = source.take(rec.size as u64).read_to_end(&mut contents);
|
||||
let _ = destination.write(&*contents);
|
||||
let _ = destination.write(&contents);
|
||||
}
|
||||
|
||||
fn create_json(dat: &DatHeader) {
|
||||
fn create_json(dat: &DatHeader, destination: &str) {
|
||||
let mut file_list: Vec<String> = Vec::new();
|
||||
for f in &dat.files {
|
||||
file_list.push(format!("extract/{}", f.name.clone()));
|
||||
}
|
||||
let mut w = BufWriter::new(File::create("list.json").unwrap());
|
||||
let mut w = BufWriter::new(File::create(destination).unwrap());
|
||||
serde_json::to_writer_pretty(&mut w, &file_list).unwrap();
|
||||
w.flush().unwrap();
|
||||
}
|
||||
|
@ -127,13 +126,13 @@ fn create_dat(files: Vec<String>) {
|
|||
let _ = f.write(&dat.to_bytes());
|
||||
|
||||
let mut jsonfiles : Vec<JsonFile> = Vec::new();
|
||||
let mut address: i32 = 65536;
|
||||
let mut address: i32 = 0x0001_0000;
|
||||
for file in files {
|
||||
// Get file size
|
||||
let file_size: i32 = fs::metadata(&file).unwrap().len() as i32;
|
||||
// Split name from path
|
||||
let split: Vec<_> = file.split('/').collect();
|
||||
let file_name = split[1].clone();
|
||||
let file_name = split[1];
|
||||
// Save file info header
|
||||
let datfile = DatFile::new(file_name.to_string(), file_size as u32, address as u32, 0);
|
||||
let _ = f.write(&datfile.to_bytes());
|
||||
|
@ -145,8 +144,8 @@ fn create_dat(files: Vec<String>) {
|
|||
|
||||
// Fill with zeros until 65535
|
||||
let current_position = f.seek(SeekFrom::Current(0)).unwrap();
|
||||
if current_position < 65536 {
|
||||
for _ in current_position..65536 {
|
||||
if current_position < 0x0001_0000 {
|
||||
for _ in current_position..0x0001_0000 {
|
||||
let _ = f.write(&[0]);
|
||||
}
|
||||
}
|
||||
|
@ -156,7 +155,7 @@ fn create_dat(files: Vec<String>) {
|
|||
let mut source = File::open(file.name).unwrap();
|
||||
let mut contents: Vec<u8> = Vec::new();
|
||||
let _ = source.read_to_end(&mut contents);
|
||||
let _ = f.write(&*contents);
|
||||
let _ = f.write(&contents);
|
||||
let current_position= f.seek(SeekFrom::Current(0)).unwrap() as u32;
|
||||
if current_position < file.padding {
|
||||
for _ in current_position..file.padding {
|
||||
|
@ -181,15 +180,17 @@ fn main() {
|
|||
match cmd.get_matches().subcommand_name() {
|
||||
Some("extract") => {
|
||||
let dat = DatHeader::new("EDEN.DAT");
|
||||
let mut source = File::open("EDEN.DAT").unwrap();
|
||||
for f in dat.files {
|
||||
extract_file(&f);
|
||||
println!("Extracting {} - Size: {}, Offset: {}", &f.name, &f.size, &f.offset)
|
||||
extract_file(&f, &mut source);
|
||||
println!("Extracting {} - Size: {}, Offset: {}", &f.name, &f.size, &f.offset);
|
||||
}
|
||||
}
|
||||
Some("json") => {
|
||||
let destination = "list.json";
|
||||
let dat = DatHeader::new("EDEN.DAT");
|
||||
create_json(&dat);
|
||||
println!("Created {}", "list.json");
|
||||
create_json(&dat, destination);
|
||||
println!("Created {destination}");
|
||||
}
|
||||
Some("generate") => {
|
||||
let files = read_json();
|
||||
|
|
Loading…
Reference in New Issue