Пример #1
0
        internal void UpdateSeedingDownloadingState()
        {
            UpdatePartialProgress();

            //If download is fully complete, set state to 'Seeding' and send an announce to the tracker.
            if (Manager.Complete && state == TorrentState.Downloading)
            {
                state = TorrentState.Seeding;
                Manager.RaiseTorrentStateChanged(new TorrentStateChangedEventArgs(Manager, TorrentState.Downloading, TorrentState.Seeding));
                _ = Manager.TrackerManager.Announce(TorrentEvent.Completed);
            }
            else if (Manager.PartialProgressSelector.TrueCount > 0)
            {
                // If some files are marked as DoNotDownload and we have downloaded all downloadable files, mark the torrent as 'seeding'.
                // Otherwise if we have not downloaded all downloadable files, set the state to Downloading.
                if (Manager.Bitfield.CountTrue(Manager.PartialProgressSelector) == Manager.PartialProgressSelector.TrueCount && state == TorrentState.Downloading)
                {
                    state = TorrentState.Seeding;
                    Manager.RaiseTorrentStateChanged(new TorrentStateChangedEventArgs(Manager, TorrentState.Downloading, TorrentState.Seeding));
                }
                else if (Manager.Bitfield.CountTrue(Manager.PartialProgressSelector) < Manager.PartialProgressSelector.TrueCount && state == TorrentState.Seeding)
                {
                    state = TorrentState.Seeding;
                    Manager.RaiseTorrentStateChanged(new TorrentStateChangedEventArgs(Manager, TorrentState.Downloading, TorrentState.Seeding));
                }
            }
        }
Пример #2
0
        private static ConsoleColor StateToColor(TorrentState State)
        {
            switch (State)
            {
            case TorrentState.Metadata:
                return(ConsoleColor.Yellow);

            case TorrentState.Hashing:
                return(ConsoleColor.Cyan);

            case TorrentState.Downloading:
                return(ConsoleColor.Green);

            case TorrentState.Seeding:
                return(ConsoleColor.Blue);

            case TorrentState.Stopped:
            case TorrentState.Stopping:
                return(ConsoleColor.Gray);

            case TorrentState.Paused:
                return(ConsoleColor.DarkGray);

            default:
                return(ConsoleColor.Red);
            }
        }
        private void Verify_Click(object sender, RoutedEventArgs e)
        {
            string torrentUrl;

            if (!GameUpdater.HttpGet("http://www.zombies.nu/dayzerotorrent.txt", out torrentUrl))
            {
                InfoPopup popup = new InfoPopup();
                popup.Headline.Content = "An Error occured.";
                popup.Message.Content  = "Could not contact Zombies.nu.\nPlease try again.";
                popup.Owner            = popup.Owner = MainWindow.GetWindow(this.Parent);
                popup.Title            = "Error";
                popup.Show();
                return;
            }
            else
            {
                TorrentState state = TorrentUpdater.CurrentState();
                if (state == TorrentState.Stopped)
                {
                    TorrentUpdater verifier = new TorrentUpdater(torrentUrl); // Sets up launcher to start checking files.
                    verifier.StartTorrents(1);
                }
                FileVerifierPopup popup = new FileVerifierPopup();
                popup.Owner            = MainWindow.GetWindow(this.Parent);
                popup.Headline.Content = "Please Wait";
                popup.Title            = "Please Wait";

                popup.Show();
            }
        }
Пример #4
0
        public DownloadMode(TorrentManager manager, DiskManager diskManager, ConnectionManager connectionManager, EngineSettings settings)
            : base(manager, diskManager, connectionManager, settings)
        {
            manager.HashFails = 0;

            // Ensure the state is correct. We should either be downloading or seeding based on
            // the files whose priority is not set to 'DoNotDownload'.
            if (manager.Complete)
            {
                state = TorrentState.Seeding;
            }
            else
            {
                state = TorrentState.Downloading;

                UpdatePartialProgress();
                if (Manager.PartialProgressSelector.TrueCount > 0)
                {
                    // If some files are marked as DoNotDownload and we have downloaded all downloadable files, mark the torrent as 'seeding'.
                    // Otherwise if we have not downloaded all downloadable files, set the state to Downloading.
                    if (Manager.Bitfield.CountTrue(Manager.PartialProgressSelector) == Manager.PartialProgressSelector.TrueCount && state == TorrentState.Downloading)
                    {
                        state = TorrentState.Seeding;
                    }
                }
            }
        }
Пример #5
0
        internal async Task UpdateSeedingDownloadingState()
        {
            UpdatePartialProgress();

            //If download is fully complete, set state to 'Seeding' and send an announce to the tracker.
            if (Manager.Complete && state == TorrentState.Downloading)
            {
                state = TorrentState.Seeding;
                await Task.WhenAll(
                    Manager.TrackerManager.AnnounceAsync (TorrentEvent.Completed, CancellationToken.None).AsTask(),
                    DiskManager.FlushAsync(Manager)
                    );

                Manager.RaiseTorrentStateChanged(new TorrentStateChangedEventArgs(Manager, TorrentState.Downloading, TorrentState.Seeding));
            }
            else if (Manager.PartialProgressSelector.TrueCount > 0)
            {
                // If some files are marked as DoNotDownload and we have downloaded all downloadable files, mark the torrent as 'seeding'.
                // Otherwise if we have not downloaded all downloadable files, set the state to Downloading.
                if (Manager.Bitfield.CountTrue(Manager.PartialProgressSelector) == Manager.PartialProgressSelector.TrueCount && state == TorrentState.Downloading)
                {
                    state = TorrentState.Seeding;
                    await DiskManager.FlushAsync(Manager);

                    Manager.RaiseTorrentStateChanged(new TorrentStateChangedEventArgs(Manager, TorrentState.Downloading, TorrentState.Seeding));
                }
                else if (Manager.Bitfield.CountTrue(Manager.PartialProgressSelector) < Manager.PartialProgressSelector.TrueCount && state == TorrentState.Seeding)
                {
                    state = TorrentState.Downloading;
                    await DiskManager.FlushAsync(Manager);

                    Manager.RaiseTorrentStateChanged(new TorrentStateChangedEventArgs(Manager, TorrentState.Seeding, TorrentState.Downloading));
                }
            }
        }
Пример #6
0
 private void ChangeState(TorrentState state)
 {
     if (State != state)
     {
         State = state;
         OnStateChanged(state);
     }
 }
Пример #7
0
		public TorrentStorage(string torrentPath, string savePath, TorrentSettings settings, TorrentState state, long uploadedData, long downloadedData)
		{
			this.torrentPath = torrentPath;
			this.savePath = savePath;
			this.settings = settings;
			this.state = state;
			this.uploadedData = uploadedData;
			this.downloadedData = downloadedData;
		}
 private void OnDownloaderStateChanged(NDesk.DBus.ObjectPath path, TorrentState from, TorrentState to)
 {
     if (downloader.GetState() == TorrentState.Seeding)
     {
         SetProgress(100);
         SetStatus(TaskStatus.Succeeded);
         OnTaskCompleted(null, false);
     }
 }
Пример #9
0
 public TorrentStorage(string torrentPath, string savePath, TorrentSettings settings, TorrentState state, long uploadedData, long downloadedData)
 {
     this.torrentPath    = torrentPath;
     this.savePath       = savePath;
     this.settings       = settings;
     this.state          = state;
     this.uploadedData   = uploadedData;
     this.downloadedData = downloadedData;
 }
Пример #10
0
        private void OnStateChanged(TorrentState e)
        {
            EventHandler <EventArgs <TorrentState> > handler = StateChanged;

            if (handler != null)
            {
                handler(this, new EventArgs <TorrentState>(e));
            }
        }
Пример #11
0
        public DownloadMode(TorrentManager manager, DiskManager diskManager, ConnectionManager connectionManager, EngineSettings settings)
            : base(manager, diskManager, connectionManager, settings)
        {
            manager.HashFails = 0;

            // Ensure the state is correct. We should either be downloading or seeding based on
            // the files whose priority is not set to 'DoNotDownload'.
            state = manager.Complete ? TorrentState.Seeding : TorrentState.Downloading;
            UpdateSeedingDownloadingState();
        }
Пример #12
0
        //-------------------------------------------------------------
        public SuggestedGameControl(DTO_Suggestion dto, KobberLan parent)
        //-------------------------------------------------------------
        {
            //Init control
            InitializeComponent();

            finishedDownloaded = false;
            kobberLan          = parent;
            dto_suggestion     = dto;
            Likes = new List <IPAddress>();
            label_GameTitle.Text   = dto.title;
            pictureBox_Cover.Image = dto.imageCover;
            state = TorrentState.Starting;

            if (dto.torrent == null)
            {
                button_Get.Enabled = false;
                button_Get.Visible = false;
            }
            else //Internet suggestion
            {
                button_Get.Enabled = true;
                button_Get.Visible = true;
            }

            //Set mouseover tooltip
            CustomToolTip tip = new CustomToolTip(dto, this);

            tip.InitImage(dto.imageBig);
            tip.SetToolTip(pictureBox_Cover, "Details");

            //-------------------------------------------------------------
            //Check for startup value
            //-------------------------------------------------------------
            if (!(string.IsNullOrEmpty(dto.startGame) && string.IsNullOrEmpty(dto.startServer)))
            {
                button_Play.Visible = true;
                button_Play.Enabled = false;

                //-------------------------------------------------------------
                //Check if player already got the game
                //-------------------------------------------------------------
                var path = Helper.GetDirection();
                if (Directory.Exists(path + "\\" + dto_suggestion.key))
                {
                    button_Play.Enabled = true;
                }
            }

            //Show popup notification about the new game
            kobberLan.Invoke(new Action(() =>
            {
                kobberLan.ShowBallonTip("Kobberlan game suggested", "Game: " + dto_suggestion.title);
            }));
        }
Пример #13
0
        public static Task WaitForState(this TorrentManager manager, TorrentState state)
        {
            var tcs = new TaskCompletionSource <object> ();

            manager.TorrentStateChanged += (o, e) => {
                if (e.NewState == state)
                {
                    tcs.TrySetResult(null);
                }
            };

            return(tcs.Task);
        }
Пример #14
0
 public override void Tick(int counter)
 {
     //If download is complete, set state to 'Seeding'
     if (Manager.Complete && state == TorrentState.Downloading)
     {
         state = TorrentState.Seeding;
         Manager.RaiseTorrentStateChanged(new TorrentStateChangedEventArgs(Manager, TorrentState.Downloading, TorrentState.Seeding));
         Manager.TrackerManager.Announce(TorrentEvent.Completed);
     }
     for (int i = 0; i < Manager.Peers.ConnectedPeers.Count; i++)
         if (!ShouldConnect(Manager.Peers.ConnectedPeers[i]))
             Manager.Peers.ConnectedPeers[i].CloseConnection();
     base.Tick(counter);
 }
Пример #15
0
 public override void Tick(int counter)
 {
     //If download is complete, set state to 'Seeding'
     if (Manager.Complete && state == TorrentState.Downloading)
     {
         state = TorrentState.Seeding;
         Manager.RaiseTorrentStateChanged(new TorrentStateChangedEventArgs(Manager, TorrentState.Downloading,
             TorrentState.Seeding));
         Manager.TrackerManager.Announce(TorrentEvent.Completed);
     }
     foreach (var t in Manager.Peers.ConnectedPeers.Where(t => !ShouldConnect(t)))
         t.CloseConnection();
     base.Tick(counter);
 }
Пример #16
0
 public override void Tick(int counter)
 {
     //If download is complete, set state to 'Seeding'
     if (Manager.Complete && state == TorrentState.Downloading)
     {
         state = TorrentState.Seeding;
         Manager.RaiseTorrentStateChanged(new TorrentStateChangedEventArgs(Manager, TorrentState.Downloading, TorrentState.Seeding));
         Manager.TrackerManager.Announce(TorrentEvent.Completed);
     }
     //for (int i = 0; i < Manager.Peers.ConnectedPeers.Count; i++)
     //    if (!ShouldConnect(Manager.Peers.ConnectedPeers[i]))
     //        Manager.Peers.ConnectedPeers[i].CloseConnection();
     base.Tick(counter);
 }
        public static Task WaitForState(this TorrentManager manager, TorrentState state)
        {
            var tcs          = new TaskCompletionSource <object> ();
            var cancellation = new CancellationTokenSource(Timeout);
            var token        = cancellation.Token.Register(() => tcs.TrySetCanceled());

            manager.TorrentStateChanged += (o, e) => {
                if (e.NewState == state)
                {
                    token.Dispose();
                    tcs.TrySetResult(null);
                }
            };

            return(tcs.Task);
        }
Пример #18
0
 public override void Tick(int counter)
 {
     //If download is complete, set state to 'Seeding'
     if (Manager.Complete && state == TorrentState.Downloading)
     {
         state = TorrentState.Seeding;
         Manager.RaiseTorrentStateChanged(new TorrentStateChangedEventArgs(Manager, TorrentState.Downloading,
                                                                           TorrentState.Seeding));
         Manager.TrackerManager.Announce(TorrentEvent.Completed);
     }
     foreach (var t in Manager.Peers.ConnectedPeers.Where(t => !ShouldConnect(t)))
     {
         t.CloseConnection();
     }
     base.Tick(counter);
 }
Пример #19
0
        //-------------------------------------------------------------
        public SuggestedGameOwnerControl(DTO_Suggestion dto, string pathHDD, KobberLan parent, bool ownSuggestions = false)
        //-------------------------------------------------------------
        {
            //Init control
            InitializeComponent();

            torrentPeers = new List <string>();
            torrentPeers.Add("127.0.0.1"); // Inclusive owner
            torrentDownloadCompleted = new List <string>();
            torrentDownloadStarted   = new List <string>();

            ingame                 = new List <string>();
            metaProgress           = 0;
            state                  = TorrentState.Starting;
            kobberLan              = parent;
            path                   = pathHDD;
            dto_suggestion         = dto;
            Likes                  = new List <IPAddress>();
            label_GameTitle.Text   = dto.title;
            pictureBox_Cover.Image = dto.imageCover;

            //Set mouseover tooltip
            CustomToolTip tip = new CustomToolTip(dto, this);

            tip.InitImage(dto.imageBig);
            tip.SetToolTip(pictureBox_Cover, "Details");
            torrentShared = false;

            //Check for startup value
            if (!(string.IsNullOrEmpty(dto.startGame) && string.IsNullOrEmpty(dto.startServer)))
            {
                button_Play.Enabled = true;
            }

            //Hide peers/downloads/remove if not own suggestions
            this.ownSuggestions = ownSuggestions;
            if (!ownSuggestions)
            {
                pictureBox_Downloaded.Visible = false;
                pictureBox_Peers.Visible      = false;
                label_Downloading.Visible     = false;
                label_Peers.Visible           = false;
                button_Clear.Visible          = false;
            }
        }
Пример #20
0
        public TorrentManagerSave(TorrentManager manager)
        {
            state = manager.State;

            if (manager.State != TorrentState.Hashing && manager.HasMetadata)
            {
                resume = manager.SaveFastResume().Encode().Encode();
            }

            downloading = new SerializableDictionary <string, bool>();
            if (manager.Torrent != null)
            {
                foreach (var file in manager.Torrent.Files)
                {
                    downloading.Add(file.Path, file.Priority != Priority.DoNotDownload);
                }
            }
        }
Пример #21
0
 public override void Tick(int counter)
 {
     //If download is complete, set state to 'Seeding'
     if (Manager.Complete && state == TorrentState.Downloading)
     {
         state = TorrentState.Seeding;
         Manager.RaiseTorrentStateChanged(new TorrentStateChangedEventArgs(Manager, TorrentState.Downloading, TorrentState.Seeding));
         _ = Manager.TrackerManager.Announce(TorrentEvent.Completed);
     }
     for (int i = 0; i < Manager.Peers.ConnectedPeers.Count; i++)
     {
         if (!ShouldConnect(Manager.Peers.ConnectedPeers[i]))
         {
             Manager.Engine.ConnectionManager.CleanupSocket(Manager.Peers.ConnectedPeers[i]);
             i--;
         }
     }
     base.Tick(counter);
 }
Пример #22
0
        public static async Task WaitForState(this TorrentManager manager, TorrentState state)
        {
            await ClientEngine.MainLoop;

            if (manager.State == state)
            {
                return;
            }

            var tcs          = new TaskCompletionSource <object> ();
            var cancellation = new CancellationTokenSource(Timeout);
            var token        = cancellation.Token.Register(() => tcs.TrySetCanceled());

            manager.TorrentStateChanged += (o, e) => {
                if (e.NewState == state)
                {
                    token.Dispose();
                    tcs.TrySetResult(null);
                }
            };

            await tcs.Task;
        }
Пример #23
0
 public DownloadMode(TorrentManager manager)
     : base(manager)
 {
     state = manager.Complete ? TorrentState.Seeding : TorrentState.Downloading;
 }
Пример #24
0
 private void ChangeState(TorrentState state)
 {
     if (State != state)
     {
         State = state;
         OnStateChanged(state);
     }
 }
 /// <summary>
 /// Creates a new TorrentStateChangedEventArgs
 /// </summary>
 /// <param name="manager">The <see cref="TorrentManager"/> whose state has changed.</param>
 /// <param name="oldState">The old state of the Torrent</param>
 /// <param name="newState">The new state of the Torrent</param>
 internal TorrentStateChangedEventArgs(TorrentManager manager, TorrentState oldState, TorrentState newState)
     : base(manager)
 {
     OldState = oldState;
     NewState = newState;
 }
Пример #26
0
        //-------------------------------------------------------------

        //-------------------------------------------------------------
        public abstract void UpdateProgressBar(TorrentState type, int progress);
Пример #27
0
 private void OnStateChanged(TorrentState e)
 {
     EventHandler<EventArgs<TorrentState>> handler = StateChanged;
     if(handler != null) handler(this, new EventArgs<TorrentState>(e));
 }
        private void StartEngine(int maxUpload)
        {
            int     port    = 54321;
            Torrent torrent = null;
            // Create the settings which the engine will use
            // downloadsPath - this is the path where we will save all the files to
            // port - this is the port we listen for connections on
            EngineSettings engineSettings = new EngineSettings(downloadsPath, port);

            engineSettings.PreferEncryption  = true;
            engineSettings.AllowedEncryption = EncryptionTypes.RC4Full | EncryptionTypes.RC4Header;

            // Create the default settings which a torrent will have.
            // 4 Upload slots - a good ratio is one slot per 5kB of upload speed
            // 50 open connections - should never really need to be changed
            // Unlimited download speed - valid range from 0 -> int.Max
            // Unlimited upload speed - valid range from 0 -> int.Max
            TorrentSettings torrentDefaults = new TorrentSettings(100, 150, 0, maxUpload);

            // Create an instance of the engine.
            engine = new ClientEngine(engineSettings);
            engine.ChangeListenEndpoint(new IPEndPoint(IPAddress.Any, port));
            byte[] nodes = null;
            try
            {
                nodes = File.ReadAllBytes(dhtNodeFile);
            }
            catch
            {
                Console.WriteLine("No existing dht nodes could be loaded");
            }

            DhtListener dhtListner = new DhtListener(new IPEndPoint(IPAddress.Any, port));
            DhtEngine   dht        = new DhtEngine(dhtListner);

            engine.RegisterDht(dht);
            dhtListner.Start();
            engine.DhtEngine.Start(nodes);

            // If the SavePath does not exist, we want to create it.
            if (!Directory.Exists(engine.Settings.SavePath))
            {
                Directory.CreateDirectory(engine.Settings.SavePath);
            }

            // If the torrentsPath does not exist, we want to create it
            if (!Directory.Exists(torrentsPath))
            {
                Directory.CreateDirectory(torrentsPath);
            }

            BEncodedDictionary fastResume;

            try
            {
                fastResume = BEncodedValue.Decode <BEncodedDictionary>(File.ReadAllBytes(fastResumeFile));
            }
            catch
            {
                fastResume = new BEncodedDictionary();
            }

            // For each file in the torrents path that is a .torrent file, load it into the engine.
            foreach (string file in Directory.GetFiles(torrentsPath))
            {
                if (file.EndsWith(".torrent"))
                {
                    try
                    {
                        // Load the .torrent from the file into a Torrent instance
                        // You can use this to do preprocessing should you need to
                        torrent = Torrent.Load(file);
                        RemoveReadOnly(torrent);
                    }
                    catch (Exception e)
                    {
                        Console.Write("Couldn't decode {0}: ", file);
                        Console.WriteLine(e.Message);
                        continue;
                    }
                    // When any preprocessing has been completed, you create a TorrentManager
                    // which you then register with the engine.
                    TorrentManager manager = new TorrentManager(torrent, downloadsPath, torrentDefaults);
                    //if (fastResume.ContainsKey(torrent.InfoHash.ToHex()))
                    //    manager.LoadFastResume(new FastResume((BEncodedDictionary)fastResume[torrent.InfoHash.ToHex()]));
                    engine.Register(manager);

                    // Store the torrent manager in our list so we can access it later
                    torrents.Add(manager);
                    manager.PeersFound += new EventHandler <PeersAddedEventArgs>(manager_PeersFound);
                }
            }

            // If we loaded no torrents, just exist. The user can put files in the torrents directory and start
            // the client again
            if (torrents.Count == 0)
            {
                Console.WriteLine("No torrents found in the Torrents directory");
                Console.WriteLine("Exiting...");
                engine.Dispose();
                return;
            }

            // For each torrent manager we loaded and stored in our list, hook into the events
            // in the torrent manager and start the engine.
            foreach (TorrentManager manager in torrents)
            {
                // Every time a piece is hashed, this is fired.
                manager.PieceHashed += delegate(object o, PieceHashedEventArgs e)
                {
                };

                // Every time the state changes (Stopped -> Seeding -> Downloading -> Hashing) this is fired
                manager.TorrentStateChanged += OnTorrentStateChanged;

                // Every time the tracker's state changes, this is fired
                foreach (TrackerTier tier in manager.TrackerManager)
                {
                }
                // Start the torrentmanager. The file will then hash (if required) and begin downloading/seeding
                manager.Start();
            }

            // While the torrents are still running, print out some stats to the screen.
            // Details for all the loaded torrent managers are shown.
            int           i            = 0;
            bool          running      = true;
            StringBuilder sb           = new StringBuilder(1024);
            DateTime      lastAnnounce = DateTime.Now;
            bool          firstRun     = true;

            while (running)
            {
                if (firstRun || lastAnnounce < DateTime.Now.AddMinutes(-1))
                {
                    foreach (TorrentManager tm in torrents)
                    {
                        tm.TrackerManager.Announce();
                    }
                    lastAnnounce = DateTime.Now;
                    firstRun     = false;
                }
                if ((i++) % 10 == 0)
                {
                    sb.Remove(0, sb.Length);
                    running = torrents.Exists(delegate(TorrentManager m) { return(m.State != TorrentState.Stopped); });

                    TorrentState totalState = torrents.Exists(m => m.State == TorrentState.Hashing) ? TorrentState.Hashing : torrents.Exists(m => m.State == TorrentState.Downloading) ? TorrentState.Downloading : TorrentState.Seeding;

                    string status = "";
                    switch (totalState)
                    {
                    case TorrentState.Hashing:
                        double totalHashProgress = 0;
                        foreach (TorrentManager m in torrents)
                        {
                            totalHashProgress += (m.State == TorrentState.Hashing) ? m.Progress : 100;
                        }
                        totalHashProgress = totalHashProgress / torrents.Count;
                        status            = String.Format("Checking files ({0:0.00}%)", totalHashProgress);
                        break;

                    case TorrentState.Seeding:
                        status = "";
                        break;

                    default:
                        double totalDownloadProgress = 0;
                        double totalDownloaded       = 0;
                        double totalToDownload       = 0;
                        double totalDownloadSpeed    = 0;
                        long   totalDownloadSize     = 0;
                        foreach (TorrentManager m in torrents)
                        {
                            totalDownloadSize += m.Torrent.Size;
                        }

                        foreach (TorrentManager m in torrents)
                        {
                            totalDownloaded    += m.Torrent.Size / 1024 * (m.Progress / 100);
                            totalToDownload    += m.Torrent.Size / 1024;
                            totalDownloadSpeed += m.Monitor.DownloadSpeed;
                        }
                        totalDownloadProgress = (totalDownloaded / totalToDownload) * 100;
                        status  = "Status: " + (torrents.Exists(m => m.State == TorrentState.Downloading && m.GetPeers().Count > 0) ? "Downloading" : "Finding peers");
                        status += "\n" + String.Format("Progress: {0:0.00}%", totalDownloadProgress);
                        status += "\n" + String.Format("D/L Speed: {0:0.00} kB/s", totalDownloadSpeed / 1024.0);
                        break;
                    }
                    if (installer != null)
                    {
                        installer.Status = status;
                    }

                    #region OLDPROGRESS
                    //foreach (TorrentManager manager in torrents)
                    //{
                    //    AppendSeperator(sb);
                    //    AppendFormat(sb, "State:           {0}", manager.State);
                    //    AppendFormat(sb, "Name:            {0}", manager.Torrent == null ? "MetaDataMode" : manager.Torrent.Name);
                    //    AppendFormat(sb, "Progress:           {0:0.00}", manager.Progress);
                    //    string status = "";
                    //    switch (manager.State)
                    //    {
                    //        case TorrentState.Hashing:
                    //            status = String.Format("Checking files ({0:0.00}%)", manager.Progress);
                    //            break;
                    //        case TorrentState.Seeding: status = ""; break;
                    //        default:
                    //            status = "Status: " + (manager.GetPeers().Count == 0 ? "Finding Peers" : "Downloading");
                    //            status += "\n" + String.Format("Progress: {0:0.00}%", manager.Progress);
                    //            status += "\n" + String.Format("D/L Speed: {0:0.00} kB/s", manager.Monitor.DownloadSpeed / 1024.0);
                    //            break;
                    //    }
                    //    if (installer != null)
                    //        installer.Status = status;
                    //    AppendFormat(sb, "Download Speed:     {0:0.00} kB/s", manager.Monitor.DownloadSpeed / 1024.0);
                    //    AppendFormat(sb, "Upload Speed:       {0:0.00} kB/s", manager.Monitor.UploadSpeed / 1024.0);
                    //    AppendFormat(sb, "Total Downloaded:   {0:0.00} MB", manager.Monitor.DataBytesDownloaded / (1024.0 * 1024.0));
                    //    AppendFormat(sb, "Total Uploaded:     {0:0.00} MB", manager.Monitor.DataBytesUploaded / (1024.0 * 1024.0));
                    //    MonoTorrent.Client.Tracker.Tracker tracker = manager.TrackerManager.CurrentTracker;
                    //    AppendFormat(sb, "Tracker Status:     {0}", tracker == null ? "<no tracker>" : tracker.Status.ToString());
                    //    AppendFormat(sb, "Warning Message:    {0}", tracker == null ? "<no tracker>" : tracker.WarningMessage);
                    //    AppendFormat(sb, "Failure Message:    {0}", tracker == null ? "<no tracker>" : tracker.FailureMessage);
                    //}
                    ////Console.Clear();
                    //Console.WriteLine(sb.ToString());
                    #endregion
                }

                System.Threading.Thread.Sleep(500);
            }
        }
Пример #29
0
        //-------------------------------------------------------------
        public override void UpdateProgressBar(TorrentState type, int progress)
        //-------------------------------------------------------------
        {
            if (type == TorrentState.Stopped)
            {
                progressBar.Visible      = false;
                label_ProgresBar.Visible = false;
            }
            //Hide when starting to seed
            else if (type == TorrentState.Seeding)
            {
                //Hide progress info
                progressBar.Enabled      = false;
                progressBar.Visible      = false;
                label_ProgresBar.Visible = false;

                //Stop sharing enabled
                button_ShareGet.Enabled = true;

                //-------------------------------------------------------------
                //Allow clients to download
                //-------------------------------------------------------------
                if (torrentShared == false)
                {
                    torrentShared = true;
                    kobberLan.SendTorrent(torrent);
                }
            }
            else if (type == TorrentState.Metadata)
            {
                //Creating torrent file
                label_ProgresBar.Text    = "Creating torrent data";
                progressBar.Visible      = true;
                label_ProgresBar.Visible = true;

                //Prevent bar totalcompleted jumping around
                if (metaProgress < progress)
                {
                    metaProgress = progress;
                }
                progressBar.Value = metaProgress;
            }
            else if (state == type)
            {
                progressBar.Value        = progress;
                progressBar.Visible      = true;
                label_ProgresBar.Visible = true;
                label_ProgresBar.Text    = type.ToString() + " " + progress.ToString("D2") + "%";
                label_ProgresBar.Refresh();
            }
            else if (type == TorrentState.Downloading)
            {
                Log.Get().Write("Game " + GetTitle() + " is downloading in OwnerControl? Maybe incomplete?", Log.LogType.Warning);

                /*
                 * progressBar.Visible = false;
                 * label_ProgresBar.Visible = true;
                 * label_ProgresBar.Text = "Incomplete, please delete .torrent file";
                 * label_ProgresBar.Refresh();
                 *
                 * button_ShareGet.Enabled = false;
                 * Torrent.Get().StopSharing(dto_suggestion.key);
                 * button_Clear.Enabled = true;
                 */
            }
            else if (type == TorrentState.Error)
            {
                progressBar.Visible      = false;
                label_ProgresBar.Visible = true;
                label_ProgresBar.Text    = "Torrent error";
                label_ProgresBar.Refresh();

                Log.Get().Write("Game " + GetTitle() + " could not be shared, unknown error.", Log.LogType.Error);
                Torrent.Get().StopSharing(dto_suggestion.key);
            }
            else
            {
                progressBar.Value = 0;
                state             = type;
            }
        }
Пример #30
0
 private void OnStateChanged(TorrentState e)
 {
     StateChanged?.Invoke(this, new EventArgs <TorrentState>(e));
 }
Пример #31
0
 /// <summary>
 /// Creates a new TorrentStateChangedEventArgs
 /// </summary>
 /// <param name="oldState">The old state of the Torrent</param>
 /// <param name="newState">The new state of the Torrent</param>
 public TorrentStateChangedEventArgs(TorrentManager manager, TorrentState oldState, TorrentState newState)
     : base(manager)
 {
     this.oldState = oldState;
     this.newState = newState;
 }
Пример #32
0
 public DownloadMode(TorrentManager manager)
     : base(manager)
 {
     manager.HashFails = 0;
     state             = manager.Complete ? TorrentState.Seeding : TorrentState.Downloading;
 }
 /// <summary>
 ///     Creates a new TorrentStateChangedEventArgs
 /// </summary>
 /// <param name="oldState">The old state of the Torrent</param>
 /// <param name="newState">The new state of the Torrent</param>
 public TorrentStateChangedEventArgs(TorrentManager manager, TorrentState oldState, TorrentState newState)
     : base(manager)
 {
     this.oldState = oldState;
     this.newState = newState;
 }
        //-------------------------------------------------------------

        //-------------------------------------------------------------
        public override void UpdateProgressBar(TorrentState type, int progress)
        {
        }
Пример #35
0
 public DownloadMode(TorrentManager manager, DiskManager diskManager, ConnectionManager connectionManager, EngineSettings settings)
     : base(manager, diskManager, connectionManager, settings)
 {
     manager.HashFails = 0;
     state             = manager.Complete ? TorrentState.Seeding : TorrentState.Downloading;
 }
 private void OnDownloaderStateChanged (NDesk.DBus.ObjectPath path, TorrentState from, TorrentState to)
 {
     if (downloader.GetState () == TorrentState.Seeding) {
         SetProgress (100);
         SetStatus (TaskStatus.Succeeded);
         OnTaskCompleted (null, false);
     }
 }
Пример #37
0
        //-------------------------------------------------------------
        public override void UpdateProgressBar(TorrentState type, int progress)
        //-------------------------------------------------------------
        {
            if (type == TorrentState.Stopped ||
                type == TorrentState.Stopping)
            {
                progressBar.Visible       = false;
                label_ProgressBar.Visible = false;
                button_Play.Enabled       = true;
                Log.Get().Write("Torrent: " + dto_suggestion.key + " state: " + type.ToString());
            }
            else if (type == TorrentState.Seeding)
            {
                progressBar.Visible       = false;
                label_ProgressBar.Visible = false;

                //-------------------------------------------------------------
                //Note host about finished download
                //-------------------------------------------------------------
                if (finishedDownloaded == false)
                {
                    finishedDownloaded = true;
                    DTO_TorrentStatus torrentStatus = new DTO_TorrentStatus()
                    {
                        key = dto_suggestion.key, address = Helper.GetHostIP(), status = TorrentStatusType.Finished
                    };
                    kobberLan.SendTorrentStatus(torrentStatus, dto_suggestion.author);
                }

                //-------------------------------------------------------------
                //Enable stop button
                //-------------------------------------------------------------
                if (button_Play.Enabled == false) //Ignore seeding message, when stop has been called
                {
                    button_Get.Enabled = true;
                    button_Get.Text    = "Stop";
                }
            }
            else if (type == TorrentState.Error)
            {
                progressBar.Visible       = false;
                label_ProgressBar.Visible = true;
                label_ProgressBar.Text    = "Torrent error";
                label_ProgressBar.Refresh();

                Log.Get().Write("Game " + GetTitle() + " got unknown error.", Log.LogType.Error);
                Torrent.Get().StopSharing(dto_suggestion.key);
            }
            else //Download
            {
                progressBar.Enabled       = true;
                progressBar.Visible       = true;
                label_ProgressBar.Visible = true;

                if (type == TorrentState.Hashing && state == TorrentState.Downloading) //Ignore hash check for every files progress (Make progress bar jump strangely)
                {
                    return;
                }
                else if (type == TorrentState.Hashing)
                {
                    state = TorrentState.Hashing;
                    label_ProgressBar.Text = "Hashing: " + progress.ToString("D2") + "%";
                }
                else if (type == TorrentState.Downloading && progress > 0)
                {
                    state = TorrentState.Downloading;
                    label_ProgressBar.Text = "Downloading: " + progress.ToString("D2") + "%";
                }
                else
                {
                    label_ProgressBar.Text = type.ToString();
                }

                progressBar.Value = progress;
                label_ProgressBar.Refresh();
            }
        }
        protected void TorrentStatusUpdate(TorrentState newState, double newProgress)
        {
            UpperProgressValue = (int) (newProgress*100.0);

            if (newState == TorrentState.Hashing)
                UpperProgressText = "Verifying...";
            else if (newState == TorrentState.Downloading)
                UpperProgressText = "Downloading...";
            else if (newState == TorrentState.Seeding || newState == TorrentState.Stopped)
            {
                TorrentUpdater.StatusCallbacks -= TorrentStatusUpdate;
                GetInstallersMeta();
            }
        }