1
1
using System ;
2
2
using System . IO ;
3
- using System . Text ;
4
- using SabreTools . IO . Extensions ;
3
+ using SabreTools . Models . LZ ;
5
4
6
5
namespace SabreTools . Compression . SZDD
7
6
{
@@ -44,39 +43,27 @@ private Decompressor(Stream source)
44
43
/// <summary>
45
44
/// Create a KWAJ decompressor
46
45
/// </summary>
47
- public static Decompressor CreateKWAJ ( byte [ ] source )
48
- => CreateKWAJ ( new MemoryStream ( source ) ) ;
46
+ public static Decompressor CreateKWAJ ( byte [ ] source , KWAJCompressionType compressionType )
47
+ => CreateKWAJ ( new MemoryStream ( source ) , compressionType ) ;
49
48
50
49
/// <summary>
51
50
/// Create a KWAJ decompressor
52
51
/// </summary>
53
- /// TODO: Replace validation when Models is updated
54
- public static Decompressor CreateKWAJ ( Stream source )
52
+ public static Decompressor CreateKWAJ ( Stream source , KWAJCompressionType compressionType )
55
53
{
56
54
// Create the decompressor
57
55
var decompressor = new Decompressor ( source ) ;
58
56
59
- // Validate the header
60
- byte [ ] magic = source . ReadBytes ( 8 ) ;
61
- if ( Encoding . ASCII . GetString ( magic ) != Encoding . ASCII . GetString ( [ 0x4B , 0x57 , 0x41 , 0x4A , 0x88 , 0xF0 , 0x27 , 0xD1 ] ) )
62
- throw new InvalidDataException ( nameof ( source ) ) ;
63
- ushort compressionType = source . ReadUInt16 ( ) ;
57
+ // Set the format and return
64
58
decompressor . _format = compressionType switch
65
59
{
66
- 0 => Format . KWAJNoCompression ,
67
- 1 => Format . KWAJXor ,
68
- 2 => Format . KWAJQBasic ,
69
- 3 => Format . KWAJLZH ,
70
- 4 => Format . KWAJMSZIP ,
60
+ KWAJCompressionType . NoCompression => Format . KWAJNoCompression ,
61
+ KWAJCompressionType . NoCompressionXor => Format . KWAJXor ,
62
+ KWAJCompressionType . QBasic => Format . KWAJQBasic ,
63
+ KWAJCompressionType . LZH => Format . KWAJLZH ,
64
+ KWAJCompressionType . MSZIP => Format . KWAJMSZIP ,
71
65
_ => throw new IndexOutOfRangeException ( nameof ( source ) ) ,
72
66
} ;
73
-
74
- // Skip the rest of the header
75
- ushort dataOffset = source . ReadUInt16 ( ) ; // DataOffset
76
- _ = source . ReadUInt16 ( ) ; // HeaderFlags
77
-
78
- // Seek and return
79
- source . Seek ( dataOffset , SeekOrigin . Begin ) ;
80
67
return decompressor ;
81
68
}
82
69
@@ -89,20 +76,11 @@ public static Decompressor CreateQBasic(byte[] source)
89
76
/// <summary>
90
77
/// Create a QBasic 4.5 installer SZDD decompressor
91
78
/// </summary>
92
- /// TODO: Replace validation when Models is updated
93
79
public static Decompressor CreateQBasic ( Stream source )
94
80
{
95
81
// Create the decompressor
96
82
var decompressor = new Decompressor ( source ) ;
97
83
98
- // Validate the header
99
- byte [ ] magic = source . ReadBytes ( 8 ) ;
100
- if ( Encoding . ASCII . GetString ( magic ) != Encoding . ASCII . GetString ( [ 0x53 , 0x5A , 0x20 , 0x88 , 0xF0 , 0x27 , 0x33 , 0xD1 ] ) )
101
- throw new InvalidDataException ( nameof ( source ) ) ;
102
-
103
- // Skip the rest of the header
104
- _ = source . ReadUInt32 ( ) ; // RealLength
105
-
106
84
// Set the format and return
107
85
decompressor . _format = Format . QBasic ;
108
86
return decompressor ;
@@ -117,24 +95,11 @@ public static Decompressor CreateSZDD(byte[] source)
117
95
/// <summary>
118
96
/// Create a standard SZDD decompressor
119
97
/// </summary>
120
- /// TODO: Replace validation when Models is updated
121
98
public static Decompressor CreateSZDD ( Stream source )
122
99
{
123
100
// Create the decompressor
124
101
var decompressor = new Decompressor ( source ) ;
125
102
126
- // Validate the header
127
- byte [ ] magic = source . ReadBytes ( 8 ) ;
128
- if ( Encoding . ASCII . GetString ( magic ) != Encoding . ASCII . GetString ( [ 0x53 , 0x5A , 0x44 , 0x44 , 0x88 , 0xF0 , 0x27 , 0x33 ] ) )
129
- throw new InvalidDataException ( nameof ( source ) ) ;
130
- byte compressionType = source . ReadByteValue ( ) ;
131
- if ( compressionType != 0x41 )
132
- throw new InvalidDataException ( nameof ( source ) ) ;
133
-
134
- // Skip the rest of the header
135
- _ = source . ReadByteValue ( ) ; // LastChar
136
- _ = source . ReadUInt32 ( ) ; // RealLength
137
-
138
103
// Set the format and return
139
104
decompressor . _format = Format . SZDD ;
140
105
return decompressor ;
0 commit comments