private async void bgBtn_Click(object sender, RoutedEventArgs e) { try { DownLoadFileInfo dl = dlIngList.SelectedItem as DownLoadFileInfo; if (dl == null || !await PopupTip.CheckNetWork()) { return; } System.Windows.Controls.Button btn = sender as System.Windows.Controls.Button; string content = btn.Content.ToString(); if (content == "开始" || content == "继续") { StartSelections(); } else if (content == "播放") { System.Diagnostics.Process.Start(MainWindow.DownloadFolder + dl.FileName); } else { Pause(); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
private void dlBtn_Click(object sender, RoutedEventArgs e) { DownLoadFileInfo dl = dlIngList.SelectedItem as DownLoadFileInfo; if (dl == null) { return; } System.Windows.Controls.Button btn = sender as System.Windows.Controls.Button; if (btn.Content.ToString() == "移除") { RemoveSelections(); } else { try { System.IO.File.Delete(dl.FileLink); } catch (System.IO.IOException ex) { Console.WriteLine(ex); } } }
public void UpdateList() { for (int i = 0; i < DownloadingList.Count; i++) { DownLoadFileInfo di = DownloadingList[i]; Downloader d = mapObjToDownload[di] as Downloader; if (d == null) { return; } DownloaderState state = DownloaderState.Working; if (state != d.State || state == DownloaderState.Working || state == DownloaderState.WaitingForReconnect) { di.DownloadProcess = d.Progress; if ((DownloaderState)mapObjToCurrentState[di] != d.State) { di.DownloadState = d.State; mapObjToCurrentState[di] = d.State; } } } UpdateSegments(); }
void Instance_DownloadRemoved(object sender, DownloaderEventArgs e) { this.Dispatcher.BeginInvoke(new Action(() => { DownLoadFileInfo item = mapDownloadToObj[e.Downloader] as DownLoadFileInfo; if (item != null) { DownloadingList.Remove(item); mapDownloadToObj[e.Downloader] = null; mapObjToDownload[item] = null; } } )); }
private void AddDownload(Downloader d) { string ext = System.IO.Path.GetExtension(d.LocalFile); DownLoadFileInfo dInfo = new DownLoadFileInfo(); dInfo.FileName = System.IO.Path.GetFileName(d.LocalFile); dInfo.FileSize = ByteFormatter.ToString(d.FileSize); dInfo.DownloadProcess = d.Progress; dInfo.FileLink = d.ResourceLocation.URL; dInfo.FileAlbum = d.ResourceLocation.Password; dInfo.DownloadState = d.State; mapDownloadToObj[d] = dInfo; mapObjToDownload[dInfo] = d; mapObjToCurrentState[dInfo] = d.State; DownloadingList.Add(dInfo); }
private void UpdateSegments() { try { if (dlIngList.SelectedItems.Count == 1) { DownLoadFileInfo newSelection = dlIngList.SelectedItems[0] as DownLoadFileInfo; Downloader d = mapObjToDownload[newSelection] as Downloader; } else { lastSelection = null; } } finally { } }
private void DownloadsAction(ActionDownloader action) { if (dlIngList.SelectedItems.Count > 0) { try { dlIngList.SelectionChanged -= new SelectionChangedEventHandler(lvwDownloads_ItemSelectionChanged); for (int i = dlIngList.SelectedItems.Count - 1; i >= 0; i--) { DownLoadFileInfo item = dlIngList.SelectedItems[i] as DownLoadFileInfo; action((Downloader)mapObjToDownload[item], null); } dlIngList.SelectionChanged += new SelectionChangedEventHandler(lvwDownloads_ItemSelectionChanged); lvwDownloads_ItemSelectionChanged(null, null); } finally { UpdateSegments(); } } }