void LibTorrentAlerts_ResumeDataArrived(Ragnar.TorrentHandle handle, byte[] data) { string path = Path.Combine(State.TorrentsStateSaveDirectory, handle.InfoHash.ToHex() + ".resume"); Directory.CreateDirectory(Path.GetDirectoryName(path)); File.WriteAllBytes(path, data); }
//void LibTorrentAlerts_TorrentNetworkStatisticsUpdated(Ragnar.StatsAlert sa) //{ // string key = sa.Handle.InfoHash.ToHex(); // if (this._torrents.ContainsKey(key)) // { // this._torrents[key].DoNetStatsUpdate(sa); // } //} void LibTorrentAlerts_MetadataReceived(Ragnar.TorrentHandle handle) { string key = handle.InfoHash.ToHex(); TorrentInfo ti = null; while (!this._torrents.ContainsKey(key)) { ; // HACK } ti = this._torrents[key]; // This is critical, without it byteflood won't load this torrent at the next startup byte[] data = this.BackUpMangetLinkMetadata(handle.TorrentFile); ti.OriginalTorrentFilePath = this.SaveMagnetLink(data, handle.TorrentFile.Name); set_files_priorities(handle, 3); ti.DoMetadataDownloadComplete(); //NotificationManager.Notify(new MagnetLinkNotification(MagnetLinkNotification.EventType.MetadataDownloadComplete, handle)); handle_torrent_file_selection(ti); }
internal void set_files_priorities(Ragnar.TorrentHandle handle, int value) { int[] prs = new int[handle.TorrentFile.NumFiles]; for (int i = 0; i < prs.Length; i++) { prs[i] = value; } handle.SetFilePriorities(prs); }
void LibTorrentAlerts_TorrentStateChanged(Ragnar.TorrentHandle handle, Ragnar.TorrentState oldstate, Ragnar.TorrentState newstate) { string key = handle.InfoHash.ToHex(); if (this._torrents.ContainsKey(key)) { this._torrents[key].DoStateChanged(oldstate, newstate); } }
void LibTorrentAlerts_TorrentFinished(Ragnar.TorrentHandle handle) { string key = handle.InfoHash.ToHex(); if (this._torrents.ContainsKey(key)) { this._torrents[key].DoTorrentComplete(); } }
void LibTorrentAlerts_TorrentAdded(Ragnar.TorrentHandle handle) { App.Current.Dispatcher.Invoke(new Action(() => { if (!_torrents.ContainsKey(handle.InfoHash.ToHex())) { TorrentInfo ti = new TorrentInfo(handle); this._torrents.Add(handle.InfoHash.ToHex(), ti); this.Torrents.Add(ti); } })); }
/// <summary> /// Used by the feed manager /// </summary> /// <param name="path"></param> /// <param name="entry"></param> /// <returns>Return weither the torrent was loaded</returns> public bool AddTorrentRss(string path, Services.RSS.RssUrlEntry entry) { if (!File.Exists(path)) { return(false); } Ragnar.TorrentInfo torrent = new Ragnar.TorrentInfo(File.ReadAllBytes(path)); if (torrent.IsValid) { if (this.ContainTorrent(torrent.InfoHash)) { return(false); } else { Directory.CreateDirectory(entry.DownloadDirectory); Ragnar.TorrentHandle handle = this.LibtorrentSession.AddTorrent(new Ragnar.AddTorrentParams() { SavePath = entry.DownloadDirectory, TorrentInfo = torrent, DownloadLimit = entry.DefaultSettings.MaxDownloadSpeed, MaxConnections = entry.DefaultSettings.MaxConnections, MaxUploads = entry.DefaultSettings.UploadSlots, UploadLimit = entry.DefaultSettings.MaxUploadSpeed }); set_files_priorities(handle, 3); if (!entry.AutoDownload) { handle.AutoManaged = false; handle.Pause(); } // normally, adding a torrent will fire the TorrentAdded Event, so this line // is somewhat unecessary. //this.Torrents.Add(new TorrentInfo(handle)); return(true); } } return(false); }
public void SaveState(bool is_shuttingdown = false) { Directory.CreateDirectory(StateSaveDirectory); File.WriteAllBytes(this.LtSessionFilePath, this.LibtorrentSession.SaveState()); for (int index = 0; index < this.Torrents.Count; index++) { try { TorrentInfo ti = this.Torrents[index]; Ragnar.TorrentHandle handle = ti.Torrent; if (!handle.HasMetadata) { continue; } if (handle.NeedSaveResumeData()) { handle.SaveResumeData(); } if (is_shuttingdown) { //save misc settings JsonObject jo = new JsonObject(); jo.Add("SavePath", handle.QueryStatus().SavePath); //jo.Add("PickedMovieData", ti.PickedMovieData.ToString()); jo.Add("RanCommand", ti.RanCommand); jo.Add("RatioLimit", ti.RatioLimit); jo.Add("CompletionCommand", ti.CompletionCommand); jo.Add("CustomName", ti.Name); jo.Add("OriginalTorrentFilePath", ti.OriginalTorrentFilePath); jo.Add("IsStopped", ti.IsStopped); jo.Add("Labels", this.LabelManager.GetLabelsForTorrent(ti)); using (TextWriter tw = File.CreateText( Path.Combine(State.TorrentsStateSaveDirectory, ti.InfoHash + ".tjson"))) { JsonConvert.Export(jo, tw); } } } catch (System.IndexOutOfRangeException) { break; } catch (Exception) { continue; } } }
public MagnetLinkNotification(EventType type, Ragnar.TorrentHandle h) : this(type, h.TorrentFile.Name, h.TorrentFile.InfoHash) { }