@@ -90,6 +90,16 @@ private static void ExtractFile(string file, string outputDirectory, bool includ
9090
9191 // Get the file type
9292 WrapperType ft = WrapperFactory . GetFileType ( magic , extension ) ;
93+ var wrapper = WrapperFactory . CreateWrapper ( ft , stream ) ;
94+ if ( wrapper == null )
95+ {
96+ Console . WriteLine ( "Could not determine the file format, skipping..." ) ;
97+ Console . WriteLine ( ) ;
98+ return ;
99+ }
100+
101+ // Create the output directory
102+ Directory . CreateDirectory ( outputDirectory ) ;
93103
94104 // 7-zip
95105 if ( ft == WrapperType . SevenZip )
@@ -109,27 +119,21 @@ private static void ExtractFile(string file, string outputDirectory, bool includ
109119 }
110120
111121 // BFPK archive
112- else if ( ft == WrapperType . BFPK )
122+ else if ( wrapper is SabreTools . Serialization . Wrappers . BFPK bfpk )
113123 {
114- // Build the BFPK information
115124 Console . WriteLine ( "Extracting BFPK contents" ) ;
116125 Console . WriteLine ( ) ;
117126
118- // Extract using the FileType
119- var bfpk = new BFPK ( ) ;
120- bfpk . Extract ( stream , file , outputDirectory , includeDebug : true ) ;
127+ bfpk . ExtractAll ( outputDirectory ) ;
121128 }
122129
123130 // BSP
124- else if ( ft == WrapperType . BSP )
131+ else if ( wrapper is SabreTools . Serialization . Wrappers . BSP bsp )
125132 {
126- // Build the BSP information
127133 Console . WriteLine ( "Extracting BSP contents" ) ;
128134 Console . WriteLine ( ) ;
129135
130- // Extract using the FileType
131- var bsp = new BSP ( ) ;
132- bsp . Extract ( stream , file , outputDirectory , includeDebug : true ) ;
136+ bsp . ExtractAllLumps ( outputDirectory ) ;
133137 }
134138
135139 // bzip2
@@ -223,15 +227,12 @@ private static void ExtractFile(string file, string outputDirectory, bool includ
223227 }
224228
225229 // GCF
226- else if ( ft == WrapperType . GCF )
230+ else if ( wrapper is SabreTools . Serialization . Wrappers . GCF gcf )
227231 {
228- // Build the GCF information
229232 Console . WriteLine ( "Extracting GCF contents" ) ;
230233 Console . WriteLine ( ) ;
231234
232- // Extract using the FileType
233- var gcf = new GCF ( ) ;
234- gcf . Extract ( stream , file , outputDirectory , includeDebug : true ) ;
235+ gcf . ExtractAll ( outputDirectory ) ;
235236 }
236237
237238 // gzip
@@ -247,15 +248,12 @@ private static void ExtractFile(string file, string outputDirectory, bool includ
247248 }
248249
249250 // InstallShield Archive V3 (Z)
250- else if ( ft == WrapperType . InstallShieldArchiveV3 )
251+ else if ( wrapper is SabreTools . Serialization . Wrappers . InstallShieldArchiveV3 isv3 )
251252 {
252- // Build the InstallShield Archive V3 information
253253 Console . WriteLine ( "Extracting InstallShield Archive V3 contents" ) ;
254254 Console . WriteLine ( ) ;
255255
256- // Extract using the FileType
257- var isav3 = new InstallShieldArchiveV3 ( ) ;
258- isav3 . Extract ( stream , file , outputDirectory , includeDebug : true ) ;
256+ isv3 . ExtractAll ( outputDirectory ) ;
259257 }
260258
261259 // IS-CAB archive
@@ -271,39 +269,30 @@ private static void ExtractFile(string file, string outputDirectory, bool includ
271269 }
272270
273271 // LZ-compressed file, KWAJ variant
274- else if ( ft == WrapperType . LZKWAJ )
272+ else if ( wrapper is SabreTools . Serialization . Wrappers . LZKWAJ kwaj )
275273 {
276- // Build the KWAJ
277274 Console . WriteLine ( "Extracting LZ-compressed file, KWAJ variant contents" ) ;
278275 Console . WriteLine ( ) ;
279276
280- // Extract using the FileType
281- var lz = new LZKWAJ ( ) ;
282- lz . Extract ( stream , file , outputDirectory , includeDebug : true ) ;
277+ kwaj . Extract ( outputDirectory ) ;
283278 }
284279
285280 // LZ-compressed file, QBasic variant
286- else if ( ft == WrapperType . LZQBasic )
281+ else if ( wrapper is SabreTools . Serialization . Wrappers . LZQBasic qbasic )
287282 {
288- // Build the QBasic
289283 Console . WriteLine ( "Extracting LZ-compressed file, QBasic variant contents" ) ;
290284 Console . WriteLine ( ) ;
291285
292- // Extract using the FileType
293- var lz = new LZQBasic ( ) ;
294- lz . Extract ( stream , file , outputDirectory , includeDebug : true ) ;
286+ qbasic . Extract ( outputDirectory ) ;
295287 }
296288
297289 // LZ-compressed file, SZDD variant
298- else if ( ft == WrapperType . LZSZDD )
290+ else if ( wrapper is SabreTools . Serialization . Wrappers . LZSZDD szdd )
299291 {
300- // Build the SZDD
301292 Console . WriteLine ( "Extracting LZ-compressed file, SZDD variant contents" ) ;
302293 Console . WriteLine ( ) ;
303294
304- // Extract using the FileType
305- var lz = new LZSZDD ( ) ;
306- lz . Extract ( stream , file , outputDirectory , includeDebug : true ) ;
295+ szdd . Extract ( Path . GetFileName ( file ) , outputDirectory ) ;
307296 }
308297
309298 // Microsoft Cabinet archive
@@ -339,27 +328,21 @@ private static void ExtractFile(string file, string outputDirectory, bool includ
339328 }
340329
341330 // PAK
342- else if ( ft == WrapperType . PAK )
331+ else if ( wrapper is SabreTools . Serialization . Wrappers . PAK pak )
343332 {
344- // Build the archive information
345333 Console . WriteLine ( "Extracting PAK contents" ) ;
346334 Console . WriteLine ( ) ;
347335
348- // Extract using the FileType
349- var pak = new PAK ( ) ;
350- pak . Extract ( stream , file , outputDirectory , includeDebug : true ) ;
336+ pak . ExtractAll ( outputDirectory ) ;
351337 }
352338
353339 // PFF
354- else if ( ft == WrapperType . PFF )
340+ else if ( wrapper is SabreTools . Serialization . Wrappers . PFF pff )
355341 {
356- // Build the archive information
357342 Console . WriteLine ( "Extracting PFF contents" ) ;
358343 Console . WriteLine ( ) ;
359344
360- // Extract using the FileType
361- var pff = new PFF ( ) ;
362- pff . Extract ( stream , file , outputDirectory , includeDebug : true ) ;
345+ pff . ExtractAll ( outputDirectory ) ;
363346 }
364347
365348 // PKZIP
@@ -409,15 +392,12 @@ private static void ExtractFile(string file, string outputDirectory, bool includ
409392 }
410393
411394 // SGA
412- else if ( ft == WrapperType . SGA )
395+ else if ( wrapper is SabreTools . Serialization . Wrappers . SGA sga )
413396 {
414- // Build the archive information
415397 Console . WriteLine ( "Extracting SGA contents" ) ;
416398 Console . WriteLine ( ) ;
417399
418- // Extract using the FileType
419- var sga = new SGA ( ) ;
420- sga . Extract ( stream , file , outputDirectory , includeDebug : true ) ;
400+ sga . ExtractAll ( outputDirectory ) ;
421401 }
422402
423403 // Tape Archive
@@ -438,39 +418,30 @@ private static void ExtractFile(string file, string outputDirectory, bool includ
438418 }
439419
440420 // VBSP
441- else if ( ft == WrapperType . VBSP )
421+ else if ( wrapper is SabreTools . Serialization . Wrappers . VBSP vbsp )
442422 {
443- // Build the archive information
444423 Console . WriteLine ( "Extracting VBSP contents" ) ;
445424 Console . WriteLine ( ) ;
446425
447- // Extract using the FileType
448- var vbsp = new VBSP ( ) ;
449- vbsp . Extract ( stream , file , outputDirectory , includeDebug : true ) ;
426+ vbsp . ExtractAllLumps ( outputDirectory ) ;
450427 }
451428
452429 // VPK
453- else if ( ft == WrapperType . VPK )
430+ else if ( wrapper is SabreTools . Serialization . Wrappers . VPK vpk )
454431 {
455- // Build the archive information
456432 Console . WriteLine ( "Extracting VPK contents" ) ;
457433 Console . WriteLine ( ) ;
458434
459- // Extract using the FileType
460- var vpk = new VPK ( ) ;
461- vpk . Extract ( stream , file , outputDirectory , includeDebug : true ) ;
435+ vpk . ExtractAll ( outputDirectory ) ;
462436 }
463437
464438 // WAD3
465- else if ( ft == WrapperType . WAD )
439+ else if ( wrapper is SabreTools . Serialization . Wrappers . WAD3 wad )
466440 {
467- // Build the archive information
468441 Console . WriteLine ( "Extracting WAD3 contents" ) ;
469442 Console . WriteLine ( ) ;
470443
471- // Extract using the FileType
472- var wad = new WAD3 ( ) ;
473- wad . Extract ( stream , file , outputDirectory , includeDebug : true ) ;
444+ wad . ExtractAllLumps ( outputDirectory ) ;
474445 }
475446
476447 // xz
@@ -491,15 +462,12 @@ private static void ExtractFile(string file, string outputDirectory, bool includ
491462 }
492463
493464 // XZP
494- else if ( ft == WrapperType . XZP )
465+ else if ( wrapper is SabreTools . Serialization . Wrappers . XZP xzp )
495466 {
496- // Build the archive information
497467 Console . WriteLine ( "Extracting XZP contents" ) ;
498468 Console . WriteLine ( ) ;
499469
500- // Extract using the FileType
501- var xzp = new XZP ( ) ;
502- xzp . Extract ( stream , file , outputDirectory , includeDebug : true ) ;
470+ xzp . ExtractAll ( outputDirectory ) ;
503471 }
504472
505473 // Everything else
0 commit comments