Exemplo n.º 1
0
            /// <summary>
            /// Write the data of this chunk.
            /// </summary>
            protected override void WriteData(ResWriter writer)
            {
                // Create offset marks
                var offsetMarks = new List <Mark.Int32>();

                foreach (var entry in parent.Entries)
                {
                    var mark = writer.MarkInt32();
                    offsetMarks.Add(mark);
                    EntryInstance instance;
                    if (!entry.TryGetInstance(this, out instance))
                    {
                        mark.Value = NO_ENTRY;
                    }
                }

                // Write entries, update offset marks while we go.
                var startPosition = writer.Position;

                for (var i = 0; i < parent.EntryCount; i++)
                {
                    var           entry = parent.GetEntry(i);
                    EntryInstance instance;
                    if (!entry.TryGetInstance(this, out instance))
                    {
                        continue;
                    }

                    // Update mark
                    offsetMarks[i].Value = writer.Position - startPosition;
                    instance.Write(writer);
                }
            }
Exemplo n.º 2
0
            /// <summary>
            /// Write the data of this chunk.
            /// </summary>
            protected override void WriteData(ResWriter writer)
            {
                base.WriteData(writer);
                var flags = entries.Select(x => x.Flags).ToArray();

                writer.WriteIntArray(flags.ToArray());
            }
Exemplo n.º 3
0
 /// <summary>
 /// Write the header of this chunk.
 /// Always call the base method first.
 /// </summary>
 protected sealed override void WriteHeader(ResWriter writer)
 {
     base.WriteHeader(writer);
     writer.WriteInt32(LineNumber);
     StringPoolRef.Write(writer, tree.StringPool, Comment);
     // Extended data (in derived types) is not part of the header
 }
Exemplo n.º 4
0
        /// <summary>
        /// Write this chunk.
        /// </summary>
        public void Write(ResWriter writer)
        {
            // Prepare
            PrepareForWrite();

            // First pass
            var position = writer.Stream.Position;

            WriteHeader(writer);
            headerSize = (int)(writer.Stream.Position - position);
            WriteData(writer);
            var endPosition = writer.Stream.Position;

            size = (int)(endPosition - position);

            if ((size & 0x03) != 0)
            {
            }

            // Update header
            writer.Stream.Position = position + 2;
            writer.WriteUInt16(headerSize);
            writer.WriteInt32(size);
            writer.Stream.Position = endPosition;
        }
Exemplo n.º 5
0
 /// <summary>
 /// Write the data of this chunk.
 /// </summary>
 protected override void WriteData(ResWriter writer)
 {
     base.WriteData(writer);
     strings.Write(writer);
     resourceMap.Write(writer);
     nodes.ForEach(x => x.Write(writer));
 }
Exemplo n.º 6
0
 /// <summary>
 /// Write the data of this chunk.
 /// </summary>
 protected override void WriteData(ResWriter writer)
 {
     byte[] data;
     int[]  offsets;
     BuildStringsData(list, IsUtf8, writer, out offsets, out data);
     writer.WriteIntArray(offsets);
     writer.WriteByteArray(data);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Write the header of this chunk.
 /// Always call the base method first.
 /// </summary>
 protected override void WriteHeader(ResWriter writer)
 {
     base.WriteHeader(writer);
     writer.WriteByte(id);
     writer.WriteByte(0);              // res0
     writer.WriteUInt16(0);            // res1
     writer.WriteInt32(entries.Count); // entryCount
 }
Exemplo n.º 8
0
 /// <summary>
 /// Encode a length in charsize=1 mode
 /// </summary>
 private static void EncodeLength8(ResWriter writer, int length)
 {
     if (length > 0x7F)
     {
         // use 2 bytes
         writer.WriteByte(0x80 | ((length >> 8) & 0x7F));
     }
     writer.WriteByte(length & 0x7F);
 }
Exemplo n.º 9
0
 /// <summary>
 /// Encode a length in charsize=3 mode
 /// </summary>
 private static void EncodeLength16(ResWriter writer, int length)
 {
     if (length > 0x7FFF)
     {
         // use 2 chars
         writer.WriteUInt16(0x8000 | ((length >> 16) & 0x7FFF));
     }
     writer.WriteUInt16(length & 0x7FFF);
 }
Exemplo n.º 10
0
        /// <summary>
        /// Write this chunk.
        /// </summary>
        public void Write(ResWriter writer)
        {
            var size = 8;

            writer.WriteUInt16(size);
            writer.Fill(1); // res0
            writer.WriteByte((int)type);
            writer.WriteInt32(data);
        }
Exemplo n.º 11
0
            /// <summary>
            /// Write this attribute.
            /// </summary>
            internal void Write(ResWriter writer)
            {
                StringPoolRef.Write(writer, tree.StringPool, Namespace);
                StringPoolRef.Write(writer, tree.StringPool, Name, resourceId);
                StringPoolRef.Write(writer, tree.StringPool, RawValue);
                var value = TypedValue ?? new Value(Value.Types.TYPE_STRING, tree.StringPool.Get(RawValue, -1));

                value.Write(writer);
            }
Exemplo n.º 12
0
 /// <summary>
 /// Write the header of this chunk.
 /// Always call the base method first.
 /// </summary>
 protected override void WriteHeader(ResWriter writer)
 {
     headerStartPosition = writer.Position;
     base.WriteHeader(writer);
     writer.WriteInt32(id);
     writer.WriteFixedLenghtUnicodeString(name, 128);
     typeStringsMark = writer.MarkInt32();
     writer.WriteInt32(typeStrings.Count);
     keyStringsMark = writer.MarkInt32();
     writer.WriteInt32(KeyStrings.Count);
 }
Exemplo n.º 13
0
 /// <summary>
 /// Write the data of this chunk.
 /// </summary>
 protected override void WriteData(ResWriter writer)
 {
     base.WriteData(writer);
     writer.WriteUInt16(20);               // attributeStart
     writer.WriteUInt16(20);               // attributeSize
     writer.WriteUInt16(attributes.Count); // attributeCount
     writer.WriteUInt16(IndexOf("id"));
     writer.WriteUInt16(IndexOf("class"));
     writer.WriteUInt16(IndexOf("style"));
     foreach (var attr in attributes)
     {
         attr.Write(writer);
     }
 }
Exemplo n.º 14
0
        /// <summary>
        /// Write the header of this chunk.
        /// Always call the base method first.
        /// </summary>
        protected override void WriteHeader(ResWriter writer)
        {
            base.WriteHeader(writer); // header
            writer.WriteInt32(Count); // stringCount
            writer.WriteInt32(0);     // styleCount
            var flags = (StringPoolFlags)0;

            if (IsUtf8)
            {
                flags |= StringPoolFlags.UTF8_FLAG;
            }
            writer.WriteInt32((int)flags);     // flags
            writer.WriteInt32(28 + Count * 4); // stringsStart
            writer.WriteInt32(0);              // stylesStart
        }
Exemplo n.º 15
0
            /// <summary>
            /// Write the header of this chunk.
            /// Always call the base method first.
            /// </summary>
            protected override void WriteHeader(ResWriter writer)
            {
                var startPosition = writer.Position;

                base.WriteHeader(writer);
                writer.WriteByte(parent.Id);
                writer.WriteByte(0);                       // res0
                writer.WriteUInt16(0);                     // res1
                writer.WriteInt32(parent.EntryCount);      // entryCount
                var entriesStartMark = writer.MarkInt32(); // entriesStart

                configuration.Write(writer);

                // Patch entriesStart
                entriesStartMark.Value = (writer.Position - startPosition) + (parent.EntryCount * 4);
            }
Exemplo n.º 16
0
            /// <summary>
            /// Write the data of this chunk.
            /// </summary>
            protected override void WriteData(ResWriter writer)
            {
                base.WriteData(writer);
                typeStringsMark.Value = writer.Position - headerStartPosition;
                typeStrings.Write(writer);
                keyStringsMark.Value = writer.Position - headerStartPosition;
                keyStrings.Write(writer);

                // Write typeSpecs and types
                foreach (var typeSpec in typeSpecs)
                {
                    typeSpec.Write(writer);

                    foreach (var typeAndFlags in typeSpec.Types)
                    {
                        typeAndFlags.Write(writer);
                    }
                }
            }
Exemplo n.º 17
0
        /// <summary>
        /// Encode a string data array.
        /// </summary>
        private static void BuildStringsData(List <Entry> list, bool isUtf8, ResWriter writer, out int[] offsets, out byte[] data)
        {
            // Build offsets
            offsets = new int[list.Count];

            // Build data
            var dataStream = new MemoryStream();
            var dataWriter = new ResWriter(dataStream, writer.BigEndian);

            for (var i = 0; i < list.Count; i++)
            {
                var s = list[i].Value;
                offsets[i] = (int)dataStream.Position;
                if (isUtf8)
                {
                    EncodeLength8(dataWriter, s.Length); // u16 length
                    var encoded = AndroidEncodings.UTF8.GetBytes(s);
                    EncodeLength8(dataWriter, encoded.Length);
                    dataStream.Write(encoded, 0, encoded.Length);
                }
                else
                {
                    EncodeLength16(dataWriter, s.Length);
                    foreach (var ch in s)
                    {
                        dataWriter.WriteUInt16(ch);
                    }
                    dataWriter.WriteUInt16(0); // Pad with '\0'
                }
            }

            // Pad with '0' to end on 4 byte boundary
            dataWriter.PadAlign(4);

            // Return actual data
            data = dataStream.ToArray();
        }
Exemplo n.º 18
0
 /// <summary>
 /// Write the header of this chunk.
 /// Always call the base method first.
 /// </summary>
 protected virtual void WriteHeader(ResWriter writer)
 {
     writer.WriteUInt16((int)type);
     writer.WriteUInt16(0); // Header size will be updated later
     writer.WriteInt32(0);  // Size will be updated later
 }
Exemplo n.º 19
0
 /// <summary>
 /// Write the data of this chunk.
 /// </summary>
 protected override void WriteData(ResWriter writer)
 {
     base.WriteData(writer);
     StringPoolRef.Write(writer, Tree.StringPool, Data);
     TypedData.Write(writer);
 }
Exemplo n.º 20
0
 /// <summary>
 /// Write this entry.
 /// </summary>
 internal override void Write(ResWriter writer)
 {
     base.Write(writer);
     value.Write(writer);
 }
Exemplo n.º 21
0
 /// <summary>
 /// Write this entry.
 /// </summary>
 internal virtual void Write(ResWriter writer)
 {
     writer.WriteUInt16(IsComplex ? 16 : 8);
     writer.WriteUInt16((int)flags);
     StringPoolRef.Write(writer, parent.TypeSpec.Package.KeyStrings, key);
 }
Exemplo n.º 22
0
 /// <summary>
 /// Write the header of this chunk.
 /// Always call the base method first.
 /// </summary>
 protected override void WriteHeader(ResWriter writer)
 {
     base.WriteHeader(writer);
     writer.WriteInt32(packages.Count); // packageCount
 }
Exemplo n.º 23
0
 /// <summary>
 /// Write the data of this chunk.
 /// </summary>
 protected override void WriteData(ResWriter writer)
 {
     base.WriteData(writer);
     strings.Write(writer);
     packages.ForEach(x => x.Write(writer));
 }
Exemplo n.º 24
0
 /// <summary>
 /// Write the data of this chunk.
 /// </summary>
 protected virtual void WriteData(ResWriter writer)
 {
     // Override me
 }
Exemplo n.º 25
0
 /// <summary>
 /// Read a 32-bit unsigned int from the given offset.
 /// </summary>
 private void SetInt32(int offset, int value)
 {
     ResWriter.EncodeInt32(data, offset, value, UseBigEndian);
 }
Exemplo n.º 26
0
 /// <summary>
 /// Save to given writer
 /// </summary>
 internal void Write(ResWriter writer)
 {
     writer.WriteInt32(data.Length + 4);
     writer.WriteByteArray(data);
 }
Exemplo n.º 27
0
 /// <summary>
 /// Write the data of this chunk.
 /// </summary>
 protected override void WriteData(ResWriter writer)
 {
     base.WriteData(writer);
     writer.WriteIntArray(resourceIds.ToArray());
 }