Beispiel #1
0
        public override int Write(System.IO.BinaryWriter bw)
        {
            long p   = bw.BaseStream.Position;
            int  len = 0;

            bw.Write(RiffParser.ToFourCC("LIST"));
            bw.Write(0);
            bw.Write(RiffParser.ToFourCC(name));
            if (this.subList.Count > 0)
            {
                foreach (RIFFBase rb in this.subList)
                {
                    len += rb.Write(bw);
                }
            }
            else
            {
                //bw.Write(content);
                len = content.Length;
            }
            long sp = bw.BaseStream.Position;

            bw.BaseStream.Position -= len + 8;
            bw.Write(len + 4);
            bw.BaseStream.Position = sp;
            if ((len & 1) != 0)
            {
                bw.Write(false);
            }
            return((int)(bw.BaseStream.Position - p));
        }
Beispiel #2
0
        public override int Write(BinaryWriter bw)
        {
            long sp = bw.BaseStream.Position;

            int[]      blockSizes = new int[0];
            byte[]     data       = RiffConn.WriteRiff(subList, ref blockSizes, true);
            FileStream fs         = File.Open("C:\\data1", FileMode.OpenOrCreate | FileMode.Truncate);

            fs.Write(data, 0, data.Length);
            fs.Close();
            byte[]       zdata  = ZLibNet.ZLibCompressor.Compress(data);
            byte[]       blocks = new byte[blockSizes.Length * 4];
            MemoryStream ms     = new MemoryStream(blocks);
            BinaryWriter b2     = new BinaryWriter(ms);

            for (int i = 0, j = 0; i < blocks.Length; i += 4, j++)
            {
                b2.Write(blockSizes[j]);
            }
            fs = File.Open("C:\\blocks1", FileMode.OpenOrCreate | FileMode.Truncate);
            fs.Write(blocks, 0, blocks.Length);
            fs.Close();
            b2.Close();
            ms.Close();
            byte[] zblk = ZLibNet.ZLibCompressor.Compress(blocks);
            byte[] wt;
            ms = new MemoryStream();
            ms.SetLength(99999999);
            BinaryWriter bww = new BinaryWriter(ms);

            bww.Write(RiffParser.ToFourCC("cmpr"));
            bww.Write(zdata.Length + 8);
            bww.Write(data.Length);
            bww.Write(zblk.Length + 8);
            bww.Write(blocks.Length);
            bww.Write(Encoding.UTF8.GetBytes("CPng\x01\x00\x04\x00"));
            bww.Write(zdata);
            bww.Write(Encoding.UTF8.GetBytes("CPng\x01\x00\x04\x00"));
            bww.Write(zblk);
            int p = (int)ms.Position;

            wt = new byte[p];
            Array.Copy(ms.GetBuffer(), wt, p);
            bww.Close();
            ms.Close();
            bw.Write(RiffParser.ToFourCC("LIST"));
            bw.Write(wt.Length);
            bw.Write(wt, 0, p);
            int len = (int)(bw.BaseStream.Position - sp);

            if ((len & 1) != 0)
            {
                bw.Write(false);
            }
            return(len);
        }
        public override int Write(System.IO.BinaryWriter bw)
        {
            if (this.content != null)
            {
                return(base.Write(bw));
            }
            long p = bw.BaseStream.Position;

            bw.Write(RiffParser.ToFourCC(name));
            bw.Write(2);
            bw.Write((short)(m_version * 100));
            return((int)(bw.BaseStream.Position - p));
        }
Beispiel #4
0
        public void Read()
        {
            CDRFile.verType = RiffParser.FromFourCC(m_parser.FileType);
            int length = Parser.DataSize;

            FileStream   fs = Parser.Stream;
            BinaryReader br = new BinaryReader(fs);

            try
            {
                this.m_cdrFile.list = RiffConn.ReadRiff(this.m_cdrFile, br, m_parser.DataSize - 4);
            }
            catch
            {
            }
            finally
            {
                br.Close();
                fs.Close();
            }
        }
Beispiel #5
0
        public void Write(String cdrPath)
        {
            if (m_cdrFile == null)
            {
                return;
            }
            FileStream   fs = File.Open(cdrPath, FileMode.OpenOrCreate);
            BinaryWriter bw = new BinaryWriter(fs);

            bw.Write(RiffParser.ToFourCC("RIFF"));
            bw.Write(0);
            bw.Write(RiffParser.ToFourCC(m_cdrFile.verType));
            foreach (RIFFBase rl in m_cdrFile.list)
            {
                rl.Write(bw);
            }
            int pos = (int)fs.Position;

            bw.Seek(4, SeekOrigin.Begin);
            bw.Write(pos - 8);
            bw.Close();
            fs.Close();
        }
Beispiel #6
0
 public CDRReader(RiffParser parser)
 {
     m_parser       = parser;
     m_cdrFile      = new CDRFile();
     m_cdrFile.list = new List <RIFFBase>();
 }
Beispiel #7
0
        public static byte[] WriteRiff(List <RIFFBase> list, ref int[] blockSizes, bool outBlockSize = false)
        {
            byte[]     tmp = new byte[0xffffff];
            List <int> bs  = null;

            if (outBlockSize)
            {
                bs = new List <int>(blockSizes);
            }
            MemoryStream ms = new MemoryStream();
            BinaryWriter bw = new BinaryWriter(ms);

            foreach (RIFFBase rl in list)
            {
                switch (rl.Type)
                {
                case RiffType.Chunk:
                    bw.Write(RiffParser.ToFourCC(rl.name));
                    byte[] content = ((RiffChunk)rl).GetContent();
                    if (bs != null)
                    {
                        bs.Add(content.Length);
                        bw.Write(bs.Count - 1);
                    }
                    else
                    {
                        bw.Write(content.Length);
                    }
                    bw.Write(content);
                    if ((content.Length & 1) != 0)
                    {
                        bw.Write(false);
                    }
                    break;

                case RiffType.LIST:
                    bw.Write(RiffParser.ToFourCC("LIST"));
                    int bsIndex = -1;
                    if (bw != null)
                    {
                        bsIndex = bs.Count;
                        bs.Add(0);
                    }
                    bw.Write(0);
                    bw.Write(RiffParser.ToFourCC(rl.name));
                    long op = bw.BaseStream.Position;
                    blockSizes = bs.ToArray();
                    if (((RiffList)rl).subList.Count > 0)
                    {
                        byte[] t1 = WriteRiff(((RiffList)rl).subList, ref blockSizes, outBlockSize);
                        bs = new List <int>(blockSizes);
                        bw.Write(t1);
                    }
                    else
                    {
                        bw.Write(rl.content);
                    }
                    long sp  = bw.BaseStream.Position;
                    int  len = (int)(sp - op);
                    bw.BaseStream.Position -= len + 8;
                    if (bs == null)
                    {
                        bw.Write(len);
                    }
                    else
                    {
                        bs.Insert(bsIndex, len + 4);
                        bs.RemoveAt(bsIndex + 1);
                        bw.Write(bsIndex);
                    }
                    bw.BaseStream.Position = sp;
                    break;
                }
            }
            int p = (int)ms.Position;

            byte[] o = new byte[p];
            Array.Copy(ms.GetBuffer(), o, p);
            bw.Close();
            ms.Close();
            blockSizes = bs.ToArray();
            return(o);
        }
Beispiel #8
0
        public static List <RIFFBase> ReadRiff(CDRFile p, BinaryReader br, int[] blockSizes, int l = -1)
        {
            int             fcc;
            int             size;
            long            len  = l == -1 ? br.BaseStream.Length : br.BaseStream.Position + l;
            List <RIFFBase> list = new List <RIFFBase>();

            while (br.BaseStream.Position < len)
            {
                fcc  = br.ReadInt32();
                size = br.ReadInt32();
                if (blockSizes != null && blockSizes.Length > 0)
                {
                    size = blockSizes[size];
                }
                string type = RiffParser.FromFourCC(fcc);
                if (0 == String.Compare(type, RiffParser.LIST4CC))
                {
                    fcc = br.ReadInt32();
                    String   name = RiffParser.FromFourCC(fcc);
                    RIFFBase rl;
                    if (name == "cmpr")
                    {
                        rl = new CDRcmpr(p);
                    }
                    else if (name == "bmkt")
                    {
                        rl = new CDRbmkt(p);
                    }
                    else if (name == "colo")
                    {
                        rl = new CDRcolo(p);
                    }
                    else if (name == "INFO")
                    {
                        rl = new CDRINFO(p);
                    }
                    else if (name == "syst")
                    {
                        rl = new CDRsyst(p);
                    }
                    else if (name == "page")
                    {
                        rl = new CDRpage(p);
                    }
                    else if (name == "gobj")
                    {
                        rl = new CDRgobj(p);
                    }
                    else if (name == "bmpt")
                    {
                        rl = new CDRbmpt(p);
                    }
                    else if (name == "iccp")
                    {
                        rl = new CDRiccp(p);
                    }
                    else if (name == "filt")
                    {
                        rl = new CDRfilt(p);
                    }
                    else if (name == "filc")
                    {
                        rl = new CDRfilc(p);
                    }
                    else if (name == "otlt")
                    {
                        rl = new CDRotlt(p);
                    }
                    else if (name == "stlt")
                    {
                        rl = new CDRstlt(p);
                    }
                    else if (name == "uil ")
                    {
                        rl = new CDRuil_(p);
                    }
                    else if (name == "doc ")
                    {
                        rl = new CDRdoc_(p);
                    }
                    else if (name == "layr")
                    {
                        rl = new CDRlayr(p);
                    }
                    else if (name == "lgob")
                    {
                        rl = new CDRlgob(p);
                    }
                    else if (name == "fntt")
                    {
                        rl = new CDRfntt(p);
                    }
                    else if (name == "grp ")
                    {
                        rl = new CDRgrp_(p);
                    }
                    else if (name == "obj ")
                    {
                        rl = new CDRobj_(p);
                    }
                    else
                    {
                        rl = new RiffList(p);
                    }
                    rl.name = name;
                    rl.Read(br, size - 4, blockSizes);
                    if (0 != (size & 1))
                    {
                        br.BaseStream.Position++;
                    }
                    list.Add(rl);
                }
                else
                {
                    RIFFBase rl;
                    String   name = RiffParser.FromFourCC(fcc);
                    if (name == "vrsn")
                    {
                        rl = new CDRvrsn(p);
                    }
                    else if (name == "sumi")
                    {
                        rl = new CDRsumi(p);
                    }
                    else if (name == "mcfg")
                    {
                        rl = new CDRmcfg(p);
                    }
                    else if (name == "fver")
                    {
                        rl = new CDRfver(p);
                    }
                    else if (name == "DISP")
                    {
                        rl = new CDRDISP(p);
                    }
                    else if (name == "iccd")
                    {
                        rl = new CDRiccd(p);
                    }
                    else if (name == "IKEY")
                    {
                        rl = new CDRIKEY(p);
                    }
                    else if (name == "ICMT")
                    {
                        rl = new CDRICMT(p);
                    }
                    else if (name == "pref")
                    {
                        rl = new CDRpref(p);
                    }
                    else if (name == "ptrt")
                    {
                        rl = new CDRptrt(p);
                    }
                    else if (name == "fild")
                    {
                        rl = new CDRfild(p);
                    }
                    else if (name == "outl")
                    {
                        rl = new CDRoutl(p);
                    }
                    else if (name == "flgs")
                    {
                        rl = new CDRflgs(p);
                    }
                    else if (name == "bbox")
                    {
                        rl = new CDRbbox(p);
                    }
                    else if (name == "loda")
                    {
                        rl = new CDRloda(p);
                    }
                    else if (name == "bmp ")
                    {
                        rl = new CDRbmp_(p);
                    }
                    else if (name == "bmrk")
                    {
                        rl = new CDRbmrk(p);
                    }
                    else if (name == "font")
                    {
                        rl = new CDRfont(p);
                    }
                    else
                    {
                        rl = new RiffChunk(p);
                    }
                    rl.name = name;
                    rl.Read(br, size);
                    if (0 != (size & 1))
                    {
                        br.BaseStream.Position++;
                    }
                    list.Add(rl);
                }
            }
            return(list);
        }