public void SetItem(IDownloadItem item) { // I keep making this mistake - the ParseFrom method can return a new IDownloadItem, so then referencing `item` after // that references the old one, and so setting the values on that doesn't help anything... CurrentSSDownloadItem = SoulseekDownloadItem.ParseFrom(item); CurrentSSDownloadItem.DownloadingFilename = HttpUtility.UrlDecode(CurrentSSDownloadItem.DownloadUri.Segments.Last()); CurrentSSDownloadItem.CompletedFilename = CurrentSSDownloadItem.DownloadingFilename; CurrentSSDownloadItem.Progress = new DownloadProgress { BytesTotal = 0, BytesDownloaded = 0, Status = DownloadStatus.Pending }; DownloadStatusChanged?.Invoke(this, new DownloadEventArgs(CurrentDownloadItem)); }
/// <summary> /// Does the opposite of BuildFrom - it takes a faked uri and creates a downloadable item /// </summary> /// <param name="fakedUri"></param> /// <returns></returns> public static SoulseekDownloadItem DeconstructFrom(Uri fakedUri) { // Do some validation checks if (fakedUri.DnsSafeHost.ToLower() != "soulseek" && fakedUri.Scheme.ToLower() != "slsk") { throw new ArgumentException("download item is not a valid soulseek download item"); } var newItem = new SoulseekDownloadItem(); var ssFn = string.Join("", fakedUri.Segments); if (ssFn.StartsWith("/")) // Trim the '/' at the start from the first segment { ssFn = ssFn.Substring(1); } newItem.SoulseekFilename = HttpUtility.UrlDecode(ssFn); newItem.SoulseekUsername = HttpUtility.UrlDecode(fakedUri.UserInfo); return(newItem); }