コード例 #1
0
        private void mainForm_Load(object sender, EventArgs e)
        {
            LoadTorrents();

            if (filesFromArgs != null)
            {
                foreach (string argument in filesFromArgs)
                {
                    if (File.Exists(argument) && argument.EndsWith(".torrent"))
                    {
                        using (addTorrent addTor = new addTorrent(argument))
                        {
                            addTor.ShowDialog();
                            GLItem item;
                            torrentFiles.Add(new TorrentFile(addTor.torrentPath, addTor.savePath, new IPEndPoint(IPAddress.Any, 6969)));
                            item = torrentList.Items.Add(torrentFiles[torrentFiles.Count - 1].name);
                            FProgressBar fbar = new FProgressBar();
                            fbar.DisplayStyle        = ProgressBarDisplayText.Percentage;
                            item.SubItems[1].Control = fbar;
                            torrentFiles[torrentList.Count - 1].Start();
                            torrentList.Refresh();
                        }
                    }
                }
            }
        }
コード例 #2
0
 private void addToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (addTorrent addTor = new addTorrent())
     {
         addTor.ShowDialog();
         if (addTor.savePath != null && addTor.torrentPath != null)
         {
             GLItem item;
             torrentFiles.Add(new TorrentFile(addTor.torrentPath, addTor.savePath, new IPEndPoint(IPAddress.Any, 6969)));
             item = torrentList.Items.Add(torrentFiles[torrentFiles.Count - 1].name);
             FProgressBar fbar = new FProgressBar();
             fbar.DisplayStyle        = ProgressBarDisplayText.Percentage;
             item.SubItems[1].Control = fbar;
             torrentFiles[torrentList.Count - 1].Start();
             torrentList.Refresh();
         }
     }
 }
コード例 #3
0
        void updateTorrents()
        {
            while (true)
            {
                try
                {
                    Invoke((MethodInvoker) delegate()
                    {
                        int index = 0;
                        foreach (TorrentFile file in torrentFiles)
                        {
                            (torrentList.Items[index].SubItems[1].Control as FProgressBar).Value = (int)file.downloadProgress;
                            torrentList.Items[index].SubItems[2].Text = ((int)file.downloadSpeed / 1000).ToString() + "kB/s";
                            torrentList.Items[index].SubItems[3].Text = ((int)file.uploadSpeed / 1000).ToString() + "kB/s";
                            torrentList.Items[index].SubItems[4].Text = (Math.Round(file.size / 1048576, 2)).ToString() + "MB";

                            if (file.torrentState == TorrentState.Downloading)
                            {
                                (torrentList.Items[index].SubItems[1].Control as FProgressBar).ProgressBarColor = Color.YellowGreen;
                                (torrentList.Items[index].SubItems[1].Control as FProgressBar).DisplayStyle     = ProgressBarDisplayText.Percentage;
                            }
                            else if (file.torrentState == TorrentState.Paused)
                            {
                                (torrentList.Items[index].SubItems[1].Control as FProgressBar).ProgressBarColor = Color.Orange;
                                (torrentList.Items[index].SubItems[1].Control as FProgressBar).DisplayStyle     = ProgressBarDisplayText.CustomText;
                                (torrentList.Items[index].SubItems[1].Control as FProgressBar).CustomText       = "Paused";
                            }
                            else if (file.torrentState == TorrentState.Error || file.torrentState == TorrentState.Stopped)
                            {
                                (torrentList.Items[index].SubItems[1].Control as FProgressBar).ProgressBarColor = Color.Red;
                                (torrentList.Items[index].SubItems[1].Control as FProgressBar).DisplayStyle     = ProgressBarDisplayText.CustomText;
                                (torrentList.Items[index].SubItems[1].Control as FProgressBar).CustomText       = "Stopped";
                            }
                            else if (file.torrentState == TorrentState.Seeding)
                            {
                                if (!file.finishNotified)
                                {
                                    file.finishNotified = true;
                                    taskBarIcon.ShowBalloonTip(5000, "Download completed!", file.name + " downloaded successfully.", ToolTipIcon.Info);
                                }
                                (torrentList.Items[index].SubItems[1].Control as FProgressBar).ProgressBarColor = Color.Yellow;
                                (torrentList.Items[index].SubItems[1].Control as FProgressBar).DisplayStyle     = ProgressBarDisplayText.CustomText;
                                (torrentList.Items[index].SubItems[1].Control as FProgressBar).CustomText       = "Seeding...";
                            }

                            TimeSpan timeLeft = TimeSpan.FromSeconds(MathUtils.ETA(file.downloadedBytes, file.downloadSpeed, file.size));
                            torrentList.Items[index].SubItems[5].Text = timeLeft.ToString();
                            index++;
                        }

                        if (torrentList.SelectedItems.Count != 0)
                        {
                            torrentTabs.Enabled = true;
                            filesList.Items.Clear();
                            int selectedIndex = torrentList.Items.FindItemIndex((GLItem)torrentList.SelectedItems[0]);
                            foreach (MonoTorrent.Common.TorrentFile file in torrentFiles[selectedIndex].torrent.Files)
                            {
                                double fileLength      = file.Length;
                                double downloaded      = file.BytesDownloaded;
                                GLItem gl              = filesList.Items.Add(file.Path);
                                FProgressBar bar       = new FProgressBar();
                                gl.SubItems[1].Control = bar;
                                bar.Value              = (int)((double)file.BytesDownloaded / (double)file.Length) * 100;
                            }

                            trackersList.Items.Clear();
                            foreach (TrackerTier tier in torrentFiles[selectedIndex].manager.TrackerManager)
                            {
                                foreach (Tracker t in tier.GetTrackers())
                                {
                                    GLItem item           = trackersList.Items.Add(t.Uri.ToString());
                                    item.SubItems[1].Text = t.Status.ToString();
                                }
                            }

                            try
                            {
                                peersList.Items.Clear();
                                foreach (PeerId p in torrentFiles[selectedIndex].manager.GetPeers())
                                {
                                    GLItem item           = peersList.Items.Add(p.Connection.Uri.ToString());
                                    item.SubItems[1].Text = ((int)p.Monitor.DownloadSpeed / 1024).ToString() + "kB/s";
                                    item.SubItems[2].Text = ((int)p.Monitor.UploadSpeed / 1024).ToString() + "kB/s";
                                }
                            }
                            catch { }

                            speedCounter.Series[0].Points.Add(torrentFiles[selectedIndex].manager.Monitor.DownloadSpeed / 1024);
                            speedCounter.Series[1].Points.Add(torrentFiles[selectedIndex].manager.Monitor.UploadSpeed / 1024);
                        }
                        else
                        {
                            torrentTabs.Enabled = false;
                        }

                        if (Args.args != null)
                        {
                            foreach (string argument in Args.args)
                            {
                                if (File.Exists(argument) && argument.EndsWith(".torrent"))
                                {
                                    using (addTorrent addTor = new addTorrent(argument))
                                    {
                                        addTor.ShowDialog();
                                        GLItem item;
                                        torrentFiles.Add(new TorrentFile(addTor.torrentPath, addTor.savePath, new IPEndPoint(IPAddress.Any, 6969)));
                                        item = torrentList.Items.Add(torrentFiles[torrentFiles.Count - 1].name);
                                        FProgressBar fbar        = new FProgressBar();
                                        fbar.DisplayStyle        = ProgressBarDisplayText.Percentage;
                                        item.SubItems[1].Control = fbar;
                                        torrentFiles[torrentList.Count - 1].Start();
                                        torrentList.Refresh();
                                    }
                                }
                            }
                            Args.args = null;
                        }
                        Refresh();
                    });
                }
                catch { }
                Thread.Sleep(1000);
            }
        }