public bool StartDownloading(string url, string label, bool force, string cookies, string id, string Downoption, string option, string folder) { string data = ""; CacheItem item = _contentCache.Item(url); if (item == null) { try { WebClient client = new WebClient(); client.Headers.Add("User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.186 Safari/535.1"); if (cookies != null) { client.Headers.Add("Cookie", cookies); } if (Downoption != "") { client.Headers.Add(Downoption); } Log.Instance().Print(client.Headers.ToString()); Log.Instance().Print("downloading torrent file"); byte[] content = client.DownloadData(url); data = Encoding.UTF8.GetString(content); item = new CacheItem(url, content); _contentCache.Add(item); } catch (Exception e) { MyTorrents.Instance().DisplayError("Error", "An unknown error has occurred."); Log.Instance().Print(string.Format("Could not download torrent [{0}].", url)); Log.Instance().Print(e); Log.Instance().Print(data); return(false); } } else { //MyTorrents.Instance().DisplayError("Error", "This torrent has been found in download cache. Action cancelled."); Log.Instance().Print(string.Format("Torrent [{0}] found from cache, not downloading again.", url)); long size = 0; foreach (CacheItem i in _contentCache.Cache) { size += i.Data.Length; } Log.Instance().Print(string.Format("Cache size is around {0:F2}Kb.", size / 1024.0)); if (!force) { return(false); } } TorrentFile tfile = null; try { MemoryStream ms = new MemoryStream(item.Data); if (ms == null) { throw new Exception(); } tfile = new TorrentFile(ms); if (tfile == null) { throw new Exception(); } } catch { MyTorrents.Instance().DisplayError("Error", "An error has occurred. Invalid torrent file."); return(false); } string hash = tfile.Hash; //if (TorrentByHash(hash) != null) //{ // MyTorrents.Instance().DisplayError("Error", "Torrent already exists."); // return false; //} string filename = tfile.Name; tfile.Close(); if (!force) { if (IsAlreadyDownloaded(hash)) { Log.Instance().Print("Already downloaded!"); return(false); } } Log.Instance().Print(String.Format("Download [{0}] started.", url)); bool ret = false; if (folder == "") { ret = _torrentSession.StartDownload(item.Data, filename, label, hash, option); } else { ret = _torrentSession.StartDownloadToFolder(item.Data, filename, label, hash, option, folder); } if (!ret) { MyTorrents.Instance().DisplayError("Error", "An unknown error has occurred."); Log.Instance().Print(data); } if (ret && !force) { _hashQueue.Add(""); } return(ret); }