예제 #1
0
        /// <summary>
        /// Private method that contains the actual logic for adding a download
        /// </summary>
        /// <param name="item"></param>
        private void InternalAddDownload(IDownloadItem item)
        {
            // Check dirs
            if (!Directory.Exists(Config.Instance.GetInProgressDownloadsFolder()))
            {
                Directory.CreateDirectory(Config.Instance.GetInProgressDownloadsFolder());
            }
            if (!Directory.Exists(Config.Instance.GetCompleteDownloadsFolder()))
            {
                Directory.CreateDirectory(Config.Instance.GetCompleteDownloadsFolder());
            }

            // Create and store downloader
            IDownloader dl = DownloaderFactory.CreateFrom(item.DownloadUri);

            dl.SetItem(item);

            // Register events
            dl.DownloadProgressChanged += IDownloader_DownloadProgressChanged;
            dl.DownloadStatusChanged   += IDownloader_DownloadStatusChanged;

            downloads[dl.CurrentDownloadItem] = dl;
            // Fire event
            DownloadAdded?.Invoke(this, new DownloadEventArgs(dl.CurrentDownloadItem));

            UpdateActiveDownloads();
            SaveDownloads();
        }
        /// <summary>
        /// Downloads specified video.
        /// </summary>
        /// <param name="video">The video to download.</param>
        /// <param name="upgradeAudio">If true, only the audio will be downloaded and it will be merged with the local video file.</param>
        /// <param name="callback">The method to call once download is completed.</param>
        public async Task DownloadVideoAsync(string url, string destination, string description, EventHandler <DownloadCompletedEventArgs> callback, DownloadAction action, DownloadOptions options, object data)
        {
            if (IsDownloadDuplicate(url))
            {
                return;
            }

            Directory.CreateDirectory(Path.GetDirectoryName(destination));

            // Add DownloadItem right away before doing any async work.
            string       DestinationNoExt = Path.Combine(Path.GetDirectoryName(destination), Path.GetFileNameWithoutExtension(destination));
            DownloadItem DownloadInfo     = new DownloadItem(url, destination, DestinationNoExt, description, action, callback, options, data);

            Application.Current.Dispatcher.Invoke(() => {
                downloadsList.Insert(0, DownloadInfo);
                // Notify UI of new download to show window.
                DownloadAdded?.Invoke(this, new EventArgs());
            });

            if (downloadsList.Where(d => d.Status == DownloadStatus.Downloading || d.Status == DownloadStatus.Initializing).Count() < Options.SimultaneousDownloads)
            {
                await StartDownloadAsync(DownloadInfo).ConfigureAwait(false);
            }
        }
 protected void OnDownloadAdded()
 {
     DownloadAdded?.Invoke(this);
     DownloadsUpdated?.Invoke(this);
 }
예제 #4
0
 protected virtual void OnDownloadAdded(Downloader d, bool willStart)
 {
     DownloadAdded?.Invoke(this, new DownloaderEventArgs(d, willStart));
 }