public void LoadTorrent(string filename) { if (!Directory.Exists(torrentDir)) { Directory.CreateDirectory(torrentDir); } try { TorrentInfo info = new TorrentInfo(filename); string torrentFileName = Path.Combine(torrentDir, info.Name + ".torrent"); File.Copy(filename, torrentFileName, true); var result = from t in Torrents where t.InfoHash == info.InfoHash select t; if (result == null || result.Count() == 0) { var addParams = new AddTorrentParams { SavePath = Properties.Settings.Default.Location, TorrentInfo = info }; var torrent = Torrent.Create(addParams, session); torrent.TorrentFileName = torrentFileName; AddTorrent(torrent); } else { Error?.Invoke(this, "This torrent already exists"); } } catch { Error?.Invoke(this, "Error parsing file"); } }
public async void LoadTorrent(string filename) { if (!Directory.Exists(torrentDir)) { Directory.CreateDirectory(torrentDir); } try { string torrentFileName = Path.Combine(torrentDir, Path.GetFileName(filename)); File.Copy(filename, torrentFileName, true); var result = from t in Torrents where t.TorrentFileName == filename select t; if (result == null || result.Count() == 0) { var addParams = new AddTorrentParams { SaveFolder = Properties.Settings.Default.Location, Filename = filename }; var torrent = await Torrent.Create(addParams); torrent.TorrentFileName = torrentFileName; AddTorrent(torrent); } else { Error?.Invoke(this, "This torrent already exists"); } } catch (Exception ex) { Error?.Invoke(this, "Error parsing file"); } }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; string file = e.Argument as string; Torrent torrent = new Torrent(trackers, file, null, string.Empty, false) { Worker = worker }; byte[] buf1; string magnet; torrent.Create(out buf1, out magnet); ed2k ed2k = new ed2k { Worker = worker }; string edlink = ed2k.GetLink(file); e.Result = new ArrayList { buf1, edlink, magnet }; }
public async void LoadMagnet(string link) { if (!Directory.Exists(torrentDir)) { Directory.CreateDirectory(torrentDir); } try { if (link.StartsWith(@"magnet:?xt=urn:btih:") || link.StartsWith(@"http://") || link.StartsWith(@"https://")) { var addParams = new AddTorrentParams { SaveFolder = Properties.Settings.Default.Location, Url = link }; var torrent = await Torrent.Create(addParams); var result = from t in Torrents where t.InfoHash == torrent.InfoHash select t; if (result == null || result.Count() == 0) { AddTorrent(torrent); } else { Error?.Invoke(this, "This torrent already exists"); } } else { Error?.Invoke(this, "Wrong link"); } } catch (Exception ex) { Error?.Invoke(this, "Error opening magnet link!"); } }