Esempio n. 1
0
        private void DownloadTask_StatusUpdate(DownloadTask downloadTask, double progressPercentage, long bps, DownloadTask.Status status)
        {
            try
            {
                Dispatcher.Invoke(new Action(() =>
                {
                    switch (status)
                    {
                    case DownloadTask.Status.Downloading:
                        InfoBox.Foreground = new SolidColorBrush(Color.FromRgb(0x00, 0x00, 0x00));
                        InfoBox.Text       = string.Format("{0:0.0}%    {1}    下载中...", progressPercentage, FormatBps(bps));
                        PBar.Value         = progressPercentage;
                        break;

                    case DownloadTask.Status.Analyzing:
                        InfoBox.Foreground = new SolidColorBrush(Color.FromRgb(0x00, 0x00, 0x00));
                        InfoBox.Text       = "正在获取下载地址...";
                        PBar.Value         = progressPercentage;
                        break;

                    case DownloadTask.Status.Merging:
                        InfoBox.Foreground = new SolidColorBrush(Color.FromRgb(0x00, 0x00, 0x00));
                        InfoBox.Text       = "正在完成...";
                        PBar.Value         = progressPercentage;
                        break;

                    case DownloadTask.Status.Finished:
                        InfoBox.Foreground = new SolidColorBrush(Color.FromRgb(0x00, 0x00, 0x00));
                        InfoBox.Text       = "下载完成!!!";
                        PBar.Value         = progressPercentage;
                        break;

                    case DownloadTask.Status.AnalysisFailed:
                        InfoBox.Foreground = new SolidColorBrush(Color.FromRgb(0xf2, 0x5d, 0x8e));
                        InfoBox.Text       = string.Format("获取下载地址失败,将在{0}秒后重试", bps);
                        break;
                    }
                }));
            }
            catch (TaskCanceledException)
            {
            }
        }
Esempio n. 2
0
        private void Append(DownloadTask downloadTask)
        {
            foreach (ListBoxItem i in QueueList.Items)
            {
                DownloadQueueItem dqi = (DownloadQueueItem)i.Content;
                if (dqi.downloadTask.Aid == downloadTask.Aid &&
                    dqi.downloadTask.Cid == downloadTask.Cid &&
                    dqi.downloadTask.Qn == downloadTask.Qn)
                {
                    return;
                }
            }
            DownloadQueueItem downloadQueueItem = new DownloadQueueItem(downloadTask);

            downloadQueueItem.Finished += DownloadQueueItem_Finished;
            downloadQueueItem.Remove   += DownloadQueueItem_Remove;
            ListBoxItem listBoxItem = new ListBoxItem();

            listBoxItem.Content = downloadQueueItem;
            QueueList.Items.Add(listBoxItem);
            ItemMap.Add(downloadQueueItem, listBoxItem);
        }
Esempio n. 3
0
 private void DownloadManager_Appended(DownloadTask downloadTask)
 {
     Append(downloadTask);
 }
Esempio n. 4
0
        private void QualityListItem_Selected(object sender, RoutedEventArgs e)
        {
            DownloadTask downloadTask = new DownloadTask(new DownloadInfo(((VideoInfo.Page.Quality)((ListBoxItem)sender).Tag), ConfigManager.GetSettings().DownloadThreads));

            TaskCreated?.Invoke(downloadTask);
        }
Esempio n. 5
0
 public static void Remove(DownloadTask downloadTask)
 {
     downloadTask.Clean();
     TaskList.Remove(downloadTask);
     ConfigUtil.ConfigManager.RemoveDownloadInfo(downloadTask.Info);
 }
Esempio n. 6
0
 private static void DownloadTask_StatusUpdate(DownloadTask downloadTask, double progressPercentage, long bps, DownloadTask.Status statues)
 {
     Console.WriteLine("{0} {1} {2}", downloadTask.Title, progressPercentage, statues);
 }
Esempio n. 7
0
 private void DownloadTask_Finished(DownloadTask downloadTask, string filepath)
 {
     Finished?.Invoke(this);
 }
Esempio n. 8
0
 private void DownloadTask_Finished(DownloadTask downloadTask)
 {
     Finished?.Invoke(this);
 }
Esempio n. 9
0
        private static ToastNotifier SendToast(DownloadTask downloadTask, string filepath)
        {
            string imagefolder = Path.Combine(ConfigManager.GetSettings().TempPath, "Image");
            string imagename   = downloadTask.Pic.Substring(downloadTask.Pic.LastIndexOf('/') + 1);
            string imagepath   = Path.Combine(imagefolder, imagename);

            // Clean workspace

            if (Directory.Exists(imagefolder))
            {
                DirectoryInfo directoryInfo = new DirectoryInfo(imagefolder);
                DateTime      datetime      = DateTime.UtcNow.AddDays(-3);
                foreach (FileInfo fileInfo in directoryInfo.GetFiles())
                {
                    if (fileInfo.CreationTime.CompareTo(datetime) < 0)
                    {
                        File.Delete(fileInfo.FullName);
                    }
                }
            }
            else
            {
                Directory.CreateDirectory(imagefolder);
            }

            // Download Image

            Image          image   = null;
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(downloadTask.Pic);

            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                using (Stream dataStream = response.GetResponseStream())
                {
                    image = Image.FromStream(dataStream);
                }
            }

            // Resize Image

            int    width        = 364;
            int    height       = 180;
            double scale        = (double)height / image.Height;
            int    resizedWidth = (int)(image.Width * scale);
            int    xOffset      = (width - resizedWidth) / 2;

            Image resizedImage = null;

            using (Bitmap bitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
            {
                using (Graphics graphics = Graphics.FromImage(bitmap))
                {
                    graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                    graphics.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                    graphics.DrawImage(image, new Rectangle(xOffset, 0, resizedWidth, height));
                }
                resizedImage = new Bitmap(bitmap);
            }
            resizedImage.Save(imagepath);

            // Create Toast

            string toastXml;

            using (StreamReader streamReader = new StreamReader(Application.GetResourceStream(new Uri("/BiliDownload/DownloadFinishedToast.xml", UriKind.Relative)).Stream))
            {
                toastXml = string.Format(streamReader.ReadToEnd(), SecurityElement.Escape(downloadTask.Title), SecurityElement.Escape(string.Format("{0}-{1}    {2}", downloadTask.Index, downloadTask.Part, downloadTask.Description)), SecurityElement.Escape(imagepath), SecurityElement.Escape(filepath));
            }

            // Send Toast

            ToastNotifier toastNotifier = NotificationManager.Show(toastXml);

            return(toastNotifier);
        }
Esempio n. 10
0
 private static void ShowToast(DownloadTask downloadTask, string filepath)
 {
     SendToast(downloadTask, filepath);
 }
Esempio n. 11
0
        private void QualityListItem_Selected(object sender, RoutedEventArgs e)
        {
            DownloadTask downloadTask = new DownloadTask(new DownloadInfo(((VideoInfo.Page.Quality)((ListBoxItem)sender).Tag), Bili_dl.SettingPanel.settings.DownloadThreads));

            TaskCreated?.Invoke(downloadTask);
        }