private void AddAction() { WebDownloadClient download = new WebDownloadClient(URL, FolderPath, FileName); download.Start(); Download.DownloadManager.Instance.DownloadList.Add(download); _addWindow.Close(); }
private void DeserializeDownloads() { try { if (File.Exists("Downloads.xml")) { XElement downloads = XElement.Load("Downloads.xml"); if (downloads.HasElements) { IEnumerable <XElement> downloadList = from el in downloads.Elements() select el; foreach (XElement download in downloadList) { WebDownloadClient downloadClient = new WebDownloadClient(download.Element("url").Value, download.Element("download_path").Value, download.Element("filename").Value); downloadClient.FileSize = Convert.ToInt64(download.Element("file_size").Value); downloadClient.DownloadedSize = Convert.ToInt64(download.Element("downloaded_size").Value); Download.DownloadManager.Instance.DownloadList.Add(downloadClient); //Downloads = Download.DownloadManager.Instance.DownloadList; if (download.Element("downloading_status").Value == "Completed") { downloadClient.Status = DownloadStatus.Completed; } else { downloadClient.Status = DownloadStatus.Paused; } downloadClient.StatusString = download.Element("downloading_status_string").Value; downloadClient.ElapsedTime = TimeSpan.Parse(download.Element("total_time").Value); downloadClient.AddedOn = DateTime.Parse(download.Element("added_on").Value); downloadClient.CompletedOn = DateTime.Parse(download.Element("completed_on").Value); downloadClient.SupportRange = bool.Parse(download.Element("supports_range").Value); downloadClient.HasError = bool.Parse(download.Element("has_error").Value); if (downloadClient.Status == DownloadStatus.Paused && !downloadClient.HasError) { downloadClient.Start(); } } XElement mainElement = new XElement("downloads"); XDocument document = new XDocument(); document.Add(mainElement); document.Save("Downloads.xml"); } } }catch (Exception e) { MessageBox.Show(e.Message); } }
private void DeleteDownloadAction() { WebDownloadClient delete = (SelectedItem as WebDownloadClient); if (delete.Status != DownloadStatus.Completed) { File.Delete(delete.DownloadPath); Download.DownloadManager.Instance.DownloadList.Remove(delete); } else { Download.DownloadManager.Instance.DownloadList.Remove(delete); } }
void DownloadEmulator() { if (!Directory.Exists(ServiceTools.Storage.Source.PathEmulator)) { Directory.CreateDirectory(ServiceTools.Storage.Source.PathEmulator); WebDownloadClient download = new WebDownloadClient(0, "https://www.zerpico.ru/retrolauncher/mednafen.zip"); download.FileName = Path.Combine(ServiceTools.Storage.Source.PathEmulator, download.Url.ToString().Substring(download.Url.ToString().LastIndexOf("/") + 1)); download.DownloadCompleted += ((e, a) => { ArchiveExtractor.ExtractAll(download.FileName, ServiceTools.Storage.Source.PathEmulator, true); System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background, (Action) delegate() { DownloadManager.Instance.ClearDownload(0); }); }); string filePath = download.FileName; string tempPath = filePath + ".tmp"; download.CheckUrl(); if (download.HasError) { return; } download.TempDownloadPath = tempPath; download.AddedOn = DateTime.UtcNow; download.CompletedOn = DateTime.MinValue; // Add the download to the downloads list DownloadManager.Instance.DownloadsList.Add(download); download.Start(); } }