public static void addTorrent(string filename) { var data = File.ReadAllBytes(filename); string newfilePath; using (var atp = new Core.AddTorrentParams()) using (var ti = new Core.TorrentInfo(filename)) { atp.save_path = Settings.User.PathDownload; atp.ti = ti; atp.flags &= ~Core.ATPFlags.flag_auto_managed; // remove auto managed flag atp.flags &= ~Core.ATPFlags.flag_paused; // remove pause on added torrent atp.flags &= ~Core.ATPFlags.flag_use_resume_save_path; // newfilePath = "./Fastresume/" + ti.info_hash().ToString() + ".torrent"; if (!File.Exists(newfilePath)) { using (var bw = new BinaryWriter(new FileStream(newfilePath, FileMode.Create))) { bw.Write(data); bw.Close(); } } _torrentSession.async_add_torrent(atp); } }
public static void addTorrent(byte[] buffer) { using (var atp = new Core.AddTorrentParams()) using (var ti = new Core.TorrentInfo(buffer)) { atp.save_path = Settings.User.PathDownload; atp.ti = ti; atp.flags &= ~Core.ATPFlags.flag_auto_managed; // remove auto managed flag atp.flags &= ~Core.ATPFlags.flag_paused; // remove pause on added torrent _torrentSession.async_add_torrent(atp); } }
public void LoadTorrent(string filename) { using (AddTorrentParams atp = new AddTorrentParams()) using (TorrentInfo ti = new TorrentInfo(filename)) { atp.ti = ti; atp.SavePath = @"C:\Download"; //atp.Flags &= ~Core.ATPFlags.flag_auto_managed; // remove auto managed flag //atp.Flags &= ~Core.ATPFlags.flag_paused; // remove pause on added torrent // atp.Flags &= ~Core.ATPFlags.flag_use_resume_save_path; // Session_AsyncAddTorrent(atp.Handle); } }
public static void LoadFastResumeData() { if (Directory.Exists("Fastresume")) { string[] files = Directory.GetFiles("Fastresume", "*.fastresume"); foreach (string s in files) { var data = File.ReadAllBytes(s); var info_hash = Path.GetFileNameWithoutExtension(s); var filename = "Fastresume/" + info_hash + ".torrent"; Core.TorrentInfo ti; if (File.Exists(filename)) { ti = new Core.TorrentInfo(filename); } else { ti = new Core.TorrentInfo(new Core.Sha1Hash(info_hash)); } using (var atp = new Core.AddTorrentParams()) using (ti) { atp.ti = ti; atp.save_path = Settings.User.PathDownload; atp.resume_data = (sbyte[])(Array)data; atp.flags &= ~Core.ATPFlags.flag_auto_managed; // remove auto managed flag atp.flags &= ~Core.ATPFlags.flag_paused; // remove pause on added torrent _torrentSession.async_add_torrent(atp); } } } else { Directory.CreateDirectory("Fastresume"); } }