/// <summary> /// Add torrent file /// </summary> /// <param name="fileName">Torrent file path</param> /// <param name="settings">Torrent settings</param> /// <param name="savePath">Save path</param> public void Add(string fileName, TorrentSettings settings, string savePath) { GuiGeneralSettings genSettings = settingsBase.LoadSettings<GuiGeneralSettings>("General Settings"); string newPath = string.Empty; Torrent torrent = null; if (File.Exists(fileName)) { newPath = Path.Combine(genSettings.TorrentsPath, Path.GetFileName(fileName)); if (newPath != fileName) { if (File.Exists(newPath)) { MessageBox.Show("This torrent already exist in torrent folder."); return; } File.Copy(fileName, newPath); } torrent = Torrent.Load(newPath); } else { // Try as url if (fileName.IndexOf("//") > 0) { newPath = Path.Combine(genSettings.TorrentsPath, fileName.Substring(fileName.LastIndexOf("/") + 1)); if (File.Exists(newPath)) { MessageBox.Show("This torrent already exist in torrent folder."); return; } torrent = Torrent.Load(new Uri(fileName), newPath); } else { MessageBox.Show("This is not a valid torrent path or url."); return; } } ListViewItem item = new ListViewItem(Path.GetFileName(newPath)); ListViewItem.ListViewSubItem subitem = item.SubItems[0]; subitem.Name = "colName"; subitem = new ListViewItem.ListViewSubItem(); subitem.Name = "colSize"; item.SubItems.Add(subitem); subitem = new ListViewItem.ListViewSubItem(); subitem.Name = "colStatus"; item.SubItems.Add(subitem); subitem = new ListViewItem.ListViewSubItem(); subitem.Name = "colSeeds"; item.SubItems.Add(subitem); subitem = new ListViewItem.ListViewSubItem(); subitem.Name = "colLeeches"; item.SubItems.Add(subitem); subitem = new ListViewItem.ListViewSubItem(); subitem.Name = "colDownSpeed"; item.SubItems.Add(subitem); subitem = new ListViewItem.ListViewSubItem(); subitem.Name = "colUpSpeed"; item.SubItems.Add(subitem); subitem = new ListViewItem.ListViewSubItem(); subitem.Name = "colDownloaded"; item.SubItems.Add(subitem); subitem = new ListViewItem.ListViewSubItem(); subitem.Name = "colUploaded"; item.SubItems.Add(subitem); subitem = new ListViewItem.ListViewSubItem(); subitem.Name = "colRatio"; item.SubItems.Add(subitem); subitem = new ListViewItem.ListViewSubItem(); subitem.Name = "colRemaining"; item.SubItems.Add(subitem); mainForm.TorrentsView.Items.Add(item); // Add torrent to manager TorrentManager manager = new TorrentManager(torrent, savePath, settings); clientEngine.Register(manager); ImageListView.ImageListViewSubItem sitem = new ImageListView.ImageListViewSubItem(new TorrentProgressBar(manager)); sitem.Name = "colProgress"; item.SubItems.Insert(2,sitem); itemToTorrent.Add(item, manager); manager.PieceHashed += new EventHandler<PieceHashedEventArgs>(torrent_PieceHashed); manager.PeersFound += OnTorrentChange; manager.TorrentStateChanged += OnTorrentStateChange; manager.FileManager.BlockWritten += new EventHandler<BlockEventArgs>(FileManager_BlockWritten); manager.PieceManager.BlockReceived += new EventHandler<BlockEventArgs>(PieceManager_BlockReceived); manager.PieceManager.BlockRequestCancelled += new EventHandler<BlockEventArgs>(PieceManager_BlockRequestCancelled); manager.PieceManager.BlockRequested += new EventHandler<BlockEventArgs>(PieceManager_BlockRequested); manager.PeerConnected += OnPeerConnected; manager.PeerDisconnected += OnPeerDisconnected; item.SubItems["colSize"].Text = FormatSizeValue(manager.Torrent.Size); item.SubItems["colName"].Text = manager.Torrent.Name; manager.HashCheck(false); }
internal void LoadMiniWindow() { miniWindow.ListView.Items.Clear(); foreach (TorrentManager torrent in itemToTorrent.Values) { ListViewItem item = new ListViewItem(torrent.Torrent.Name); ListViewItem.ListViewSubItem subitem = item.SubItems[0]; subitem.Name = "colName"; ImageListView.ImageListViewSubItem sitem = new ImageListView.ImageListViewSubItem(new TorrentProgressBar(torrent)); sitem.Name = "colProgress"; item.SubItems.Add(sitem); miniWindow.ListView.Items.Add(item); } }