Mercurial > repos > IBBoard.ArmyBuilder.API
comparison Extractors/ArmyBuilderFileExtractor.cs @ 3:1a54f6afafe7
Re #84 and #85: Support Army Builder v2/v3 files
* Separate out the two versions of file
* Restructure file loader to load v2 files correctly
* Tidy up file extractor (still not working)
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 17 May 2009 18:40:36 +0000 |
parents | 1a5205612b72 |
children | d2f7826147eb |
comparison
equal
deleted
inserted
replaced
2:d5ba733cd289 | 3:1a54f6afafe7 |
---|---|
3 // The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license. | 3 // The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license. |
4 // | 4 // |
5 | 5 |
6 using System; | 6 using System; |
7 using System.IO; | 7 using System.IO; |
8 //using ICSharpCode.SharpZipLib.BZip2; | |
9 //using ICSharpCode.SharpZipLib.GZip; | |
10 using ICSharpCode.SharpZipLib.Zip.Compression.Streams; | 8 using ICSharpCode.SharpZipLib.Zip.Compression.Streams; |
11 using IBBoard.ArmyBuilder.API; | 9 using IBBoard.ArmyBuilder.API; |
12 | 10 |
13 namespace IBBoard.ArmyBuilder.API.Extractors | 11 namespace IBBoard.ArmyBuilder.API.Extractors |
14 { | 12 { |
15 public class ArmyBuilderFileExtractor | 13 public class ArmyBuilderFileExtractor |
16 { | 14 { |
17 public static byte[] GetFileEntryContent(FileTableEntry entry) | 15 public static byte[] GetFileEntryContent(FileTableEntry entry) |
18 { | 16 { |
19 //BZip2InputStream zipped = null; | |
20 //GZipInputStream zipped = null; | |
21 InflaterInputStream zipped = null; | 17 InflaterInputStream zipped = null; |
22 byte[] byteArr = new byte[entry.FileSize]; | 18 byte[] byteArr = new byte[entry.FileSize]; |
23 | 19 |
24 try | 20 try |
25 { | 21 { |
26 byte [] compressed = GetFileEntryCompressedContent(entry); | 22 byte[] compressed = GetFileEntryCompressedContent(entry); |
27 MemoryStream ms = new MemoryStream(compressed, 0, compressed.Length); | 23 MemoryStream ms = new MemoryStream(compressed); |
28 ms.Seek(0, SeekOrigin.Begin); | 24 ms.Seek(0, SeekOrigin.Begin); |
29 //zipped = new BZip2InputStream(ms); | 25 zipped = new InflaterInputStream(ms, new Inflater(true)); |
30 //zipped = new GZipInputStream(ms); | 26 |
31 zipped = new InflaterInputStream(ms); | |
32 | |
33 int size = 0; | 27 int size = 0; |
34 int offset = 0; | 28 int pos = 0; |
35 | 29 |
36 do | 30 do |
37 { | 31 { |
38 size = zipped.Read(byteArr, offset, byteArr.Length); | 32 size = zipped.Read(byteArr, pos, byteArr.Length); |
39 offset+= size; | 33 pos+=size; |
40 } | 34 } |
41 while (size > 0); | 35 while (size > 0); |
42 } | 36 } |
43 finally | 37 finally |
44 { | 38 { |
45 if (zipped != null) | 39 if (zipped != null) |
46 { | 40 { |