Example #1
0
        public Patch(string patchFile)
        {
            using (FileStream fs = new FileStream(patchFile, FileMode.Open, FileAccess.Read))
            using (BinaryReader br = new BinaryReader(fs))
            {
                m_PTCH = br.ReadStruct<PTCH>();
                //Debug.Assert(m_PTCH.m_magic.FourCC() == "PTCH");

                if (m_PTCH.m_magic.FourCC() != "PTCH")
                    throw new InvalidDataException("not PTCH");

                m_MD5 = br.ReadStruct<MD5_>();
                Debug.Assert(m_MD5.m_magic.FourCC() == "MD5_");

                m_XFRM = br.ReadStruct<XFRM>();
                Debug.Assert(m_XFRM.m_magic.FourCC() == "XFRM");

                m_type = m_XFRM.m_type.FourCC();

                switch (m_type)
                {
                    case "BSD0":
                        m_unpackedSize = br.ReadInt32();
                        m_compressedDiffStream = new MemoryStream(br.ReadRemaining());
                        BSDIFFParse();
                        break;
                    case "COPY":
                        m_compressedDiffStream = new MemoryStream(br.ReadRemaining());
                        return;
                    default:
                        Debug.Assert(false, String.Format("Unknown patch type: {0}", m_type));
                        break;
                }
            }
        }
Example #2
0
        public Patch(string patchFile)
        {
            using (FileStream fs = new FileStream(patchFile, FileMode.Open, FileAccess.Read))
                using (BinaryReader br = new BinaryReader(fs))
                {
                    m_PTCH = br.ReadStruct <PTCH>();
                    Debug.Assert(m_PTCH.m_magic.FourCC() == "PTCH");

                    m_MD5 = br.ReadStruct <MD5_>();
                    Debug.Assert(m_MD5.m_magic.FourCC() == "MD5_");

                    m_XFRM = br.ReadStruct <XFRM>();
                    Debug.Assert(m_XFRM.m_magic.FourCC() == "XFRM");

                    m_type = m_XFRM.m_type.FourCC();

                    switch (m_type)
                    {
                    case "BSD0":
                        m_unpackedSize   = br.ReadUInt32();
                        m_compressedDiff = br.ReadRemaining();
                        BSDIFFParse();
                        break;

                    case "COPY":
                        m_compressedDiff = br.ReadRemaining();
                        return;

                    default:
                        Debug.Assert(false, String.Format("Unknown patch type: {0}", m_type));
                        break;
                    }
                }
        }