public LibTorrentAlertsWatcher(Ragnar.Session session) { ses = session; alerts = ses.Alerts; main_thread_dispatcher = System.Windows.Threading.Dispatcher.CurrentDispatcher; watcher_thread = new System.Threading.Thread(monitor); watcher_thread.Priority = System.Threading.ThreadPriority.AboveNormal; watcher_thread.Start(); }
/// <summary> /// No use outside of TorrentInfo.PopulateFileList() /// </summary> /// <param name="branch"></param> /// <param name="trunk"></param> public static void ProcessFile(string branch, DirectoryKey trunk, TorrentInfo owner, Ragnar.FileEntry f, int index) { string[] parts = branch.Split('\\'); if (parts.Length == 1) { //((FileList)trunk[DirectoryKey.FILE_MARKER]).Add(new FileInfo(owner, f)); trunk.Add(f.Path, new FileInfo(owner, f, index)); } else { string node = parts[0]; string other = branch.Substring(node.Length + 1); if (!trunk.ContainsKey(node)) { trunk[node] = new DirectoryKey(node, owner); } ProcessFile(other, (DirectoryKey)trunk[node], owner, f, index); } }
private byte[] BackUpMangetLinkMetadata(Ragnar.TorrentInfo info) { Ragnar.TorrentCreator tc = new Ragnar.TorrentCreator(info); byte[] f = tc.Generate(); tc.Dispose(); string path = System.IO.Path.Combine(State.TorrentsStateSaveDirectory, info.InfoHash + ".torrent"); File.WriteAllBytes(path, f); return f; }
/// <summary> /// Copies a torrent to ./torrents-bkp /// </summary> /// <param name="path">The path of the torrent file to be copied.</param> /// <returns>The new path of the torrent file.</returns> public string BackupTorrent(string path, Ragnar.TorrentInfo t) { string newpath = System.IO.Path.Combine(State.TorrentsStateSaveDirectory, t.InfoHash + ".torrent"); if (new DirectoryInfo(newpath).FullName != new DirectoryInfo(path).FullName) File.Copy(path, newpath, true); return newpath; }
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_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_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); } })); }
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_TorrentStatsUpdated(Ragnar.TorrentStatus status) { string key = status.InfoHash.ToHex(); if (this._torrents.ContainsKey(key)) { this._torrents[key].DoStatsUpdate(status); } }
void LibTorrentAlerts_TorrentFinished(Ragnar.TorrentHandle handle) { string key = handle.InfoHash.ToHex(); if (this._torrents.ContainsKey(key)) { this._torrents[key].DoTorrentComplete(); } }
//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); }
public MagnetLinkNotification(EventType type, Ragnar.TorrentHandle h) : this(type, h.TorrentFile.Name, h.TorrentFile.InfoHash) { }
public TrackerInfo(Ragnar.AnnounceEntry t, TorrentInfo parent) { this.Tracker = t; this.Parent = parent; }
public FileInfo(TorrentInfo owner, Ragnar.FileEntry file, int file_index) { this.file_path = file.Path.FixUTF8(); this.RawSize = file.Size; this.Owner = owner; this.FileIndex = file_index; if (this.Owner != null) { this.Owner.FileInfoList.Add(this); } }