private void AddTorrentFileButton_Click(object sender, EventArgs e) { var openfile = new OpenFileDialog { Filter = "Torrent Files|*.torrent", Title = "Select Torrent File" }; openfile.ShowDialog(); var parser = new BencodeParser(); var torrent = parser.Parse <Torrent>(openfile.FileName); var addTorrent = new AddTorrentDialog(); var drive = new DriveInfo("C"); // Formatting Labels ((Label)addTorrent.Controls["TorrentSizeLabel"]).Text = Formatter.BytesToEnglish(torrent.TotalSize) + " (Space Left on drive: " + Formatter.BytesToEnglish(drive.AvailableFreeSpace) + ")"; ((Label)addTorrent.Controls["TorrentDateLabel"]).Text = torrent.CreationDate.ToString(); ((Label)addTorrent.Controls["TorrentHashLabel"]).Text = Formatter.HashFormatter(torrent.GetInfoHash()); ((Label)addTorrent.Controls["TorrentCommentLabel"]).Text = torrent.Comment; // Display Torrent Files in the AddTorrentMenu Window var listview = ((ListView)addTorrent.Controls["FilesList"]); var T = torrent.File; // Only One File Exists if (torrent.Files == null) { var item = new ListViewItem(new string[] { T.FileName, Formatter.BytesToEnglish(T.FileSize), "Normal" }); //var test = item.SubItems; listview.Items.Add(item); item.Checked = true; } // Multiple Files in the torrent else { MultiFileInfoList files = torrent.Files; foreach (MultiFileInfo f in files) { listview.Items.Add(new ListViewItem(new string[] { f.FileName, Formatter.BytesToEnglish(f.FileSize), "Normal" })); } } ((ComboBox)addTorrent.Controls["TorrentDirectory"]).Text = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); DialogResult result = addTorrent.ShowDialog(); if (result == DialogResult.OK) { var row = new ListViewItem(new string[] { (MainWindowListView.Items.Count + 1).ToString(), T.FileName, Formatter.BytesToEnglish(T.FileSize) }); MainWindowListView.Items.Add(row); row.Selected = true; var test2 = new Connection(torrent); } }
/// <summary> /// Parses file info for multi-file torrents. /// </summary> /// <param name="info">The 'info'-dictionary of a torrent.</param> /// <param name="encoding"></param> /// <returns>The file info.</returns> protected virtual MultiFileInfoList ParseMultiFileInfo(BDictionary info, Encoding encoding) { if (!info.ContainsKey(TorrentInfoFields.Files)) { return(null); } var list = new MultiFileInfoList { DirectoryName = info.Get <BString>(TorrentInfoFields.Name).ToString(encoding), }; var fileInfos = info.Get <BList>(TorrentInfoFields.Files).Cast <BDictionary>() .Select(x => new MultiFileInfo { FileSize = x.Get <BNumber>(TorrentFilesFields.Length), Path = x.Get <BList>(TorrentFilesFields.Path)?.AsStrings(encoding).ToList(), Md5Sum = x.Get <BString>(TorrentFilesFields.Md5Sum)?.ToString(encoding) }); list.AddRange(fileInfos); return(list); }
public static void InsertInDataGrid(DataGridView grid, SingleFileInfo torrent, MultiFileInfoList torrents = null) { var column = ((DataGridViewComboBoxColumn)grid.Columns[2]); grid.Rows.Add(new object[] { torrent.FileName, Formatter.BytesToEnglish(torrent.FileSize), "Normal" }); var cell = (DataGridViewComboBoxCell)grid.Rows[0].Cells[2]; // var test = grid; //column.DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox; //column.Items.AddRange(new string[] { "Normal", "High", "Maximum" }); //column.MaxDropDownItems = 3; /* * grid.DefaultCellStyle.SelectionBackColor = Color.White; * grid.DefaultCellStyle.SelectionForeColor = Color.Black; */ }