public void AddTorrent(string filename) { var data = System.IO.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 (!System.IO.File.Exists(newfilePath)) { using (var bw = new System.IO.BinaryWriter(new System.IO.FileStream(newfilePath, System.IO.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 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 async System.Threading.Tasks.Task LoadFastResumeData() { IsTsunamiEnabled = false; if (Directory.Exists("Fastresume")) { // FARE TRY CATCH FINALLY log.Debug("processing"); //Window loading = new Pages.Loading(); //loading.Show(); //System.Windows.Controls.Label lb = (System.Windows.Controls.Label)loading.FindName("txtLoading"); //System.Windows.Controls.ProgressBar pb = (System.Windows.Controls.ProgressBar)loading.FindName("progressLoading"); string[] files = Directory.GetFiles("Fastresume", "*.fastresume"); //int i = 0; if (files.Length > 0) { // fast resuming //pb.Maximum = files.Length+0.01; FileToLoad = files.Length + 0.01; foreach (string s in files) { //i++; FileLoading++; //lb.Content = "Loading "+i+" of "+files.Length+" torrents"; StringLoading = "Loading " + FileLoading + " of " + files.Length + " torrents"; log.Info(stringLoading); //pb.Value = i; 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 await System.Threading.Tasks.Task.Run(() => _torrentSession.add_torrent(atp)); } log.Debug("{0} loaded. waiting 250ms", FileLoading); await System.Threading.Tasks.Task.Delay(250); } } else { log.Debug("nothing to fast resume, sleep"); //lb.Content = "Tsunami is loading..."; StringLoading = "Tsunami is loading..."; //pb.Maximum = 10.001; FileToLoad = 10.001; while (FileLoading < 10) { // i++; FileLoading++; // pb.Value = i; await System.Threading.Tasks.Task.Delay(250); } } //loading.Close(); } else { log.Debug("no fastresume folder found, creating"); Directory.CreateDirectory("Fastresume"); StringLoading = "Tsunami is loading..."; FileToLoad = 10.001; while (FileLoading < 10) { FileLoading++; await System.Threading.Tasks.Task.Delay(250); } } IsTsunamiEnabled = true; log.Debug("finished"); }
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"); } }
public TorrentItem(Core.TorrentStatus ts) { Formatter = x => ((int)x).ToString() + "%"; FileList = new ObservableCollection <FileEntry>(); using (Core.Sha1Hash hash = ts.info_hash) { Hash = hash.ToString(); } FileEntry fe; int piecesOffset = 0; using (Core.TorrentInfo tf = ts.torrent_file()) using (Core.FileStorage fs = tf.files()) { // per ogni file nel torrent for (int i = 0; i <= tf.num_files() - 1; i++) { using (Core.FileEntry cfe = fs.at(i)) using (Core.Sha1Hash hash = cfe.filehash) { // lo inserisco fe = new FileEntry(cfe); fe.FileName = fs.file_name(i); fe.IsValid = fs.is_valid(); fe.PieceSize = fs.piece_size(i); if (fe.PieceSize > fe.Size) { // one piece fe.Pieces.Add(new Part() { Id = piecesOffset, Downloaded = false, Priority = 4 }); } else { decimal piecesUsed = fe.Size / fe.PieceSize; for (int u = 0; u < piecesUsed; u++) { fe.Pieces.Add(new Part() { Id = piecesOffset, Downloaded = false, Priority = 4 }); piecesOffset++; } } FileList.Add(fe); } } } if (FileList.Count == 0) { // non ci sono file nel torrent fe = new FileEntry(); fe.FileName = ts.name; FileList.Add(fe); } SequentialDownload = ts.sequential_download; Update(ts); }