Пример #1
0
 public DownloadInformationControl(Download download)
 {
     InitializeComponent();
     m_Download         = download;
     iconPictureBox.Tag = m_Download.FileName;
     try
     {
         // 2008-10-21 Eroli: Mono-Fix
         if (!UtilitiesForMono.IsRunningOnMono)
         {
             iconPictureBox.Image = ShellIcon.GetLargeSystemIcon((string)iconPictureBox.Tag);
         }
     }
     catch
     {
     }
     fileSizeTextBox.Text  = m_Download.FileSizeString;
     fileNameTextBox.Text  = m_Download.FileName;
     subFolderTextBox.Text = m_Download.SubFolder;
     fileHashTextBox.Text  = m_Download.FileHashString;
     if (m_Download.LastReception != null)
     {
         TimeSpan span = DateTime.Now.Subtract((DateTime)m_Download.LastReception);
         lastReceptionTextBox.Text = string.Format(Properties.Resources.Date_Diff, span.Days, span.Hours, span.Minutes, span.Seconds);
     }
     try
     {
         progressPictureBox.Image = ProgressBars.GetProgressBar(m_Download, progressPictureBox.Width, progressPictureBox.Height, Font);
     }
     catch
     {
     }
 }
Пример #2
0
 private void updateTimer_Tick(object sender, EventArgs e)
 {
     if (!((string)iconPictureBox.Tag).Equals(m_Download.FileName))
     {
         iconPictureBox.Tag = m_Download.FileName;
         try
         {
             // 2008-10-21 Eroli: Mono-Fix
             if (!UtilitiesForMono.IsRunningOnMono)
             {
                 iconPictureBox.Image = ShellIcon.GetLargeSystemIcon((string)iconPictureBox.Tag);
             }
         }
         catch
         {
         }
     }
     fileNameTextBox.Text = m_Download.FileName;
     fileSizeTextBox.Text = m_Download.FileSizeString;
     fileHashTextBox.Text = m_Download.FileHashString;
     if (m_Download.LastReception != null)
     {
         TimeSpan span = DateTime.Now.Subtract((DateTime)m_Download.LastReception);
         lastReceptionTextBox.Text = string.Format(Properties.Resources.Date_Diff, span.Days, span.Hours, span.Minutes, span.Seconds);
     }
     try
     {
         progressPictureBox.Image.Dispose();
     }
     catch
     {
     }
     try
     {
         progressPictureBox.Image = ProgressBars.GetProgressBar(m_Download, progressPictureBox.Width, progressPictureBox.Height, Font);
     }
     catch
     {
     }
     subFolderTextBox.Text = m_Download.SubFolder;
 }
Пример #3
0
        private void updateTimer_Tick(object sender, EventArgs e)
        {
            try
            {
                ((System.Windows.Forms.Timer)sender).Stop();
                updateTimer.Interval = Math.Max(1000, uploadsDataGridView.Rows.Count * 10);
                if (m_MainForm.ActiveTab == this && !m_MainForm.IsInTray)
                {
                    try
                    {
                        // T.Norad: BZ 121. Copy uploads collection to prevent a lock on the uploads collection in core.
                        RIndexedHashtable <string, Upload> uploadsCopy = new RIndexedHashtable <string, Upload>(Core.Uploads);
                        uploadsLabel.Text = string.Format(Properties.Resources.Uploads, uploadsCopy.Count, Constants.MaximumUploadsCount, uploadsCopy.Count - Constants.MaximumUploadsCount < 0 ? 0 : uploadsCopy.Count - Constants.MaximumUploadsCount);
                        {
                            DataGridViewRow row;
                            for (int n = uploadsDataGridView.Rows.Count - 1; n >= 0; n--)
                            {
                                row = uploadsDataGridView.Rows[n];
                                if (!uploadsCopy.ContainsKey(((RandomTag <string>)row.Tag).Tag))
                                {
                                    try
                                    {
                                        ((Image)row.Cells["Progress"].Value).Dispose();
                                    }
                                    catch
                                    {
                                    }
                                    uploadsDataGridView.Rows.RemoveAt(n);
                                }
                            }
                        }
                        DataGridViewRow  uploadRow;
                        DataGridViewCell uploadCell;
                        int a = 0;
                        foreach (Upload upload in uploadsCopy.Values)
                        {
                            if (a % 50 == 0)
                            {
                                Application.DoEvents();
                            }
                            a++;
                            uploadRow = null;
                            foreach (DataGridViewRow row in uploadsDataGridView.Rows)
                            {
                                if ((((RandomTag <string>)row.Tag).Tag).Equals(upload.UploadIDString))
                                {
                                    uploadRow = row;
                                    break;
                                }
                            }

                            // get display values from shared files or (swarming) download
                            String fileName;
                            String fileSizeString;
                            long   fileSize;
                            try
                            {
                                SharedFile sharedFile;
                                if (Core.SharedFiles.TryGetValue(upload.FileHashString, out sharedFile))
                                {
                                    fileName       = sharedFile.FileName;
                                    fileSizeString = sharedFile.FileSizeString;
                                    fileSize       = sharedFile.FileSize;
                                }
                                else
                                {
                                    Download download;
                                    if (Core.DownloadsAndQueue.TryGetValue(upload.SourceDownloadIDString, out download))
                                    {
                                        fileName       = download.FileName;
                                        fileSizeString = download.FileSizeString;
                                        fileSize       = download.FileSize;
                                    }
                                    else
                                    {
                                        continue;
                                    }
                                }
                            }
                            catch
                            {
                                continue;
                            }
                            // create grid rows
                            if (uploadRow == null)
                            {
                                uploadRow        = new DataGridViewRow();
                                uploadRow.Height = 17;
                                uploadCell       = new DataGridViewTextBoxCell();
                                uploadRow.Cells.Add(uploadCell);
                                uploadCell.Value = fileName;
                                uploadCell       = new DataGridViewTextBoxCell();
                                uploadRow.Cells.Add(uploadCell);
                                uploadCell.Value = fileSizeString;
                                uploadCell.Tag   = fileSize;
                                uploadCell       = new DataGridViewTextBoxCell();
                                uploadRow.Cells.Add(uploadCell);
                                uploadCell.Value = upload.CompletedString;
                                uploadCell.Tag   = upload.Completed;
                                uploadCell       = new DataGridViewImageCell();
                                uploadRow.Cells.Add(uploadCell);
                                try
                                {
                                    uploadCell.Value = ProgressBars.GetProgressBar(upload, uploadsDataGridView.Columns["Progress"].Width, 16);
                                }
                                catch
                                {
                                }
                                uploadCell = new DataGridViewTextBoxCell();
                                uploadRow.Cells.Add(uploadCell);
                                if (uploadsCopy.IndexOfKey(upload.UploadIDString) < Constants.MaximumUploadsCount)
                                {
                                    uploadCell.Value = upload.UpstreamString;
                                    uploadCell.Tag   = upload.Upstream;
                                }
                                else
                                {
                                    uploadCell.Value = string.Empty;
                                    uploadCell.Tag   = -1;
                                }
                                uploadCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight;
                                uploadRow.Tag = new RandomTag <string>(upload.UploadIDString);
                                uploadsDataGridView.Rows.Add(uploadRow);
                                continue;
                            }
                            uploadCell       = uploadRow.Cells["FileName"];
                            uploadCell.Value = fileName;
                            uploadCell       = uploadRow.Cells["FileSize"];
                            uploadCell.Value = fileSizeString;
                            uploadCell.Tag   = fileSize;
                            uploadCell       = uploadRow.Cells["Completed"];
                            uploadCell.Value = upload.CompletedString;
                            uploadCell.Tag   = upload.Completed;
                            uploadCell       = uploadRow.Cells["Progress"];
                            try
                            {
                                ((Image)uploadCell.Value).Dispose();
                            }
                            catch
                            {
                            }
                            try
                            {
                                uploadCell.Value = ProgressBars.GetProgressBar(upload, (int)uploadsDataGridView.Columns["Progress"].Width, 16);
                            }
                            catch
                            {
                            }
                            uploadCell = uploadRow.Cells["lastRequest"];
                            if (uploadsCopy.IndexOfKey(upload.UploadIDString) < Constants.MaximumUploadsCount)
                            {
                                uploadCell.Value = upload.UpstreamString;
                                uploadCell.Tag   = upload.Upstream;
                            }
                            else
                            {
                                uploadCell.Value = string.Empty;
                                uploadCell.Tag   = -1;
                            }
                        }
                        uploadsDataGridView.Sort(uploadsDataGridView.SortedColumn, uploadsDataGridView.SortOrder == SortOrder.Descending ? ListSortDirection.Descending : ListSortDirection.Ascending);
                    }
                    catch (Exception ex)
                    {
                        Logger.Instance.Log(ex, "An exception was thrown! (UploadsControl)");
                    }
                }
            }
            finally
            {
                ((System.Windows.Forms.Timer)sender).Start();
            }
        }