コード例 #1
0
ファイル: MAS2Reader.cs プロジェクト: llenroc/SimTelemetry
        public byte[] ExtractBytes(MAS2File f)
        {
            BinaryReader reader = new BinaryReader(System.IO.File.OpenRead(this.mas2_file));

            reader.BaseStream.Seek(f.FileOffset, SeekOrigin.Begin);
            byte[] RawData = reader.ReadBytes((int)f.CompressedSize);
            reader.Close();

            if (f.IsCompressed)
            {
                byte[] OutputData = new byte[f.UncompressedSize];

                // MAS2 compression consists of a simple inflate/deflate process.
                ZlibCodec codec = new ZlibCodec(CompressionMode.Decompress);
                codec.InitializeInflate();
                codec.InputBuffer      = RawData;
                codec.NextIn           = 0;
                codec.AvailableBytesIn = RawData.Length;

                codec.OutputBuffer      = OutputData;
                codec.NextOut           = 0;
                codec.AvailableBytesOut = OutputData.Length;

                codec.Inflate(FlushType.None);
                codec.EndInflate();

                return(OutputData);
            }
            else
            {
                return(RawData);
            }
        }
コード例 #2
0
ファイル: MAS2Reader.cs プロジェクト: llenroc/SimTelemetry
        public MAS2Reader(string file, string[] exts)
        {
            this.mas2_file = file;
            Files          = new List <MAS2File>();
            reader         = new BinaryReader(System.IO.File.OpenRead(file));
            ReadHeader();

            int  files        = file_header.Length / 256;
            uint FilePosition = (uint)reader.BaseStream.Position;

            reader.Close();

            List <string> extensions       = new List <string>(exts);
            bool          parse_extensions = (extensions.Count > 0);

            for (int f = 0; f < files; f++)
            {
                MAS2File masfile = new MAS2File {
                    Master = this
                };
                uint size_compressed = BitConverter.ToUInt32(file_header, 65 * 4 + f * 256);
                masfile.FileOffset = FilePosition;
                FilePosition      += size_compressed;

                string filename = ASCIIEncoding.ASCII.GetString(file_header, f * 256 + 16, 128);
                filename = filename.Substring(0, filename.IndexOf('\0')).ToLower();

                if (parse_extensions)
                {
                    string ext = System.IO.Path.GetExtension(filename);
                    if (extensions.Contains(ext) == false)
                    {
                        continue;
                    }
                }

                uint file_index        = BitConverter.ToUInt32(file_header, f * 256);
                uint size_uncompressed = BitConverter.ToUInt32(file_header, 63 * 4 + f * 256);

                string filename_path = ASCIIEncoding.ASCII.GetString(file_header, f * 256 + 16 + filename.Length + 1, 128);
                filename_path = filename_path.Substring(0, filename_path.IndexOf('\0')).ToLower();


                masfile.CompressedSize   = size_compressed;
                masfile.UncompressedSize = size_uncompressed;
                masfile.Index            = file_index;
                masfile.Filename         = filename;
                masfile.Filename_Path    = filename_path;

                this.Files.Add(masfile);
            }
        }
コード例 #3
0
ファイル: MAS2Reader.cs プロジェクト: nlhans/SimTelemetry
 public string ExtractString(MAS2File f)
 {
     return ASCIIEncoding.ASCII.GetString(ExtractBytes(f));
 }
コード例 #4
0
ファイル: MAS2Reader.cs プロジェクト: nlhans/SimTelemetry
        public void ExtractFile(MAS2File f, string target)
        {
            BinaryReader reader = new BinaryReader(System.IO.File.OpenRead(this.mas2_file));
            reader.BaseStream.Seek(f.FileOffset, SeekOrigin.Begin);
            byte[] RawData = reader.ReadBytes((int)f.CompressedSize);

            if (f.IsCompressed)
            {
                byte[] OutputData = new byte[f.UncompressedSize];

                // MAS2 compression consists of a simple inflate/deflate process.
                ZlibCodec codec = new ZlibCodec(CompressionMode.Decompress);
                codec.InitializeInflate();
                codec.InputBuffer = RawData;
                codec.NextIn = 0;
                codec.AvailableBytesIn = RawData.Length;

                codec.OutputBuffer = OutputData;
                codec.NextOut = 0;
                codec.AvailableBytesOut = OutputData.Length;

                codec.Inflate(FlushType.None);
                codec.EndInflate();

                System.IO.File.WriteAllBytes(target, OutputData);
            }
            else
            {
                System.IO.File.WriteAllBytes(target, RawData);
            }
        }
コード例 #5
0
ファイル: MAS2Reader.cs プロジェクト: nlhans/SimTelemetry
        public MAS2Reader(string file, string[] exts)
        {
            this.mas2_file = file;
            Files = new List<MAS2File>();
            reader = new BinaryReader(System.IO.File.OpenRead(file));
            ReadHeader();

            int files = file_header.Length / 256;
            uint FilePosition = (uint)reader.BaseStream.Position;
            reader.Close();

            List<string> extensions = new List<string>(exts);
            bool parse_extensions = (extensions.Count > 0);
            for (int f = 0; f < files; f++)
            {
                MAS2File masfile = new MAS2File { Master = this };
                uint size_compressed = BitConverter.ToUInt32(file_header, 65 * 4 + f * 256);
                masfile.FileOffset = FilePosition;
                FilePosition += size_compressed;

                string filename = ASCIIEncoding.ASCII.GetString(file_header, f * 256 + 16, 128);
                filename = filename.Substring(0, filename.IndexOf('\0')).ToLower();

                if(parse_extensions)
                {
                    string ext = System.IO.Path.GetExtension(filename);
                    if (extensions.Contains(ext) == false)
                        continue;
                }

                uint file_index = BitConverter.ToUInt32(file_header, f * 256);
                uint size_uncompressed = BitConverter.ToUInt32(file_header, 63 * 4 + f * 256);

                string filename_path = ASCIIEncoding.ASCII.GetString(file_header, f * 256 + 16 + filename.Length + 1, 128);
                filename_path = filename_path.Substring(0, filename_path.IndexOf('\0')).ToLower();

                masfile.CompressedSize = size_compressed;
                masfile.UncompressedSize = size_uncompressed;
                masfile.Index = file_index;
                masfile.Filename = filename;
                masfile.Filename_Path = filename_path;

                this.Files.Add(masfile);
            }
        }
コード例 #6
0
ファイル: MAS2Reader.cs プロジェクト: llenroc/SimTelemetry
 public string ExtractString(MAS2File f)
 {
     return(ASCIIEncoding.ASCII.GetString(ExtractBytes(f)));
 }