@@ -13,27 +13,24 @@ public static void Unpack(string archivePath, bool rename = false)
13
13
Directory . CreateDirectory ( systemDir ) ;
14
14
15
15
Stream stream = File . OpenRead ( archivePath ) ;
16
- int fileNameLength = stream . ReadByte ( ) * 2 - 2 ;
17
- while ( fileNameLength > 0 )
16
+ int filenameLength = stream . ReadByte ( ) * 2 ;
17
+ while ( filenameLength > 0 )
18
18
{
19
- string fileName = ReadUtf16Le ( stream , fileNameLength ) ;
20
- string filePath = Path . Combine ( systemDir , fileName ) ;
21
- File . WriteAllText ( filePath , string . Empty ) ;
22
-
23
- stream . ReadByte ( ) ;
24
- stream . ReadByte ( ) ;
19
+ string filename = ReadString ( stream , filenameLength ) . Replace ( "\0 " , string . Empty ) ;
20
+ string filepath = Path . Combine ( systemDir , filename ) ;
21
+ File . WriteAllText ( filepath , string . Empty ) ;
25
22
26
23
int chunkSize = 65536 ;
27
24
int fileLength = BitConverter . ToInt32 ( ReadBytes ( stream , 4 ) , 0 ) ;
28
25
for ( int i = chunkSize ; i < fileLength ; i += chunkSize )
29
26
{
30
- WriteChunkFromStream ( stream , chunkSize , filePath ) ;
27
+ ReadAndWriteBytes ( stream , chunkSize , filepath ) ;
31
28
}
32
29
33
30
int remained = fileLength - fileLength / chunkSize * chunkSize ;
34
- WriteChunkFromStream ( stream , remained , filePath ) ;
31
+ ReadAndWriteBytes ( stream , remained , filepath ) ;
35
32
36
- fileNameLength = stream . ReadByte ( ) * 2 - 2 ;
33
+ filenameLength = stream . ReadByte ( ) * 2 ;
37
34
}
38
35
stream . Close ( ) ;
39
36
@@ -42,22 +39,28 @@ public static void Unpack(string archivePath, bool rename = false)
42
39
43
40
private static byte [ ] ReadBytes ( Stream stream , int length )
44
41
{
45
- byte [ ] bytesArray = new byte [ length ] ;
46
- stream . Read ( bytesArray , 0 , length ) ;
47
- return bytesArray ;
42
+ byte [ ] bytes = new byte [ length ] ;
43
+ stream . Read ( bytes , 0 , length ) ;
44
+ return bytes ;
48
45
}
49
46
50
- private static string ReadUtf16Le ( Stream stream , int size )
47
+ private static string ReadString ( Stream stream , int length )
51
48
{
52
- byte [ ] bytesArray = ReadBytes ( stream , size ) ;
53
- return Encoding . Unicode . GetString ( bytesArray ) ;
49
+ byte [ ] bytes = ReadBytes ( stream , length ) ;
50
+ return Encoding . Unicode . GetString ( bytes ) ;
51
+ }
52
+
53
+ private static void WriteBytes ( byte [ ] bytes , string path )
54
+ {
55
+ FileStream stream = new FileStream ( path , FileMode . Append ) ;
56
+ stream . Write ( bytes , 0 , bytes . Length ) ;
57
+ stream . Close ( ) ;
54
58
}
55
59
56
- private static void WriteChunkFromStream ( Stream stream , int size , string filePath )
60
+ private static void ReadAndWriteBytes ( Stream stream , int length , string path )
57
61
{
58
- byte [ ] bytesArray = ReadBytes ( stream , size ) ;
59
- string chunk = Encoding . UTF8 . GetString ( bytesArray ) ;
60
- File . AppendAllText ( filePath , chunk ) ;
62
+ byte [ ] bytes = ReadBytes ( stream , length ) ;
63
+ WriteBytes ( bytes , path ) ;
61
64
}
62
65
63
66
}
0 commit comments