private void TorrentRemovedAlert(Core.torrent_removed_alert a) { Interlocked.MemoryBarrier(); using (Core.Sha1Hash sha1hash = a.info_hash) { string hash = sha1hash.ToString(); if (TorrentList.ToList().Any(e => e.Hash == hash)) { Models.TorrentItem ti = TorrentList.ToList().First(f => f.Hash == hash); log.Debug("removing {0}", ti.Name); Application.Current.Dispatcher.BeginInvoke( System.Windows.Threading.DispatcherPriority.Normal, (Action) delegate() { TorrentList.Remove(ti); }); log.Info("{0} removed", ti.Name); } if (File.Exists("./Fastresume/" + hash + ".fastresume")) { File.Delete("./Fastresume/" + hash + ".fastresume"); } if (File.Exists("./Fastresume/" + hash + ".torrent")) { File.Delete("./Fastresume/" + hash + ".torrent"); } } }
private void PieceFinishedAlert(piece_finished_alert a) { Interlocked.MemoryBarrier(); using (Core.TorrentHandle th = a.handle) using (Core.Sha1Hash hash = th.info_hash()) { if (TorrentList.ToList().Any(x => x.Hash == hash.ToString())) { Models.TorrentItem ti = TorrentList.First(z => z.Hash == hash.ToString()); if (!ReferenceEquals(null, ti.Pieces.Parts) && ti.Pieces.Parts.Any(q => q.Id == a.piece_index)) { ti.Pieces.Parts[a.piece_index].Downloaded = true; log.Debug("{0} for {1}", a.piece_index, ti.Name); foreach (Models.FileEntry item in ti.FileList) { foreach (Models.Part part in item.Pieces.Where(k => k.Id == a.piece_index)) { part.Downloaded = true; } } if (ti.SequentialDownload) { if (ti.Pieces.Parts.Any(w => w.Downloaded == false)) { Models.Part mp = ti.Pieces.Parts.First(w => w.Downloaded == false); mp.Priority = 7; th.piece_priority(mp.Id, 7); } } } } } }
private void btnResume_Click(object sender, RoutedEventArgs e) { Image os = (Image)e.OriginalSource; Models.TorrentItem ti = (Models.TorrentItem)os.DataContext; TsunamiViewModel res = (TsunamiViewModel)FindResource("TsunamiVM"); res.ResumeTorrent(ti.Hash); }
private void FormFadeOut_Completed(object sender, EventArgs e) { if (DataContext is Models.TorrentItem) { Models.TorrentItem ti = (Models.TorrentItem)DataContext; TsunamiViewModel res = (TsunamiViewModel)FindResource("TsunamiVM"); res.RemoveTorrent(ti.Hash, _deleteFileToo); _deleteFileToo = false; } }
private async void torrentFile_PreviewMouseDown(object sender, MouseButtonEventArgs e) { TextBlock or = (TextBlock)e.OriginalSource; Models.TorrentItem ti = (Models.TorrentItem)or.DataContext; FileList fileList = new FileList { DataContext = ti }; await MaterialDesignThemes.Wpf.DialogHost.Show(fileList, "RootDialog"); }
private void torrentItem_PropertyChanged(object sender, PropertyChangedEventArgs e) { Interlocked.MemoryBarrier(); if (e.PropertyName == "SequentialDownload") { Models.TorrentItem ti = (Models.TorrentItem)sender; using (Core.Sha1Hash hash = new Core.Sha1Hash(ti.Hash)) using (Core.TorrentHandle th = _torrentSession.find_torrent(hash)) { th.set_sequential_download(ti.SequentialDownload); if (ti.SequentialDownload) { // lower all parts priority to 1 foreach (Models.Part mp in ti.Pieces.Parts.Where(x => x.Downloaded == false)) { mp.Priority = 1; th.piece_priority(mp.Id, 1); } // highest priority only at first an last part if not already downloaded if (ti.Pieces.Parts.First().Downloaded == false || ti.Pieces.Parts.Last().Downloaded == false) { Models.Part firstPart = ti.Pieces.Parts.First(); Models.Part lastPart = ti.Pieces.Parts.Last(); firstPart.Priority = 7; lastPart.Priority = 7; th.piece_priority(firstPart.Id, 7); th.piece_priority(lastPart.Id, 7); } else { // first and last part already downloaded, proceed with next undownloaded part if (ti.Pieces.Parts.Any(w => w.Downloaded == false)) { Models.Part mp = ti.Pieces.Parts.First(w => w.Downloaded == false); mp.Priority = 7; th.piece_priority(mp.Id, 7); } } } else { // not sequencial, all part with default priority foreach (Models.Part mp in ti.Pieces.Parts.Where(x => x.Downloaded == false)) { mp.Priority = 4; th.piece_priority(mp.Id, 4); } } } } }
private async void StateUpdateAlert(Core.state_update_alert a) { Interlocked.MemoryBarrier(); log.Trace("state update alert for {0} torrents", a.status.Count()); if (a.status.Count() > 0 && log.IsDebugEnabled) { log.Debug("state update alert for {0} torrents", a.status.Count()); } foreach (Core.TorrentStatus ts in a.status) { using (ts) using (Core.Sha1Hash hash = ts.info_hash) { if (TorrentList.ToList().Any(z => z.Hash == hash.ToString())) { Models.TorrentItem ti = TorrentList.First(e => e.Hash == hash.ToString()); await System.Threading.Tasks.Task.Run(() => ti.Update(ts)); } } } }
private async void TorrentAddedAlert(Core.torrent_added_alert a) { Interlocked.MemoryBarrier(); using (Core.TorrentHandle th = a.handle) using (Core.TorrentStatus ts = th.status()) { Models.TorrentItem ti = new Models.TorrentItem(ts); ti.PropertyChanged += torrentItem_PropertyChanged; await Application.Current.Dispatcher.BeginInvoke( System.Windows.Threading.DispatcherPriority.Send, (Action) delegate() { TorrentList.Add(ti); log.Debug("{0} added", ti.Name); //Hardcodet.Wpf.TaskbarNotification.TaskbarIcon tbi = (Hardcodet.Wpf.TaskbarNotification.TaskbarIcon)App.Current.MainWindow.FindName("tsunamiNotifyIcon"); //string title = "Tsunami"; //string text = "New torrent added!"; //tbi.ShowBalloonTip(title, text, tbi.Icon, true); }); } }
private async void btnCancel_Click(object sender, MouseButtonEventArgs e) { Image or = (Image)e.OriginalSource; Models.TorrentItem ti = (Models.TorrentItem)or.DataContext; var deleteMessageDialog = new Dialogs.DelDialog { DataContext = ti }; await MaterialDesignThemes.Wpf.DialogHost.Show(deleteMessageDialog, "RootDialog"); if (deleteMessageDialog.DeleteTorrent && deleteMessageDialog.DeleteFile) { _deleteFileToo = true; FormFadeOut.Begin(); } if (deleteMessageDialog.DeleteTorrent && !deleteMessageDialog.DeleteFile) { _deleteFileToo = false; FormFadeOut.Begin(); } }