コード例 #1
0
 /// <summary>
 /// Writes a <see cref="BartID"/> into the stream
 /// </summary>
 public void WriteBartID(BartID value)
 {
     lock (this)
     {
         dataSegments.Add(new BartIDSegment(value));
         byteCount += 4 + value.Data.Length;
     }
 }
コード例 #2
0
ファイル: ByteStream.cs プロジェクト: pkt30/OscarLib
 public BartIDSegment(BartID value)
 {
     item = value;
 }
コード例 #3
0
ファイル: ByteStream.cs プロジェクト: pkt30/OscarLib
        /// <summary>
        /// Parses a byte buffer into an <see cref="BartID"/> object
        /// </summary>
        private void ReadIconInfo(byte[] buffer, UserInfo userinfo)
        {
            using (ByteStream iconStream = new ByteStream(buffer))
            {
                int iconStreamSize = iconStream.GetByteCount();

                while (iconStream.CurrentPosition + 4 <= iconStreamSize)
                {
                    BartID item = new BartID(iconStream);

                    // Find the end of the current data item in the stream
                    int endDataPosition = iconStream.CurrentPosition + item.Data.Length;

                    switch (item.Type)
                    {
                        case BartTypeId.BuddyIcon:
                            if (!GraphicsManager.IsBlankIcon(item.Data))
                            {
                                userinfo.Icon = item;
                            }
                            break;

                        case BartTypeId.StatusString: // Available message
                            using (ByteStream messageStream = new ByteStream(item.Data))
                            {
                                Encoding encoding = Encoding.UTF8;
                                byte[] amessage = new byte[0];

                                if (messageStream.HasMoreData)
                                {
                                    // Pull the message to a byte array, assume at first that the encoding
                                    // is UTF-8.  If existing encoding information exists, use that instead
                                    amessage = messageStream.ReadByteArray(messageStream.ReadByte());

                                    // Check if there's encoding information available
                                    if (messageStream.HasMoreData)
                                    {
                                        // Check to see if the encoding's been specified
                                        if (messageStream.ReadUshort() == 0x0001)
                                        {
                                            messageStream.AdvanceOffset(2);
                                            string encodingStr = messageStream.ReadString(messageStream.ReadUshort(), Encoding.ASCII);

                                            // Try to use the encoding from the byte stream
                                            try
                                            {
                                                encoding = Encoding.GetEncoding(encodingStr);
                                            }
                                            catch (ArgumentException)
                                            {
                                                Logging.WriteString(
                                                    "ReadIconInfo: Got unknown encoding for available message ("
                                                    + encodingStr + "), falling back to UTF-8");
                                                encoding = Encoding.UTF8;
                                            }
                                        }
                                    }
                                }

                                userinfo.AvailableMessage = Encoding.Unicode.GetString(
                                    Encoding.Convert(encoding, Encoding.Unicode, amessage));

                            }
                            break;
                        default:
                            break;
                    }
                }
            }
        }
コード例 #4
0
ファイル: ByteStream.cs プロジェクト: pkt30/OscarLib
 /// <summary>
 /// Writes a <see cref="BartID"/> into the stream
 /// </summary>
 public void WriteBartID(BartID value)
 {
     lock (this)
     {
         dataSegments.Add(new BartIDSegment(value));
         byteCount += 4 + value.Data.Length;
     }
 }
コード例 #5
0
        /// <summary>
        /// Parses a byte buffer into an <see cref="BartID"/> object
        /// </summary>
        private void ReadIconInfo(byte[] buffer, UserInfo userinfo)
        {
            using (ByteStream iconStream = new ByteStream(buffer))
            {
                int iconStreamSize = iconStream.GetByteCount();

                while (iconStream.CurrentPosition + 4 <= iconStreamSize)
                {
                    BartID item = new BartID(iconStream);

                    // Find the end of the current data item in the stream
                    int endDataPosition = iconStream.CurrentPosition + item.Data.Length;

                    switch (item.Type)
                    {
                    case BartTypeId.BuddyIcon:
                        if (!GraphicsManager.IsBlankIcon(item.Data))
                        {
                            userinfo.Icon = item;
                        }
                        break;

                    case BartTypeId.StatusString:     // Available message
                        using (ByteStream messageStream = new ByteStream(item.Data))
                        {
                            Encoding encoding = Encoding.UTF8;
                            byte[]   amessage = new byte[0];

                            if (messageStream.HasMoreData)
                            {
                                // Pull the message to a byte array, assume at first that the encoding
                                // is UTF-8.  If existing encoding information exists, use that instead
                                amessage = messageStream.ReadByteArray(messageStream.ReadByte());

                                // Check if there's encoding information available
                                if (messageStream.HasMoreData)
                                {
                                    // Check to see if the encoding's been specified
                                    if (messageStream.ReadUshort() == 0x0001)
                                    {
                                        messageStream.AdvanceOffset(2);
                                        string encodingStr = messageStream.ReadString(messageStream.ReadUshort(), Encoding.ASCII);

                                        // Try to use the encoding from the byte stream
                                        try
                                        {
                                            encoding = Encoding.GetEncoding(encodingStr);
                                        }
                                        catch (ArgumentException)
                                        {
                                            Logging.WriteString(
                                                "ReadIconInfo: Got unknown encoding for available message ("
                                                + encodingStr + "), falling back to UTF-8");
                                            encoding = Encoding.UTF8;
                                        }
                                    }
                                }
                            }

                            userinfo.AvailableMessage = Encoding.Unicode.GetString(
                                Encoding.Convert(encoding, Encoding.Unicode, amessage));
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
        }
コード例 #6
0
 public BartIDSegment(BartID value)
 {
     item = value;
 }