public ICollection <TorrentContext> TorrentList => _agent.TorrentList; // List of all managed torrents /// <summary> /// Update download information. This is used as the tracker callback to be invoked /// when the next announce response is recieved back for the torrent being downloaded. /// </summary> /// <param name="obj"></param> private void UpdateDownloadInformation(Object obj) { TorrentClient main = (TorrentClient)obj; TorrentDetails torrentDetails = _agent.GetTorrentDetails(_tc); main.ClientWindow.InfoWindow.Update(torrentDetails); }
/// <summary> /// Intialise main application status bar /// </summary> /// <param name="main"></param> public MainStatusBar(TorrentClient main) { _statusBarItems = new List <StatusItem>(); _download = new StatusItem(Key.ControlD, "~^D~ Download", () => { ActionDownload(main); }); _shutdown = new StatusItem(Key.ControlS, "~^S~ shutdown", () => { ActionShutdown(main); }); _toggleSeeding = new StatusItem(Key.ControlT, "~^T~ Toggle Seeding", () => { ActionToggleSeeding(main); }); _toggleSeedInformation = new StatusItem(Key.ControlJ, "~^J~ Seed Information", () => { ActionToggleSeedInformation(main); }); _quit = new StatusItem(Key.ControlQ, "~^Q~ Quit", () => { ActionQuit(main); }); Display(Status.Shutdown); }
/// <summary> /// Load torrents in the seeding directory. /// </summary> public void LoadSeedingTorrents(TorrentClient main) { Application.MainLoop.AddTimeout(TimeSpan.FromSeconds(2), UpdateSeederList); _torrentHandler = main.ClientWindow.TorrentHandler; foreach (var file in Directory.GetFiles(main.Configuration.SeedDirectory, "*.torrent")) { main.ClientWindow.TorrentHandler.AddSeedingTorrent(file, main.Configuration); } }
/// <summary> /// Creat application object and run it. /// </summary> static void Main(string[] _) { try { TorrentClient main = new TorrentClient(); main.Run(); } catch (Exception ex) { Application.MainLoop.Invoke(() => { MessageBox.Query("Error", ex.Message, "Ok"); }); } }
/// <summary> /// Initiate torrent download. /// </summary> /// <param name="mainWindow"></param> public void Download(TorrentClient main) { try { // Update status bar for starting download Application.MainLoop.Invoke(() => { main.MainStatusBar.Display(Status.StartingUp); }); // Load torrent file and parse MetaInfoFile torrentFile = new MetaInfoFile(_fileName); torrentFile.Parse(); Application.MainLoop.Invoke(() => { main.ClientWindow.UpdatProgressBar(0); main.ClientWindow.InfoWindow.SetTracker(torrentFile.GetTracker()); }); // Create torrent context and tracker _tc = new TorrentContext(torrentFile, _selector, _diskIO, main.Configuration.DestinationDirectory) { CallBack = UpdateDownloadProgress, CallBackData = main }; _tracker = new Tracker(_tc) { CallBack = UpdateDownloadInformation, CallBackData = main }; // Hookup tracker to agent, add torrent and startup everyhing up _agent.AddTorrent(_tc); _agent.AttachPeerSwarmQueue(_tracker); _tracker.StartAnnouncing(); _agent.StartTorrent(_tc); Application.MainLoop.Invoke(() => { main.MainStatusBar.Display(Status.Downloading); }); } catch (Exception ex) { Application.MainLoop.Invoke(() => { MessageBox.Query("Error", ex.Message, "Ok"); main.MainStatusBar.Display(Status.Shutdown); }); } }
/// <summary> /// Update torrent download progress bar (this is the torrent context progress callback). /// On completion of download copy torrent file to seeding directory and clear the main /// download information screen to allow a new torrent to be downloaded. /// </summary> /// <param name="obj"></param> private void UpdateDownloadProgress(Object obj) { TorrentClient main = (TorrentClient)obj; Application.MainLoop.Invoke(() => { main.ClientWindow.UpdatProgressBar((float)((double)_tc.TotalBytesDownloaded / (double)_tc.TotalBytesToDownload)); }); if (_tc.TotalBytesToDownload - _tc.TotalBytesDownloaded == 0) { _tracker.CallBack = null; _tracker.CallBackData = null; _tracker = null; _tc.CallBack = null; _tc.CallBackData = null; _tc = null; main.ResetWindowAndCopySeedingFile(); } }
/// <summary> /// Quit application. /// </summary> /// <param name="main"></param> private void ActionQuit(TorrentClient main) { main.ClientWindow.TorrentHandler.Shutdown(); Application.Top.Running = false; }
/// <summary> /// Toggle seeding list window and selected seeder information window. /// </summary> /// <param name="main"></param> private void ActionToggleSeedInformation(TorrentClient main) { main.ClientWindow.ToggleSeedinginformation(); }
/// <summary> /// Toggle seeder list and main torrent information window. /// </summary> /// <param name="main"></param> private void ActionToggleSeeding(TorrentClient main) { ToggleSeeding(main.ClientWindow.DisplayInformationWindow); main.ClientWindow.ToggleSeedingList(); }
/// <summary> /// Stop currently downloading torrent. /// </summary> /// <param name="main"></param> private void ActionShutdown(TorrentClient main) { main.ClientWindow.ClosedownTorrent(); main.MainStatusBar.Display(Status.Shutdown); }
/// <summary> /// Start torrent download. /// </summary> /// <param name="main"></param> private void ActionDownload(TorrentClient main) { main.ClientWindow.TorrentHandler.SetDownloadTorrent(main.ClientWindow.TorrentFileText.Text.ToString()); Task.Run(() => main.ClientWindow.TorrentHandler.Download(main)); }