示例#1
0
        public void Read(Stream inputStream)
        {
            BinaryReader reader      = new BinaryReader(inputStream, Encoding.UTF8, true);
            int          magicNumber = reader.ReadInt32();
            int          version     = reader.ReadInt32();
            int          endianess   = reader.ReadInt32();

            switch (endianess)
            {
            case LittleEndianConstant:     // LE
                Endianess = Endianess.LittleEndian;
                break;

            case BigEndianConstant:     // BE
                Endianess = Endianess.BigEndian;
                version   = EndianessBitConverter.FlipEndianess(version);
                reader    = new BigEndianBinaryReader(inputStream, Encoding.UTF8, true);
                break;

            default:
                throw new Exception(string.Format("Unknown endianess: {0:X}", endianess));
            }
            int entryCount   = reader.ReadInt32();
            int headerSize   = reader.ReadInt32();
            int offsetKeys   = reader.ReadInt32();
            int offsetValues = reader.ReadInt32();
            int padding      = reader.ReadInt32();

            for (int i = 0; i < entryCount; i++)
            {
                int offsetKey   = reader.ReadInt32();
                int offsetValue = reader.ReadInt32();

                long nextEntryPosition = inputStream.Position;

                inputStream.Position = offsetKeys + offsetKey;
                string key = reader.ReadNullTerminatedString();
                inputStream.Position = offsetValues + offsetValue;
                short  valueConstant = reader.ReadInt16();
                string value         = reader.ReadNullTerminatedString();

                Entries.Add(new LangEntry
                {
                    Key   = key,
                    Value = value
                });

                inputStream.Position = nextEntryPosition;
            }
        }
        public void Read(Stream inputStream, Dictionary <uint, string> langIdDictionary)
        {
            BinaryReader headerReader = new BinaryReader(inputStream, Encoding.UTF8, true);
            BinaryReader reader;

            int magicNumber = headerReader.ReadInt32();
            int version     = headerReader.ReadInt32(); // GZ 2, TPP 3
            int endianess   = headerReader.ReadInt32(); // LE, BE

            switch (endianess)
            {
            case LittleEndianConstant:     // LE
                Endianess = Endianess.LittleEndian;
                reader    = headerReader;
                break;

            case BigEndianConstant:     // BE
                Endianess = Endianess.BigEndian;
                version   = EndianessBitConverter.FlipEndianess(version);
                reader    = new BigEndianBinaryReader(inputStream, Encoding.UTF8, true);
                break;

            default:
                throw new Exception(string.Format("Unknown endianess: {0:X}", endianess));
            }

            int entryCount   = reader.ReadInt32();
            int valuesOffset = reader.ReadInt32();
            int keysOffset   = reader.ReadInt32();

            inputStream.Position = valuesOffset;
            Dictionary <int, LangEntry> offsetEntryDictionary = new Dictionary <int, LangEntry>();

            for (int i = 0; i < entryCount; i++)
            {
                int    valuePosition = (int)inputStream.Position - valuesOffset;
                short  colorId       = headerReader.ReadInt16();
                string value         = reader.ReadNullTerminatedString();
                offsetEntryDictionary.Add(valuePosition, new LangEntry
                {
                    Color = colorId,
                    Value = value
                });
            }

            inputStream.Position = keysOffset;
            for (int i = 0; i < entryCount; i++)
            {
                uint langIdCode = reader.ReadUInt32();
                int  offset     = reader.ReadInt32();

                string langId;
                if (langIdDictionary.TryGetValue(langIdCode, out langId))
                {
                    offsetEntryDictionary[offset].LangId = langId;
                }

                offsetEntryDictionary[offset].Key = langIdCode;
            }

            Entries = offsetEntryDictionary.Values.ToList();
        }