public void DeleteSubscriptionFiles(Callback Callback) { List <string> files = new List <string>(); List <Track> tracks = new List <Track>(); List <PodcastEpisode> ppe = this.Episodes.ToList(); foreach (PodcastEpisode pe in ppe) { if (pe.Track != null) { tracks.Add(pe.Track); if (pe.Track.ConfirmExists) { files.Add(pe.Track.FilePath); } } } Database.RemoveFromLibrary(tracks); if (files.Count > 0) { foreach (string s in files) { TrackWriter.AddToDeleteList(s); } } TrackWriter.DeleteItems(); this.Close(Callback); }
private void removeEpisode(PodcastEpisode PE) { List <frmTaskDialog.Option> options = new List <frmTaskDialog.Option>(); if (PE.Playable || PE.IsDownloading) // only ask if there's already some data { options.Add(new frmTaskDialog.Option("Remove Podcast Entry", "Remove this episode from the episode list but leave the audio file in your library.", 1)); options.Add(new frmTaskDialog.Option("Remove All", "Remove this episode from the list and delete the audio file.", 2)); options.Add(new frmTaskDialog.Option("Cancel", "Don't remove this episode.", 0)); frmTaskDialog od = new frmTaskDialog("Remove Podcast Episode", "Choose an option for removing a podcast episode:", options); od.ShowDialog(this); switch (od.ResultIndex) { case 0: return; case 1: break; case 2: if (PE.Track != null) { Database.RemoveFromLibrary(new List <Track>() { PE.Track }); TrackWriter.AddToDeleteList(PE.Track.FilePath); TrackWriter.DeleteItems(); PE.Track = null; } break; } } PE.SetDownloadStatus(PodcastDownloadStatus.Deleted); lvwEpisodes.RemoveItem(PE); }
public void Download() { cancelAllDownloads = false; cancelThisDownload = false; if (this.FileExists) { if (this.DownloadStatus != PodcastDownloadStatus.Played) { this.DownloadStatus = PodcastDownloadStatus.Unplayed; } } else { using (WebClient client = new WebClient()) { this.DownloadStatus = PodcastDownloadStatus.DownloadInProgress; updateDownloadStatusString(); Stream localStream = null; Stream resposeStream = null; HttpWebRequest webRequest = null; HttpWebResponse webResponse = null; try { long totalSize = 1; string localTempFile = Path.GetTempFileName(); webRequest = (HttpWebRequest)WebRequest.Create(this.URL); webRequest.Credentials = CredentialCache.DefaultCredentials; webRequest.ServicePoint.Expect100Continue = false; webResponse = (HttpWebResponse)webRequest.GetResponse(); totalSize = webResponse.ContentLength; resposeStream = client.OpenRead(this.URL); localStream = new FileStream(localTempFile, FileMode.Create, FileAccess.Write, FileShare.None); bool showProgress = totalSize > 100000; int chunkSize = 0; long bytesRecd = 0; long nextThreshold = 0; byte[] downBuffer = new byte[2048]; while ((chunkSize = resposeStream.Read(downBuffer, 0, downBuffer.Length)) > 0) { if (cancelAllDownloads || cancelThisDownload) { this.DownloadStatus = PodcastDownloadStatus.DownloadCanceled; return; } if (showProgress) { bytesRecd += chunkSize; if (bytesRecd > nextThreshold) { nextThreshold += totalSize / NUM_DOWNLOAD_UPDATES; updateDownloadStatusString("Downloading: " + (bytesRecd * 100L / totalSize).ToString() + "%"); } } localStream.Write(downBuffer, 0, chunkSize); } localStream.Close(); localStream = null; if (!Directory.Exists(Setting.PodcastDownloadDirectory)) { try { Directory.CreateDirectory(Setting.PodcastDownloadDirectory); } catch { } if (!Directory.Exists(Setting.PodcastDownloadDirectory)) { Setting.PodcastDownloadDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic); if (!Directory.Exists(Setting.PodcastDownloadDirectory)) { Directory.CreateDirectory(Setting.PodcastDownloadDirectory); } } } if (!Directory.Exists(Setting.PodcastDownloadDirectory)) { throw new Exception("failed2"); } string fileName = Lib.ReplaceBadFilenameChars(this.Subscription.Name + " - " + this.Title); string newPathRoot = Path.Combine(Setting.PodcastDownloadDirectory, fileName); string ext = Path.GetExtension(this.URL); string newPath = newPathRoot + ext; if (File.Exists(newPath)) { int i = 1; do { newPath = newPathRoot + (i++).ToString() + ext; }while (File.Exists(newPath)); } File.Copy(localTempFile, newPath); TrackWriter.AddToDeleteList(localTempFile); TrackWriter.DeleteItems(); AddToLibrary(newPath); fileExists = null; this.DownloadStatus = PodcastDownloadStatus.Unplayed; this.DownloadDate = DateTime.Now; if (this.DownloadDate > this.Subscription.LastDownloadDate) { this.Subscription.LastDownloadDate = this.DownloadDate; } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); this.DownloadStatus = PodcastDownloadStatus.Error; Controller.ShowMessage("Download of " + this.Title + " failed."); } finally { if (localStream != null) { localStream.Close(); } if (resposeStream != null) { resposeStream.Close(); } if (webResponse != null) { webResponse.Close(); } updateDownloadStatusString(); } } } System.Diagnostics.Debug.Assert(!this.IsDownloading); if (DataChanged != null) { DataChanged(this); } }