Mercurial > repos > IBBoard.ArmyBuilder.API
view 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 |
line wrap: on
line source
// This file (ArmyBuilderFileExtractor.cs) is a part of the IBBoard.ArmyBuilder.API project and is copyright 2009 IBBoard // // 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. // using System; using System.IO; using ICSharpCode.SharpZipLib.Zip.Compression.Streams; using IBBoard.ArmyBuilder.API; namespace IBBoard.ArmyBuilder.API.Extractors { public class ArmyBuilderFileExtractor { public static byte[] GetFileEntryContent(FileTableEntry entry) { InflaterInputStream zipped = null; byte[] byteArr = new byte[entry.FileSize]; try { byte[] compressed = GetFileEntryCompressedContent(entry); MemoryStream ms = new MemoryStream(compressed); ms.Seek(0, SeekOrigin.Begin); zipped = new InflaterInputStream(ms, new Inflater(true)); int size = 0; int pos = 0; do { size = zipped.Read(byteArr, pos, byteArr.Length); pos+=size; } while (size > 0); } finally { if (zipped != null) { zipped.Close(); } } return byteArr; } public static byte[] GetFileEntryCompressedContent(FileTableEntry entry) { FileStream stream = entry.GetParentFileStream(); stream.Seek(entry.Location, SeekOrigin.Begin); byte[] bytes = new byte[entry.CompressedSize]; try { stream.Read(bytes, 0, entry.CompressedSize); } finally { stream.Close(); } return bytes; } } }