예제 #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
        void LoadTorrents()
        {
            string fastResumePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "fastresume", "fr.dat");
            string torrentsPath   = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "fastresume");

            if (File.Exists(fastResumePath))
            {
                BEncodedDictionary fastResume;
                fastResume = BEncodedValue.Decode <BEncodedDictionary>(File.ReadAllBytes(fastResumePath));

                int index = 0;
                foreach (string file in Directory.GetFiles(torrentsPath))
                {
                    if (file.EndsWith(".torrent.dat"))
                    {
                        string[] lines = File.ReadAllLines(file);
                        torrentFiles.Add(new TorrentFile(lines[1], lines[0], new IPEndPoint(IPAddress.Any, 6969), file + ".dht"));
                        if (fastResume.ContainsKey(torrentFiles[index].torrent.InfoHash.ToHex()))
                        {
                            torrentFiles[index].manager.LoadFastResume(new FastResume((BEncodedDictionary)fastResume[torrentFiles[index].torrent.InfoHash.ToHex()]));
                        }
                        GLItem item;
                        item = torrentList.Items.Add(torrentFiles[index].name);
                        FProgressBar fbar = new FProgressBar();
                        fbar.DisplayStyle        = ProgressBarDisplayText.Percentage;
                        item.SubItems[1].Control = fbar;
                        torrentFiles[index].Start();
                        index++;
                        this.Refresh();
                    }
                }
            }
        }
예제 #3
0
        private void torrentList_Click(object sender, EventArgs e)
        {
            if (torrentList.SelectedItems.Count != 0)
            {
                int selectedIndex = torrentList.Items.FindItemIndex((GLItem)torrentList.SelectedItems[0]);
                torrentNameLbl.Text    = "Name: " + torrentFiles[selectedIndex].name;
                torrentSizeLbl.Text    = "Size: " + (Math.Round(torrentFiles[selectedIndex].size / 1048576, 2)).ToString() + "MB";
                torrentCommentLbl.Text = "Comment: " + torrentFiles[selectedIndex].comment;
                torrentPathLbl.Text    = "Path: " + torrentFiles[selectedIndex].path;
                outPathLbl.Text        = "Out path: " + torrentFiles[selectedIndex].savePath;

                torrentBar.Value = (int)torrentFiles[torrentList.Items.FindItemIndex((GLItem)torrentList.SelectedItems[0])].downloadProgress;
                torrentBar.PointToClient(torrentTabs.Location);

                filesList.Items.Clear();

                torrentTabs.Enabled = true;

                foreach (MonoTorrent.Common.TorrentFile file in torrentFiles[selectedIndex].torrent.Files)
                {
                    float        fileLength = (float)Math.Round((double)file.Length / 1048576, 2);
                    float        downloaded = (float)Math.Round((double)file.BytesDownloaded / 1048576, 2);
                    GLItem       gl         = filesList.Items.Add(file.Path);
                    FProgressBar bar        = new FProgressBar();
                    gl.SubItems[1].Control = bar;
                    bar.Value = MathUtils.PercentageOf(downloaded, fileLength);
                }

                filesList.Refresh();

                UpdateSizes();
            }
        }
예제 #4
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();
         }
     }
 }
예제 #5
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);
            }
        }