Beispiel #1
0
        private unsafe void WriteWimHeader()
        {
            WimHeader whUpdated = Header;

            byte[] bWhUpdated = new byte[sizeof(WimHeader)];
            Marshal.Copy((IntPtr)(&whUpdated), bWhUpdated, 0, bWhUpdated.Length);
            _file.Position = 0;
            _writer.Write(bWhUpdated);
        }
Beispiel #2
0
        private void WriteXmlMetadata()
        {
            byte[] bXml;
            using (MemoryStream msXml = new MemoryStream())
            {
                using (XmlWriter xw = XmlWriter.Create(msXml,
                                                       new XmlWriterSettings
                {
                    OmitXmlDeclaration = true,
                    Encoding = Encoding.Unicode
                }))
                {
                    XmlMetadata.Save(xw);
                }

                long xmlSize = msXml.Length;

                long fileSize = xmlSize + Header.XmlData.OffsetInWim + (long)Header.IntegrityTable.SizeInWim;
                XmlMetadata.Root?.Element("TOTALBYTES")?.SetValue(fileSize.ToString());

                msXml.Position = 0;
                msXml.SetLength(0);
                using (XmlWriter xw = XmlWriter.Create(msXml,
                                                       new XmlWriterSettings
                {
                    OmitXmlDeclaration = true,
                    Encoding = Encoding.Unicode
                }))
                {
                    XmlMetadata.Save(xw);
                }

                bXml = msXml.ToArray();
            }

            WimHeader whUpdated = Header;

            whUpdated.XmlData.OriginalSize       = (ulong)bXml.LongLength;
            whUpdated.XmlData.SizeInWimWithFlags = (ulong)bXml.LongLength | ((ulong)whUpdated.XmlData.Flags << 56);

            _file.Position = whUpdated.XmlData.OffsetInWim;
            _file.SetLength(whUpdated.XmlData.OffsetInWim);
            _writer.Write(bXml);

            whUpdated.IntegrityTable.OffsetInWim = _file.Position;
            Header = whUpdated;
        }