示例#1
0
 void statusStripUpdate(object sender, TorrentStatusUpdateEventArgs e)
 {
     if (this.statusStrip1.InvokeRequired)
     {
         statusStripHandler d = new statusStripHandler(statusStripUpdate);
         this.statusStrip1.Invoke(d, new object[] { sender, e });
     }
     else
     {
         string text = e.notifyMessage;
         if (this.updateInProgress)
         {
             text = "Update in progress...";
         }
         else
         {
             if (this.torrentUser.engineState == EngineState.Paused)
             {
                 text = "";
             }
             else if ((e.Leeches == 0) || (text.Contains("Connections")))
             {
                 text = "Waiting for peers...";
             }
             else if (e.Leeches == 1)
             {
                 text = text.Replace("eers", "eer");
             }
         }
         this.toolStripStatusLabel1.Text = text;
         this.notifyIcon1.Text           = text;
     }
 }
示例#2
0
 void torrentUser_StatusUpdate(object sender, TorrentStatusUpdateEventArgs e)
 {
     if (this.torrentUser.engineState == EngineState.Downloading)
     {
         this.notifyIcon1.Text = e.notifyMessage;
     }
 }
 private void UpdateStatus(TorrentStatusUpdateEventArgs e)
 {
     if (this.StatusUpdate == null)
     {
         return;
     }
     StatusUpdate(this, e);
 }
示例#4
0
 void torrentUser_StatusUpdate(TorrentUser sender, TorrentStatusUpdateEventArgs e)
 {
     if (sender.engineState != EngineState.Seeding)
     {
         return;
     }
     QuietSeedInfo(this, new QuietSeedEventArgs(e.infoMessage, e.notifyMessage));
 }
 private void UpdateFinished(TorrentStatusUpdateEventArgs e)
 {
     this.lastTimeMessage = "";
     if (this.TorrentDownloadCompleted == null)
     {
         return;
     }
     TorrentDownloadCompleted(this, e);
 }
示例#6
0
 void torrentUser_TorrentDownloadCompleted(object sender, TorrentStatusUpdateEventArgs e)
 {
     setTorrentInfo(e);
     if (!this.parent.updateInProgress)
     {
         return;
     }
     try
     {
         this.Invoke((MethodInvoker) delegate
         {
             if (this.changeLogs.Count == 0)
             {
                 MessageBox.Show(this, "Update Completed.", "Success");
             }
             else
             {
                 string message            = "Update Completed. Would you like to see\nthe most recent changelogs?";
                 string caption            = "Success";
                 MessageBoxButtons buttons = MessageBoxButtons.YesNo;
                 DialogResult result;
                 result = MessageBox.Show(message, caption, buttons);
                 if (result == System.Windows.Forms.DialogResult.Yes)
                 {
                     foreach (string changelog in this.changeLogs)
                     {
                         DirectoryInfo folder = new DirectoryInfo(Application.StartupPath);
                         folder        = folder.Parent.Parent;
                         string adress = Path.Combine(folder.FullName, changelog);
                         try
                         {
                             System.Diagnostics.Process.Start("notepad.exe", adress);
                         }
                         catch (Exception ex)
                         {
                             Console.WriteLine(ex);
                         }
                     }
                 }
             }
         });
     }
     catch (Exception)
     {
     }
     this.torrentUser.StatusUpdate             -= torrentUser_StatusUpdate;
     this.torrentUser.TorrentDownloadCompleted -= torrentUser_TorrentDownloadCompleted;
     this.parent.updateInProgress = false;
     disposeThis();
     return;
 }
示例#7
0
 private void setTorrentInfo(TorrentStatusUpdateEventArgs e)
 {
     if (this.progressBar1.InvokeRequired)
     {
         setTorrentInfoCallback d = new setTorrentInfoCallback(setTorrentInfo);
         this.Invoke(d, new object[] { e });
     }
     else
     {
         setProgressBar((int)(e.Progress * 100));
         setInfoLabel(e.infoMessage);
         setTimeLabel(e.timeMessage);
     }
 }
        private void waitForFinish(object sender, TorrentStateChangedEventArgs e)
        {
            foreach (TorrentManager manager in this.managers)
            {
                if (!manager.Complete)
                {
                    return;
                }
            }
            this.engineState = EngineState.Paused;
            foreach (TorrentManager manager in this.managers)
            {
                if (manager.State == TorrentState.Stopping)
                {
                    return;
                }
                else if (manager.State == TorrentState.Stopped)
                {
                    manager.TorrentStateChanged -= waitForFinish;
                }
                else
                {
                    manager.Stop();
                    return;
                }
            }
            TorrentStatusUpdateEventArgs args = new TorrentStatusUpdateEventArgs(0, 0, 0, 0, 100, "Update Completed", "Approximately 0 seconds remaining.");

            foreach (TorrentManager manager in this.managers)
            {
                this.engine.Unregister(manager);
            }
            this.managers.Clear();
            this.torrents.Clear();
            this.activeWebSeeds = 0;
            this.engineState    = EngineState.Paused;
            StopDht();
            if (parent.debugMode)
            {
                this.refreshDebugWindow();
            }
            UpdateFinished(args);
        }
示例#9
0
 void torrentUser_StatusUpdate(object sender, TorrentStatusUpdateEventArgs e)
 {
     setTorrentInfo(e);
 }
示例#10
0
        void engine_StatsUpdate(object sender, StatsUpdateEventArgs e)
        {
            if (this.engineState == EngineState.Paused)
            {
                return;
            }
            long   uploadSpeed   = this.engine.TotalUploadSpeed;
            long   downloadSpeed = this.engine.TotalDownloadSpeed;
            int    seeds         = 0;
            int    leeches       = 0;
            int    nPeers        = 0;
            double totalProgress = 0.0;
            string names         = "Torrents: ";

            foreach (TorrentManager manager in this.managers)
            {
                totalProgress = totalProgress + manager.Progress;
                seeds        += manager.Peers.Seeds + this.activeWebSeeds;
                leeches      += manager.Peers.Leechs;
                nPeers       += manager.InactivePeers;
                names        += manager.Torrent.Comment;
                Console.WriteLine(manager.Monitor.DataBytesDownloaded);
                if ((manager.State == TorrentState.Downloading) && (manager.UseWebSeeding == false))
                {
                    manager.UseWebSeeding = true;
                }
            }
            if ((this.engineState == EngineState.Seeding) && (leeches == 0))
            {
                if (this.waitCount != 30)
                {
                    this.waitCount += 1;
                }
                else
                {
                    this.waitCount = 0;
                    this.debug("Announcing to Tracker.");
                    foreach (TorrentManager manager in this.managers)
                    {
                        manager.TrackerManager.Announce();
                    }
                    return;
                }
            }
            if ((this.engineState == EngineState.Downloading) && (seeds == 0))
            {
                seeds += leeches;
            }
            string debugMessage = names + " Inactive Peers: " + nPeers.ToString()
                                  + " Seeds: " + seeds.ToString() + " Peers: " + leeches.ToString()
                                  + " UL: " + uploadSpeed.ToString() + " DL: " + downloadSpeed.ToString() +
                                  " Progress: " + (((totalProgress / (double)this.managers.Count) - 100 * (1 - (double)this.downloadSize / (double)this.totalSize)) * (double)this.totalSize / (double)this.downloadSize).ToString()
                                  + " DLSize: " + this.downloadSize.ToString() + " TotalSize: " + this.totalSize.ToString();

            Console.WriteLine(debugMessage);
            debug(debugMessage);
            if (this.engineState == EngineState.Seeding)
            {
                string seedText;
                if ((leeches == 0) && (uploadSpeed == 0))
                {
                    seedText = "Waiting for peers...";
                }
                else
                {
                    seedText = "Seeding to " + leeches.ToString() + " peers at " + niceSize(uploadSpeed) + "/s";
                }
                TorrentStatusUpdateEventArgs seedArgs = new TorrentStatusUpdateEventArgs((int)uploadSpeed, 0, leeches, 0, 0, seedText, "");
                StatusUpdate(this, seedArgs);
                return;
            }
            double progress = (totalProgress / (double)this.managers.Count);

            progress = (progress - 100 * (1 - (double)this.downloadSize / (double)this.totalSize)) * (double)this.totalSize / (double)this.downloadSize;
            bool   stillHashing = false;
            string hashMessage  = "";

            if (progress < 0)
            {
                stillHashing = true;
                if (this.initialProgress == -999999)
                {
                    this.initialProgress = progress;
                }
                var hashProgress = 1 - progress / this.initialProgress;
                hashMessage = "Hashing existing pieces (" + String.Format("{0:0.#}", (hashProgress * 100)) + "%)";
                progress    = 0;
            }

            long remaining;

            if ((progress > 0.000001) && (downloadSpeed == 0))
            {
                this.initialSize = (long)((100.0 - progress) * (double)this.downloadSize / 100.0);
            }
            remaining = (long)((100.0 - progress) * (double)this.downloadSize / 100.0);
            progress  = Math.Round(progress, 6);

            this.speedSample.Add(downloadSpeed);
            if (this.speedSample.Count > 30)
            {
                this.speedSample.RemoveAt(0);
            }
            double      weight   = 0;
            long        speedSum = 0;
            float       fallOff  = 0;
            int         k        = this.speedSample.Count;
            List <long> speeds   = new List <long>(this.speedSample);

            foreach (long entry in speeds)
            {
                speedSum += (long)((double)entry / Math.Pow(k, fallOff));
                weight   += (1.0 / Math.Pow(k, fallOff));
                k--;
            }
            long avgSpeed = (long)(speedSum / weight);

            if (avgSpeed == 0)
            {
                avgSpeed = 1;
            }
            long timeRemaining = remaining / avgSpeed;
            bool skipTime      = false;

            if (this.lastTime == -10000)
            {
                this.lastTime = timeRemaining;
                skipTime      = true;
            }
            else
            {
                try
                {
                    if ((Math.Abs((this.lastTime - timeRemaining)) > 89) && (timeRemaining > 60))
                    {
                        skipTime = true;
                    }
                }
                catch (OverflowException)
                {
                    return;
                }
            }
            string plural = "";

            if (seeds > 1)
            {
                plural = "s";
            }
            this.lastTime = timeRemaining;
            if ((timeRemaining < 0) || (Math.Abs(timeRemaining) > 100000))
            {
                skipTime = true;
            }

            string infoMessage = "";

            if (this.engineState == EngineState.Paused)
            {
                infoMessage = "Download paused (" + ((int)progress).ToString() + "% of "
                              + niceSize(this.downloadSize) + " completed.)";
            }
            else if ((downloadSpeed == 0) && ((int)progress != 100) && ((int)progress != 0))
            {
                if ((progress == this.lastProgress) && (progress > 0))
                {
                    infoMessage = "Waiting for seeds...";
                }
                else
                {
                    infoMessage = "Resuming previous update...";
                }
                this.lastProgress = progress;
            }
            else if ((downloadSpeed == 0) && ((int)progress == 0))
            {
                if (stillHashing)
                {
                    infoMessage = hashMessage;
                }
                else
                {
                    infoMessage = "Establishing Connections...";
                }
            }
            else
            {
                infoMessage = "Downloading " + niceSize(this.downloadSize)
                              + " from " + seeds.ToString() + " seed" + plural + " at " + niceSize(downloadSpeed)
                              + "/s (" + ((int)progress).ToString() + "% completed)";
            }
            string timeMessage = "";

            if (!skipTime)
            {
                timeMessage          = "Approximately " + niceTime((long)timeRemaining) + " remaining.";
                this.lastTimeMessage = timeMessage;
            }
            else
            {
                timeMessage = this.lastTimeMessage;
            }

            TorrentStatusUpdateEventArgs args = new TorrentStatusUpdateEventArgs((int)uploadSpeed, (int)downloadSpeed, leeches, seeds, progress, infoMessage, timeMessage);

            if (this.engineState != EngineState.Paused)
            {
                UpdateStatus(args);
            }
        }
示例#11
0
 void torrentUser_StatusUpdate(TorrentUser sender, TorrentStatusUpdateEventArgs e)
 {
     statusStripUpdate(sender, e);
 }