@@ -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 ) ?;
0 commit comments