Skip to content

Commit cd45496

Browse files
committed
Make fmt happy
1 parent b1d431e commit cd45496

3 files changed

Lines changed: 78 additions & 40 deletions

File tree

src/dat1.rs

Lines changed: 62 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -107,60 +107,79 @@ impl Dat1Archive {
107107
let mut cursor = Cursor::new(&data);
108108

109109
// Read header
110-
let dir_count = cursor.read_u32::<BigEndian>()
110+
let dir_count = cursor
111+
.read_u32::<BigEndian>()
111112
.context("Failed to read directory count from DAT1 header")?;
112-
let _unknown1 = cursor.read_u32::<BigEndian>()
113+
let _unknown1 = cursor
114+
.read_u32::<BigEndian>()
113115
.context("Failed to read unknown1 field from DAT1 header")?;
114-
let _unknown2 = cursor.read_u32::<BigEndian>()
116+
let _unknown2 = cursor
117+
.read_u32::<BigEndian>()
115118
.context("Failed to read unknown2 field from DAT1 header")?;
116-
let _unknown3 = cursor.read_u32::<BigEndian>()
119+
let _unknown3 = cursor
120+
.read_u32::<BigEndian>()
117121
.context("Failed to read unknown3 field from DAT1 header")?;
118122

119123
let mut directories = Vec::new();
120124

121125
// Read directory names
122126
let mut dir_names = Vec::new();
123127
for i in 0..dir_count {
124-
let name_len = cursor.read_u8()
125-
.with_context(|| format!("Failed to read name length for directory {}", i))? as usize;
128+
let name_len = cursor
129+
.read_u8()
130+
.with_context(|| format!("Failed to read name length for directory {i}"))?
131+
as usize;
126132
let mut name_bytes = vec![0u8; name_len];
127-
cursor.read_exact(&mut name_bytes)
128-
.with_context(|| format!("Failed to read name bytes for directory {}", i))?;
133+
cursor
134+
.read_exact(&mut name_bytes)
135+
.with_context(|| format!("Failed to read name bytes for directory {i}"))?;
129136
let name =
130137
utils::decode_filename(&name_bytes).context("Failed to decode directory name")?;
131138
dir_names.push(name);
132139
}
133140

134141
// Read directory contents
135142
for dir_name in dir_names {
136-
let file_count = cursor.read_u32::<BigEndian>()
137-
.with_context(|| format!("Failed to read file count for directory '{}'", dir_name))?;
138-
let _unknown4 = cursor.read_u32::<BigEndian>()
139-
.with_context(|| format!("Failed to read unknown4 field for directory '{}'", dir_name))?;
140-
let _unknown5 = cursor.read_u32::<BigEndian>()
141-
.with_context(|| format!("Failed to read unknown5 field for directory '{}'", dir_name))?;
142-
let _unknown6 = cursor.read_u32::<BigEndian>()
143-
.with_context(|| format!("Failed to read unknown6 field for directory '{}'", dir_name))?;
143+
let file_count = cursor
144+
.read_u32::<BigEndian>()
145+
.with_context(|| format!("Failed to read file count for directory '{dir_name}'"))?;
146+
let _unknown4 = cursor.read_u32::<BigEndian>().with_context(|| {
147+
format!("Failed to read unknown4 field for directory '{dir_name}'")
148+
})?;
149+
let _unknown5 = cursor.read_u32::<BigEndian>().with_context(|| {
150+
format!("Failed to read unknown5 field for directory '{dir_name}'")
151+
})?;
152+
let _unknown6 = cursor.read_u32::<BigEndian>().with_context(|| {
153+
format!("Failed to read unknown6 field for directory '{dir_name}'")
154+
})?;
144155

145156
let mut files = Vec::new();
146157

147158
for j in 0..file_count {
148-
let name_len = cursor.read_u8()
149-
.with_context(|| format!("Failed to read name length for file {} in directory '{}'", j, dir_name))? as usize;
159+
let name_len = cursor.read_u8().with_context(|| {
160+
format!("Failed to read name length for file {j} in directory '{dir_name}'")
161+
})? as usize;
150162
let mut name_bytes = vec![0u8; name_len];
151-
cursor.read_exact(&mut name_bytes)
152-
.with_context(|| format!("Failed to read name bytes for file {} in directory '{}'", j, dir_name))?;
163+
cursor.read_exact(&mut name_bytes).with_context(|| {
164+
format!("Failed to read name bytes for file {j} in directory '{dir_name}'")
165+
})?;
153166
let name =
154167
utils::decode_filename(&name_bytes).context("Failed to decode file name")?;
155168

156-
let attributes = cursor.read_u32::<BigEndian>()
157-
.with_context(|| format!("Failed to read attributes for file '{}' in directory '{}'", name, dir_name))?;
158-
let offset = cursor.read_u32::<BigEndian>()
159-
.with_context(|| format!("Failed to read offset for file '{}' in directory '{}'", name, dir_name))? as u64;
160-
let size = cursor.read_u32::<BigEndian>()
161-
.with_context(|| format!("Failed to read size for file '{}' in directory '{}'", name, dir_name))?;
162-
let packed_size = cursor.read_u32::<BigEndian>()
163-
.with_context(|| format!("Failed to read packed size for file '{}' in directory '{}'", name, dir_name))?;
169+
let attributes = cursor.read_u32::<BigEndian>().with_context(|| {
170+
format!("Failed to read attributes for file '{name}' in directory '{dir_name}'")
171+
})?;
172+
let offset = cursor.read_u32::<BigEndian>().with_context(|| {
173+
format!("Failed to read offset for file '{name}' in directory '{dir_name}'")
174+
})? as u64;
175+
let size = cursor.read_u32::<BigEndian>().with_context(|| {
176+
format!("Failed to read size for file '{name}' in directory '{dir_name}'")
177+
})?;
178+
let packed_size = cursor.read_u32::<BigEndian>().with_context(|| {
179+
format!(
180+
"Failed to read packed size for file '{name}' in directory '{dir_name}'"
181+
)
182+
})?;
164183

165184
let compressed = attributes & DAT1_COMPRESSED_FLAG != 0;
166185
let actual_packed_size = if packed_size == 0 { size } else { packed_size };
@@ -259,7 +278,8 @@ impl Dat1Archive {
259278
utils::ensure_dir_exists(&output_path)?;
260279

261280
// Read file data from archive
262-
let file_data = self.read_file_data(file)
281+
let file_data = self
282+
.read_file_data(file)
263283
.with_context(|| format!("Failed to read data for file '{}'", file.name))?;
264284

265285
// Decompress if needed
@@ -320,8 +340,12 @@ impl Dat1Archive {
320340
target_dir: Option<&str>,
321341
) -> Result<()> {
322342
let base_path = file_path.as_ref();
323-
let files = utils::collect_files(&file_path)
324-
.with_context(|| format!("Failed to collect files from path '{}'", file_path.as_ref().display()))?;
343+
let files = utils::collect_files(&file_path).with_context(|| {
344+
format!(
345+
"Failed to collect files from path '{}'",
346+
file_path.as_ref().display()
347+
)
348+
})?;
325349

326350
for file in files {
327351
let data =
@@ -361,7 +385,8 @@ impl Dat1Archive {
361385

362386
// Remove any existing file with the same name from all directories
363387
for dir in &mut self.directories {
364-
dir.files.retain(|existing_file| existing_file.name != archive_path);
388+
dir.files
389+
.retain(|existing_file| existing_file.name != archive_path);
365390
}
366391

367392
// Add file entry
@@ -450,7 +475,11 @@ impl Dat1Archive {
450475
cursor.write_u8(file_name.len() as u8)?;
451476
cursor.write_all(file_name.as_bytes())?;
452477

453-
let attributes = if file.compressed { DAT1_COMPRESSED_FLAG } else { DAT1_UNCOMPRESSED_FLAG };
478+
let attributes = if file.compressed {
479+
DAT1_COMPRESSED_FLAG
480+
} else {
481+
DAT1_UNCOMPRESSED_FLAG
482+
};
454483
cursor.write_u32::<BigEndian>(attributes)?;
455484
cursor.write_u32::<BigEndian>(current_offset)?;
456485
cursor.write_u32::<BigEndian>(file.size)?;

src/dat2.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ impl Dat2Archive {
150150

151151
// Read file count first (using byteorder for simplicity)
152152
let mut cursor = Cursor::new(&data[tree_start..]);
153-
let file_count = cursor.read_u32::<LittleEndian>()
153+
let file_count = cursor
154+
.read_u32::<LittleEndian>()
154155
.context("Failed to read file count from DAT2 directory tree")?;
155156

156157
// Parse directory tree entries using deku
@@ -165,7 +166,7 @@ impl Dat2Archive {
165166
.map_err(|e| anyhow::anyhow!("Failed to parse file entry: {}", e))?;
166167

167168
let filename = utils::decode_filename(&entry.filename_bytes)
168-
.with_context(|| format!("Failed to decode filename for file entry {}", i))?;
169+
.with_context(|| format!("Failed to decode filename for file entry {i}"))?;
169170

170171
files.push(FileEntry {
171172
name: filename, // Keep backslashes for internal consistency
@@ -400,7 +401,6 @@ impl Dat2Archive {
400401
}
401402
}
402403

403-
404404
/// Add files to the archive (directories processed recursively)
405405
///
406406
/// This method can add a single file or an entire directory to the archive.
@@ -428,8 +428,12 @@ impl Dat2Archive {
428428
let base_path = file_path.as_ref();
429429

430430
// Find all files to add (handles both single files and directories)
431-
let files = utils::collect_files(&file_path)
432-
.with_context(|| format!("Failed to collect files from path '{}'", file_path.as_ref().display()))?;
431+
let files = utils::collect_files(&file_path).with_context(|| {
432+
format!(
433+
"Failed to collect files from path '{}'",
434+
file_path.as_ref().display()
435+
)
436+
})?;
433437

434438
// Process all files in parallel for better performance
435439
let results: Result<Vec<FileEntry>> = files
@@ -445,7 +449,8 @@ impl Dat2Archive {
445449
// Add all the new files to the archive, handling duplicates
446450
// First, remove any existing files from archive that match the new file names
447451
let new_file_names: HashSet<String> = new_entries.iter().map(|e| e.name.clone()).collect();
448-
self.files.retain(|existing_file| !new_file_names.contains(&existing_file.name));
452+
self.files
453+
.retain(|existing_file| !new_file_names.contains(&existing_file.name));
449454

450455
// Then add new files, deduplicating within the new batch
451456
let mut seen_names = HashSet::new();

src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,11 @@ fn main() -> Result<()> {
124124
let archive = DatArchive::open(&dat_file)?;
125125
let output_dir = output.unwrap_or_else(|| PathBuf::from(".")); // Use current directory if not specified
126126
let expanded_files = utils::expand_response_files(&files)?;
127-
archive.extract(&output_dir, &expanded_files, ExtractionMode::PreserveStructure)?;
127+
archive.extract(
128+
&output_dir,
129+
&expanded_files,
130+
ExtractionMode::PreserveStructure,
131+
)?;
128132
}
129133

130134
Commands::ExtractFlat {

0 commit comments

Comments
 (0)