Exemple #1
0
        /// <summary>
        /// Downloads a buddy icon from the AIM servers
        /// </summary>
        /// <param name="screenName">The screenname to which the icon belongs</param>
        /// <param name="iconId">The ID of the icon stored on the server</param>
        public void DownloadBuddyIcon(string screenName, BartID iconId)
        {
            // Check to make sure the icon ID is valid and actually a buddy icon
            if (iconId == null || iconId.Data == null ||
                !(iconId.Type == BartTypeId.BuddyIcon || iconId.Type == BartTypeId.BigBuddyIcon))
            {
                return;
            }

            // Check to see if the icon's cached, if the cache location is set
            if (!String.IsNullOrEmpty(AutoSaveLocation))
            {
                string saveLocation = Path.Combine(AutoSaveLocation, iconId.ToString());
                if (File.Exists(saveLocation))
                {
                    OnBuddyIconDownloaded(screenName, iconId, saveLocation);
                    return;
                }
            }

            // Check to see if there's already a request in progress for this icon ID
            if (currentlyDownloading.Contains(iconId))
            {
                return;
            }
            currentlyDownloading.Add(iconId);

            SNACHeader sh = new SNACHeader();
            sh.FamilyServiceID = SNAC_BART_FAMILY;
            sh.FamilySubtypeID = BART_DOWNLOAD;
            sh.Flags = 0;

            ByteStream stream = new ByteStream();
            stream.WriteByte((byte)Encoding.ASCII.GetByteCount(screenName));
            stream.WriteString(screenName, Encoding.ASCII);
            stream.WriteByte(0x01);
            stream.WriteBartID(iconId);

            SNACFunctions.BuildFLAP(Marshal.BuildDataPacket(parent, sh, stream));
        }