Exemplo n.º 1
0
        public void RemoveTorrentAndFiles(PeriodicTorrent torrent)
        {
            torrent.Torrent.TorrentStateChanged += (s, e) =>
            {
                if (e.NewState == TorrentState.Stopped || e.NewState == TorrentState.Error)
                {
                    Client.Unregister(torrent.Torrent);
                    // Delete cache
                    if (File.Exists(torrent.CacheFilePath))
                    {
                        File.Delete(torrent.CacheFilePath);
                    }
                    if (File.Exists(Path.Combine(SettingsManager.TorrentCachePath,
                                                 Path.GetFileNameWithoutExtension(torrent.CacheFilePath) + ".info")))
                    {
                        File.Delete(Path.Combine(SettingsManager.TorrentCachePath,
                                                 Path.GetFileNameWithoutExtension(torrent.CacheFilePath) + ".info"));
                    }
                    // Delete files
                    try
                    {
                        Directory.Delete(torrent.Torrent.Path, true);
                    }
                    catch { }

                    torrent.Torrent.Dispose();
                    Application.Current.Dispatcher.BeginInvoke(new Action(() => Torrents.Remove(torrent)));
                }
            };
            Task.Factory.StartNew(() => torrent.Stop());
        }
Exemplo n.º 2
0
        private void RemoveTorrentCommandExecute()
        {
            Messenger.Default.Send(new DeleteTorrentShowDialog((dialogResult) =>
            {
                if (dialogResult == true)
                {
                    SelectedItem.Stop();
                    engine.Unregister(SelectedItem.Manager);
                    saveLoadManager.Remove(SelectedItem.Manager);

                    ViewModelLocator locator = new ViewModelLocator();
                    var deleteTorrentVM      = locator.DeleteTorrent;

                    if (deleteTorrentVM.Delete == DeleteTorrent.DeleteWithDownloadedFiles)
                    {
                        foreach (var item in SelectedItem.Files)
                        {
                            File.Delete(SelectedItem.SavePath + "\\" + item.Path);
                        }

                        try
                        {
                            Directory.Delete(SelectedItem.SavePath, false);
                        }
                        catch (IOException)
                        {
                        }
                    }


                    SelectedItem.Manager.Dispose();
                    Torrents.Remove(SelectedItem);
                }
            }));
        }
Exemplo n.º 3
0
        public void OnTorrentRemoved(object sender, TorrentActionEventArgs args)
        {
            Torrent torrent = bitTorrentManager.GetTorrent(args.Handle);

            // Marshall the collection call back to the window thread, torrent will be captured
            Action dispatchAction = () => Torrents.Remove(torrent);

            this.currentDispatcher.BeginInvoke(dispatchAction);
        }
Exemplo n.º 4
0
        void RemoveDownload(Download download)
        {
            TreeIter iter;

            if (Torrents.GetIterFirst(out iter))
            {
                do
                {
                    if (download != Torrents.GetValue(iter, 0))
                    {
                        continue;
                    }

                    download.PriorityChanged -= HandlePriorityChanged;
                    download.StateChanged    -= HandleStateChanged;
                    Torrents.Remove(ref iter);
                    Selection.UnselectAll();
                    break;
                } while (Torrents.IterNext(ref iter));
            }
        }
Exemplo n.º 5
0
 public void RemoveTorrent(PeriodicTorrent torrent)
 {
     torrent.Torrent.TorrentStateChanged += (s, e) =>
     {
         if (e.NewState == TorrentState.Stopped || e.NewState == TorrentState.Error)
         {
             torrent.Stop();
             try
             {
                 Client.Unregister(torrent.Torrent);
             }
             catch { }     // TODO: See if we need to do more
             // Delete cache
             if (File.Exists(torrent.CacheFilePath))
             {
                 File.Delete(torrent.CacheFilePath);
             }
             if (File.Exists(Path.Combine(SettingsManager.TorrentCachePath,
                                          Path.GetFileNameWithoutExtension(torrent.CacheFilePath) + ".info")))
             {
                 File.Delete(Path.Combine(SettingsManager.TorrentCachePath,
                                          Path.GetFileNameWithoutExtension(torrent.CacheFilePath) + ".info"));
             }
             torrent.Torrent.Dispose();
             // We need to delay this until we're out of the handler for some reason
             Task.Factory.StartNew(() => Application.Current.Dispatcher.BeginInvoke(new Action(() => Torrents.Remove(torrent))));
         }
     };
     Task.Factory.StartNew(() => torrent.Stop());
 }