internal void RaiseTorrentStateChanged(TorrentStateChangedEventArgs e)
 {
     // Whenever we have a state change, we need to make sure that we flush the buffers.
     // For example, Started->Paused, Started->Stopped, Downloading->Seeding etc should all
     // flush to disk.
     Toolbox.RaiseAsyncEvent <TorrentStateChangedEventArgs>(TorrentStateChanged, this, e);
 }
Esempio n. 2
0
        private void onTorrentStateChanged(object sender, TorrentStateChangedEventArgs e)
        {
            if (e.OldState == TorrentState.Downloading && e.NewState == TorrentState.Seeding)
                if (currentHandle != null)
                    currentHandle.Set();

            Debug.WriteLine(e.OldState + ", " + e.NewState);
        }
Esempio n. 3
0
        private void TorrentStateChanged(object sender, TorrentStateChangedEventArgs e)
        {
            if (e.NewState == MonoTorrent.Common.TorrentState.Error)
            {
                _mbus.Send<ITorrentError>(msg => msg.Torrent = this);
            }

            if (e.OldState == MonoTorrent.Common.TorrentState.Downloading && e.NewState == MonoTorrent.Common.TorrentState.Seeding)
            {
                if (_completedTime == null)
                    _completedTime = DateTime.Now;

                var oldSavePath = String.Copy(SavePath);

                _mbus.Send<ITorrentCompleted>(msg => msg.Torrent = this).ContinueWith(_ => BasicMove(oldSavePath));
            }
        }
Esempio n. 4
0
 internal void RaiseTorrentStateChanged(TorrentStateChangedEventArgs e)
 => TorrentStateChanged?.InvokeAsync(this, e);
Esempio n. 5
0
        public static void HandleTorrentStateChanged(object sender, 
            TorrentStateChangedEventArgs e)
        {
            var torrentManager = e.TorrentManager;
            var clientEngine = torrentManager.Engine;
            logger.DebugFormat("Torrent {0}: State changed from {1} to {2}", e.TorrentManager.Torrent.Name,
              e.OldState.ToString(), e.NewState.ToString());

            switch (e.NewState) {
                case TorrentState.Downloading:
                    logger.DebugFormat("Open connections: {0}", torrentManager.OpenConnections);
                    if (e.OldState == TorrentState.Hashing) {
                        logger.Debug("Hashing Mode completed.");

                        logger.DebugFormat("{0} chunks out of {1} already available.",
                            torrentManager.DedupManager.TotalChunksAvailable,
                            torrentManager.DedupManager.TotalChunks);

                        logger.DebugFormat("{0} pieces ({2} percent) already available out of {1} in total.",
                            torrentManager.Bitfield.TrueCount,
                            torrentManager.Torrent.Pieces.Count, torrentManager.Bitfield.PercentComplete);
                    }
                    break;
                case TorrentState.Seeding:
                    if (e.OldState == TorrentState.Downloading) {
                        logger.DebugFormat("Download completed.", torrentManager.Torrent.Name);

                        logger.Debug(GetStatsLog(torrentManager));
                        // Flush so that whoever is waiting for the download can
                        // read it immediately.
                        clientEngine.DiskManager.Flush(e.TorrentManager);
                    }
                    break;
                default:
                    break;
            }
        }
Esempio n. 6
0
        public void OnTorrentStateChanged(object sender, TorrentStateChangedEventArgs e)
        {
            if (e.NewState == TorrentState.Stopped)
            {
                try
                {
                    string resumeDataFileName = GetFastResumeFileName(e.TorrentManager);
                    using (FileStream resumeFile = File.OpenWrite(resumeDataFileName))
                    {
                        e.TorrentManager.SaveFastResume().Encode(resumeFile);
                        resumeFile.Flush();
                        resumeFile.Close();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error saving fastresume info for {0}, reason: {1}", e.TorrentManager.InfoHash.ToHex(),
                        ex.Message);
                }
            }

            if (e.NewState == TorrentState.Error || e.NewState == TorrentState.Stopped)
            {
                TorrentManager tm = e.TorrentManager;
                ClientEngine engine = tm.Engine;
                engine.Unregister(tm);
            }
            else if (e.TorrentManager.Progress == 100.0 && e.NewState == TorrentState.Seeding)
            {
                TorrentManager tm = e.TorrentManager;
                ClientEngine engine = tm.Engine;
                IList<TorrentManager> engineTorrents = engine.Torrents;

                bool allSeeding = engineTorrents.Count(m => { return (m.Progress < 100 || m.State != TorrentState.Seeding); }) < 1;
                if (allSeeding)
                {
                    if (updater != null && !errorMsgsOnly)
                        updater.Status = DayZeroLauncherUpdater.STATUS_UPTODATE;

                    if (downloader != null)
                        downloader.IsRunning = false;

                    StatusCallbacks(TorrentState.Stopped, 1);
                }
            }
        }
        public void OnTorrentStateChanged(object sender, TorrentStateChangedEventArgs e)
        {
            if (e.TorrentManager.Progress == 100.0 && e.NewState == TorrentState.Seeding)
            {
                bool lastFile = !torrents.Exists(delegate(TorrentManager m) { return m.Progress != 100; });
                if (lastFile)
                {
                    if (installer != null)
                        installer.Status = "Installing..";
                    if (updater != null)
                        updater.Status = DayZeroLauncherUpdater.STATUS_UPTODATE;
                }

                foreach (string f in Directory.GetFiles(Path.Combine(downloadsPath, e.TorrentManager.Torrent.Name), "*.*", SearchOption.AllDirectories))
                {
                    if (e.TorrentManager.Torrent.Files.None(t => t.FullPath.ToLower() == f.ToLower()))
                    {
                        if (!f.Contains("ra_chat_off.pbo"))
                            File.Delete(f);
                    }
                }
                if (lastFile)
                {
                    if (installer != null)
                    {
                        installer.Status = "Ready to Play";
                    }
                    StopTorrents();

                    CalculatedGameSettings.Current.Update();
                }
            }
        }
Esempio n. 8
0
 internal void RaiseTorrentStateChanged(TorrentStateChangedEventArgs e)
 => Toolbox.RaiseAsyncEvent(TorrentStateChanged, this, e);
 private void torrent_TorrentStateChanged(object sender, TorrentStateChangedEventArgs e)
 {
     try
     {
         this.Invoke(stateHandler);
     }
     catch { }
 }
        private void manager_TorrentStateChanged(object sender, TorrentStateChangedEventArgs args)
        {
            try {
                LoggingService.LogDebug("State: {0}", args.NewState);
                LoggingService.LogDebug("Progress: {0:0.00}", this.manager.Progress);

                if (args.NewState == TorrentState.Downloading || (args.NewState == TorrentState.Seeding && args.OldState != TorrentState.Downloading)) {
                    // XXX: Only have the requesting end connect for now,
                    // so we dont end up with redundant conncetions in each direction.
                    // We need a solution for this that can handle reverse connections.
                    if (!(File is LocalFile)) {
                        LoggingService.LogDebug("Torrent is ready! connecting to peers!");
                        lock (this.peers) {
                            bool didConnect = false;
                            foreach (IFileTransferPeer p in this.peers) {
                                BitTorrentFileTransferPeer peer = (BitTorrentFileTransferPeer)p;
                                if (ConnectToPeer(peer))
                                    didConnect = true;
                            }
                            if (!didConnect) {
                                base.statusDetail = "Unable to connect to any peers";
                                this.Cancel();
                            }
                        }
                    } else {
                        LoggingService.LogDebug("Torrent is ready! Waiting for connections from peers!");
                    }
                }

                if (args.NewState == TorrentState.Seeding && this.manager.Progress == 100) {

                    if (Direction == FileTransferDirection.Download) {
                        if (Core.Settings.IncompleteDownloadDir != Core.Settings.CompletedDownloadDir) {
                            // Ensure torrent is stopped before attempting to move file, to avoid access violation.
                            manager.Stop();

                            IO.File.Move(IO.Path.Combine(Core.Settings.IncompleteDownloadDir, file.Name),
                                         IO.Path.Combine(Core.Settings.CompletedDownloadDir, file.Name));
                        }
                    }

                    foreach (BitTorrentFileTransferPeer peer in base.peers) {
                        if (peer.Peer == null || !peer.Peer.IsSeeder) {
                            return;
                        }
                    }

                    if (manager == null || manager.Progress != 100) {
                        // If we got here, then everyone is a seeder.
                        // No need to keep the transfer active.
                        this.Cancel();
                    } else {
                        // Success! Ensure torrent is stopped.
                        manager.Stop();
                    }
                }
            } catch (Exception ex) {
                LoggingService.LogError("Error in manager_TorrentStateChanged.", ex);
                this.Cancel();
            }
        }
		private void OnTorrentStateChanged(object sender, TorrentStateChangedEventArgs args)
		{
			TorrentManager manager = (TorrentManager)sender;
			
			Gtk.Application.Invoke (delegate {
				if (args.OldState == TorrentState.Downloading) {
					logger.Debug("Removing " + manager.Torrent.Name + " from download label");
					mainWindow.DownloadingLabel.RemoveTorrent(manager);
				} else if (args.OldState == TorrentState.Seeding) {
					logger.Debug("Removing " + manager.Torrent.Name + " from upload label");
					mainWindow.SeedingLabel.RemoveTorrent(manager);
				}
				
				if (args.NewState == TorrentState.Downloading) {
					logger.Debug("Adding " + manager.Torrent.Name + " to download label");
					mainWindow.DownloadingLabel.AddTorrent(manager);
				} else if (args.NewState == TorrentState.Seeding) {
					logger.Debug("Adding " + manager.Torrent.Name + " to upload label");
					mainWindow.SeedingLabel.AddTorrent(manager);
				}
			
				if (!prefSettings.EnableNotifications)
					return;
				if (args.NewState != TorrentState.Seeding)
					return;
				if (args.OldState != TorrentState.Downloading)
					return;
			
				Notifications.Notification notify = new Notifications.Notification ("Download Complete", manager.Torrent + " has finished downloading.");
				notify.AttachToWidget (mainWindow.TrayIcon);
				notify.Timeout = 5000;
				notify.Show ();
			});
			
		}
Esempio n. 12
0
        static void torrentManager_TorrentStateChanged(object sender, 
            TorrentStateChangedEventArgs e)
        {
            Debug.WriteLine(string.Format("Torrent state changed {0} => {1}",
            e.OldState, e.NewState));

              if (e.NewState == TorrentState.Seeding) {
            if (e.OldState == TorrentState.Downloading) {
              Debug.WriteLine("Entire torrent download completed");
            }
              }
        }
Esempio n. 13
0
        private void TorrentStateChanged(object sender, TorrentStateChangedEventArgs e)
        {
            if (e.NewState == MonoTorrent.Common.TorrentState.Error)
            {
                _mbus.Send<ITorrentError>(msg => msg.Torrent = this);
            }

            if (e.OldState == MonoTorrent.Common.TorrentState.Downloading && e.NewState == MonoTorrent.Common.TorrentState.Seeding)
            {
                if (_completedTime == null)
                    _completedTime = DateTime.Now;

                var oldSavePath = String.Copy(SavePath);

                _mbus.Send<ITorrentCompleted>(msg => msg.Torrent = this).ContinueWith(_ =>
                                                                                          {
                                                                                              if(!oldSavePath.Equals(SavePath))
                                                                                                  return;

                                                                                              var moveCompleted =
                                                                                                  _kvs.Get<bool>(
                                                                                                      "paths.shouldMoveCompleted");

                                                                                              var newPath =
                                                                                                  _kvs.Get<string>(
                                                                                                      "paths.completedPath");

                                                                                              if(moveCompleted && !String.IsNullOrEmpty(newPath))
                                                                                              {
                                                                                                  var appendLabel =
                                                                                                      _kvs.Get<bool>(
                                                                                                          "paths.appendLabelOnMoveCompleted");

                                                                                                  if (appendLabel && !String.IsNullOrEmpty(Label))
                                                                                                      newPath =
                                                                                                          Path.Combine(
                                                                                                              newPath,
                                                                                                              Label);

                                                                                                  Move(newPath);
                                                                                              }
                                                                                          });
            }
        }