Beispiel #1
0
    private void TimerEventOneSecond(Object myObject, EventArgs myEventArgs)
    {
        if (State != BtmState.Running)
        {
            return;
        }

        DllInterface.TorrentHandles handles = new DllInterface.TorrentHandles();
        DllInterface.GetAllTorrentHandles(ref handles);


        for (Int32 i = 0; i < handles.mNumHandles; i++)
        {
            TorrentHandle handle = handles.mHandles[i];


            // THREADING ISSUE???!!?!??!?!

            DllInterface.TorrentMetaData meta = new DllInterface.TorrentMetaData();
            DllInterface.GetTorrentMetaData(handle, ref meta);

            Torrent torrent = GetTorrent(handle);
            if (torrent != null)
            {
                torrent.MetaData = meta;
            }
        }
    }
Beispiel #2
0
    }// END RefreshListView

    public void RefreshGeneralTabPage(int torrentId, DllInterface.TorrentMetaData meta)
    {
        float totalFilesSize      = ((float)meta.mTotalPieces * (float)meta.mPieceSize) / (1024.0f * 1024.0f);
        float totalHaveSize       = ((float)meta.mPiecesDownloaded * (float)meta.mPieceSize) / (1024.0f * 1024.0f);
        float onePercentOfTorrent = totalFilesSize / 100.0f;

        mGeneralTabLabelShareRatio.Text = String.Format("{0:0.00}", totalHaveSize / onePercentOfTorrent / 100.0f);


        // remaining
        if (meta.mDownloadSpeed == 0)
        {
            char chInfinity = (char)0x221E;
            mGeneralTabLabelRemaining.Text = String.Format("{0}", chInfinity);
        }
        else
        {
            UInt32 hoursRemaining   = (UInt32)(meta.mEta / (60 * 60));
            UInt32 minutesRemaining = (UInt32)((meta.mEta - (hoursRemaining * (60 * 60))) / 60);
            UInt32 secondsRemaining = (UInt32)((meta.mEta - (hoursRemaining * (60 * 60))) - (minutesRemaining * 60));
            mGeneralTabLabelRemaining.Text = String.Format("{0:0}h {1:00}m", hoursRemaining, minutesRemaining);
        }


        // time elapsed
        UInt32 hoursRunning   = (UInt32)(meta.mTimeSinceStarted / (60 * 60));
        UInt32 minutesRunning = (UInt32)((meta.mTimeSinceStarted - (hoursRunning * (60 * 60))) / 60);
        UInt32 secondsRunning = (UInt32)((meta.mTimeSinceStarted - (hoursRunning * (60 * 60))) - (minutesRunning * 60));

        mGeneralTabLabelTimeElapsed.Text = String.Format("{0:0}h {1:00}m", hoursRunning, minutesRunning);          //"1h 31m 22s";


        mGeneralTabLabelDownloaded.Text = String.Format("{0:0.00} MB", totalHaveSize);
        mGeneralTabLabelLocalName.Text  = meta.mFileName;

        DateTime unixEpoch = new DateTime(1970, 1, 1);

        unixEpoch = unixEpoch.AddSeconds(meta.mCreationDate);
        mGeneralTabLabelCreatedOn.Text = unixEpoch.ToString("D");

        mGeneralTabLabelTotalSize.Text = String.Format("{0:0.00} MB ({1:0.00} MB done)", totalFilesSize, totalHaveSize);
        mGeneralTabLabelPieces.Text    = String.Format("{0} x {1:0.00} MB (have {2})", meta.mTotalPieces, meta.mPieceSize / (1024.0f * 1024.0f), meta.mPiecesDownloaded);

        String infohash = "";

        for (int i = 0, j = 0; i < meta.mInfoHash.Length; i++, j++)
        {
            infohash += String.Format("{0:X2}", meta.mInfoHash[i]);

            if (j == 3)
            {
                j         = -1;
                infohash += " ";
            }
        }
        mGeneralTabLabelHash.Text = infohash;

        mGeneralTabLabelComment.Text = meta.mComment;
    }    // END RefreshGeneralTabPage
Beispiel #3
0
    }    // END FindTorrentItemInMainListView

    public void RefreshListView()
    {
        // remove old torrents
        bool removed = false;

        do
        {
            removed = false;
            for (Int32 i = 0; i < mListView.Items.Count; i++)
            {
                TorrentHandle handle = (TorrentHandle)mListView.Items[i].Tag;

                if (torrentManager.GetTorrent(handle) == null)
                {
                    mListView.Items.Remove(mListView.Items[i]);
                    removed = true;
                    break;
                }
            }
        }while(removed == true);


        for (Int32 i = 0; i < torrentManager.TorrentCount; i++)
        {
            Torrent torrent = torrentManager.TorrentAtIndex(i);

            DllInterface.TorrentMetaData meta = torrent.MetaData;


            ListViewItem listViewItem = FindTorrentItemInMainListView(torrent.Handle);
            ListViewItem.ListViewSubItem idItem;
            ListViewItem.ListViewSubItem sizeItem;
            ListViewItem.ListViewSubItem doneItem;
            ListViewItem.ListViewSubItem statusItem;
            ListViewItem.ListViewSubItem seedsItem;
            ListViewItem.ListViewSubItem peersItem;
            ListViewItem.ListViewSubItem downSpeedItem;
            ListViewItem.ListViewSubItem upSpeedItem;
            ListViewItem.ListViewSubItem etaItem;


            bool addToControl = false;
            if (listViewItem == null)
            {
                addToControl = true;
            }

            if (addToControl)
            {
                // create the new item and pass the torrent name, all other details are sub items
                listViewItem = new System.Windows.Forms.ListViewItem(meta.mName);

                idItem = new ListViewItem.ListViewSubItem(listViewItem, "");
                listViewItem.SubItems.Add(idItem);

                sizeItem = new ListViewItem.ListViewSubItem(listViewItem, "");
                listViewItem.SubItems.Add(sizeItem);

                doneItem = new ListViewItem.ListViewSubItem(listViewItem, "");
                listViewItem.SubItems.Add(doneItem);

                statusItem = new ListViewItem.ListViewSubItem(listViewItem, "");
                listViewItem.SubItems.Add(statusItem);

                seedsItem = new ListViewItem.ListViewSubItem(listViewItem, "");
                listViewItem.SubItems.Add(seedsItem);

                peersItem = new ListViewItem.ListViewSubItem(listViewItem, "");
                listViewItem.SubItems.Add(peersItem);

                downSpeedItem = new ListViewItem.ListViewSubItem(listViewItem, "");
                listViewItem.SubItems.Add(downSpeedItem);

                upSpeedItem = new ListViewItem.ListViewSubItem(listViewItem, "");
                listViewItem.SubItems.Add(upSpeedItem);

                etaItem = new ListViewItem.ListViewSubItem(listViewItem, "");
                listViewItem.SubItems.Add(etaItem);

                mListView.Items.AddRange(new System.Windows.Forms.ListViewItem[] { listViewItem });

                // custom data
                listViewItem.Tag = torrent.Handle;
            }
            else
            {
                idItem        = listViewItem.SubItems[1];
                sizeItem      = listViewItem.SubItems[2];
                doneItem      = listViewItem.SubItems[3];
                statusItem    = listViewItem.SubItems[4];
                seedsItem     = listViewItem.SubItems[5];
                peersItem     = listViewItem.SubItems[6];
                downSpeedItem = listViewItem.SubItems[7];
                upSpeedItem   = listViewItem.SubItems[8];
                etaItem       = listViewItem.SubItems[9];
            }

            // set the image depending on if the connection is encrypted or not
            if (DllInterface.DoesTorrentOnlyUsesEncryptedConnections(torrent.Handle))
            {
                // fully encrypted, padlock icon
                listViewItem.ImageIndex = 6;
            }
            else
            {
                // some connections are plain text
                listViewItem.ImageIndex = 7;
            }


            String strNewValue;

            // Name
            if (listViewItem.Text != meta.mName)
            {
                listViewItem.Text = meta.mName;
            }

            strNewValue = torrent.Handle.ToString();
            if (idItem.Text != strNewValue)
            {
                idItem.Text = strNewValue;
            }

            // size
            Int64 totalSize = meta.mTotalSize;
            strNewValue = FormatBytes(totalSize);             //String.Format("{0:0} MB", (totalSize / (1024.0f * 1024.0f)));
            if (sizeItem.Text != strNewValue)
            {
                sizeItem.Text = strNewValue;
            }


            // done
            float onePercent = (meta.mTotalPieces / 100.0f);
            float done       = meta.mPiecesDownloaded / onePercent;
            if (float.IsNaN(done))
            {
                done = 0.0f;
            }
            strNewValue = String.Format("{0:0.0}%", done);
            if (doneItem.Text != strNewValue)
            {
                doneItem.Text = strNewValue;
            }

            // status
            switch (meta.mState)
            {
            case DllInterface.TorrentMetaData.TorrentState.Stopped:
                strNewValue = String.Format("Stopped");
                break;

            case DllInterface.TorrentMetaData.TorrentState.CreateFiles:
                strNewValue = String.Format("Creating Files");
                break;

            case DllInterface.TorrentMetaData.TorrentState.PeerMode:
                strNewValue = String.Format("Downloading");
                break;

            case DllInterface.TorrentMetaData.TorrentState.SeedMode:
                strNewValue = String.Format("Seeding");
                break;

            case DllInterface.TorrentMetaData.TorrentState.Queued:
                strNewValue = String.Format("Queued");
                break;

            case DllInterface.TorrentMetaData.TorrentState.Rechecking:
                strNewValue = String.Format("Checking");
                break;
            }
            if (statusItem.Text != strNewValue)
            {
                statusItem.Text = strNewValue;
            }

            // Seeds
            UInt32 numConnectedSeeds = meta.mNumSeeds;
            //UInt32 totalSeeds = 0;
            //strNewValue = String.Format("{0} ({1})", numConnectedSeeds, totalSeeds);
            strNewValue = String.Format("{0}", numConnectedSeeds);
            if (seedsItem.Text != strNewValue)
            {
                seedsItem.Text = strNewValue;
            }

            // Peers
            UInt32 numConnectedPeers = meta.mNumPeers;
            //UInt32 totalPeers = 0;
            strNewValue = String.Format("{0}", numConnectedPeers);
            if (peersItem.Text != strNewValue)
            {
                peersItem.Text = strNewValue;
            }


            // down speed
            float speed = ((float)meta.mDownloadSpeed / 1024.0f);
            strNewValue = String.Format("{0:0.0} kB/s", speed);
            if (downSpeedItem.Text != strNewValue)
            {
                downSpeedItem.Text = strNewValue;
            }

            // up speed
            speed       = ((float)meta.mUploadSpeed / 1024.0f);
            strNewValue = String.Format("{0:0.0} kB/s", speed);
            if (upSpeedItem.Text != strNewValue)
            {
                upSpeedItem.Text = strNewValue;
            }


            // TODO : if state is done, leave the following field blank...


            // eta
            if (meta.mDownloadSpeed == 0)
            {
                char chInfinity = (char)0x221E;

                strNewValue = String.Format("{0}", chInfinity);
                if (etaItem.Text != strNewValue)
                {
                    etaItem.Text = strNewValue;
                }
            }
            else
            {
                TimeSpan t = TimeSpan.FromSeconds(meta.mEta);
                if (t.Days > 0)
                {
                    strNewValue = string.Format("{0}d {1:D2}h {2:D2}m", t.Days, t.Hours, t.Minutes);
                }
                else if (t.Hours > 0)
                {
                    strNewValue = string.Format("{0}h {1:D2}m", t.Hours, t.Minutes);
                }
                else if (t.Minutes > 0)
                {
                    strNewValue = string.Format("{0} minute", t.Minutes);
                    if (t.Minutes > 1)
                    {
                        strNewValue = strNewValue + "s";
                    }
                }
                else
                {
                    strNewValue = string.Format("{0} seconds", t.Seconds);
                }

                if (etaItem.Text != strNewValue)
                {
                    etaItem.Text = strNewValue;
                }
            }
        }
    }// END RefreshListView