/// <summary> /// Processes a download reply - SNAC(10,07) /// </summary> /// <param name="dp">A <see cref="DataPacket"/> object with a buffer containing SNAC(10,07)</param> private void ProcessDownloadReply(DataPacket dp) { string screenName = dp.Data.ReadString(dp.Data.ReadByte(), Encoding.ASCII); BartID queriedId = new BartID(dp.Data); currentlyDownloading.Remove(queriedId); BartReplyCode responseCode = (BartReplyCode)dp.Data.ReadByte(); if (responseCode == BartReplyCode.Success) { BartID replyId = new BartID(dp.Data); ushort dataLength = dp.Data.ReadUshort(); byte[] data = dp.Data.ReadByteArray(dataLength); if (!Directory.Exists(AutoSaveLocation)) { MemoryStream iconStream = new MemoryStream(data); if (BuddyIconReceived != null) { BuddyIconReceived(this, new BuddyIconReceivedEventArgs(screenName, replyId, iconStream)); } } else { string saveLocation = Path.Combine(AutoSaveLocation, replyId.ToString()); using (FileStream writer = new FileStream(saveLocation, FileMode.Create, FileAccess.Write)) { writer.Write(data, 0, data.Length); } OnBuddyIconDownloaded(screenName, replyId, saveLocation); } } }
/// <summary> /// Raises the <see cref="BuddyIconDownloaded"/> event /// </summary> protected internal void OnBuddyIconDownloaded(string screenName, BartID iconId, string iconPath) { if (BuddyIconDownloaded != null) { BuddyIconDownloaded(this, new BuddyIconDownloadedEventArgs(screenName, iconId, iconPath)); } }
/// <summary> /// Compares the current instance with another object of the same type. /// </summary> public int CompareTo(object obj) { BartID other = obj as BartID; if (other != null) { return(ToString().CompareTo(other.ToString())); } return(-1); }
/// <summary> /// Processes an upload reply - SNAC(10,03) /// </summary> /// <param name="dp">A <see cref="DataPacket"/> object with a buffer containing SNAC(10,03)</param> private void ProcessUploadReply(DataPacket dp) { BartReplyCode responseCode = (BartReplyCode)dp.Data.ReadByte(); if (responseCode == BartReplyCode.Success) { BartID uploadedItem = new BartID(dp.Data); if (BuddyIconUploadCompleted != null) { BuddyIconUploadCompleted(this, new BuddyIconUploadCompletedArgs(uploadedItem)); } } else { OnBuddyIconUploadFailed(responseCode); } }
/// <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)); }
public override bool Equals(object obj) { BartID other = obj as BartID; return(other != null && ToString() == other.ToString()); }
/// <summary> /// Initializes a new BuddyIconDownloadedEventArgs /// </summary> public BuddyIconDownloadedEventArgs(string screenName, BartID iconId, string iconFile) { this.screenName = screenName; this.iconId = iconId; this.iconFile = iconFile; }
/// <summary> /// Initializes a new BuddyIconReceivedEventArgs /// </summary> public BuddyIconReceivedEventArgs(string screenName, BartID iconId, MemoryStream iconStream) { this.screenName = screenName; this.iconId = iconId; this.iconStream = iconStream; }
/// <summary> /// Initializes a new BuddyIconUploadCompletedArgs /// </summary> public BuddyIconUploadCompletedArgs(BartID bartId) { this.bartId = bartId; }
/// <summary> /// Processes a download reply - SNAC(10,07) /// </summary> /// <param name="dp">A <see cref="DataPacket"/> object with a buffer containing SNAC(10,07)</param> private void ProcessDownloadReply(DataPacket dp) { string screenName = dp.Data.ReadString(dp.Data.ReadByte(), Encoding.ASCII); BartID queriedId = new BartID(dp.Data); currentlyDownloading.Remove(queriedId); BartReplyCode responseCode = (BartReplyCode)dp.Data.ReadByte(); if (responseCode == BartReplyCode.Success) { BartID replyId = new BartID(dp.Data); ushort dataLength = dp.Data.ReadUshort(); byte[] data = dp.Data.ReadByteArray(dataLength); if (!Directory.Exists(AutoSaveLocation)) { MemoryStream iconStream = new MemoryStream(data); if(BuddyIconReceived != null) { BuddyIconReceived(this, new BuddyIconReceivedEventArgs(screenName, replyId, iconStream)); } } else { string saveLocation = Path.Combine(AutoSaveLocation, replyId.ToString()); using (FileStream writer = new FileStream(saveLocation, FileMode.Create, FileAccess.Write)) { writer.Write(data, 0, data.Length); } OnBuddyIconDownloaded(screenName, replyId, saveLocation); } } }