Пример #1
0
        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);
        }
Пример #2
0
        /// <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);
        }
Пример #3
0
        public void AddTorrentByPath(string path, bool notifyIfAdded = true)
        {
            Ragnar.TorrentInfo torrent = null;

            try
            {
                torrent = new Ragnar.TorrentInfo(File.ReadAllBytes(path));

                if (!torrent.IsValid)
                {
                    torrent.Dispose();
                    MessageBox.Show(string.Format("Invalid torrent file {0}", path), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                if (this.ContainTorrent(torrent.InfoHash))
                {
                    if (notifyIfAdded)
                    {
                        NotificationManager.Notify(new TorrentAlreadyAddedNotification(torrent.Name, torrent.InfoHash));
                    }
                    return;
                }

                path = BackupTorrent(path, torrent);
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("Could not load torrent {0}\n{1}", path, ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            var handle = this.LibtorrentSession.AddTorrent(new Ragnar.AddTorrentParams()
            {
                TorrentInfo = torrent,
                SavePath    = App.Settings.DefaultDownloadPath
            });

            handle.AutoManaged = false;
            handle.Pause();


            TorrentInfo ti = new TorrentInfo(handle);

            ti.OriginalTorrentFilePath = path;
            ti.ApplyTorrentSettings(App.Settings.DefaultTorrentProperties);

            // we don't want all files to have a "lowest" file priorities since initialize priorities with the value 1
            // we change it to 3, the priority "normal" as considered by byteflood.

            set_files_priorities(handle, 3);

            handle_torrent_file_selection(ti);
        }
Пример #4
0
        /// <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);
        }
Пример #5
0
        /// <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;
        }
Пример #6
0
        public void AddTorrentByPath(string path, bool notifyIfAdded = true)
        {
            Ragnar.TorrentInfo torrent = null;

            try
            {
                torrent = new Ragnar.TorrentInfo(File.ReadAllBytes(path));

                if (!torrent.IsValid)
                {
                    torrent.Dispose();
                    MessageBox.Show(string.Format("Invalid torrent file {0}", path), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                if (this.ContainTorrent(torrent.InfoHash))
                {
                    if (notifyIfAdded)
                    {
                        NotificationManager.Notify(new TorrentAlreadyAddedNotification(torrent.Name, torrent.InfoHash));
                    }
                    return;
                }

                path = BackupTorrent(path, torrent);
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("Could not load torrent {0}\n{1}", path, ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            var handle = this.LibtorrentSession.AddTorrent(new Ragnar.AddTorrentParams()
            {
                TorrentInfo = torrent,
                SavePath = App.Settings.DefaultDownloadPath
            });

            handle.AutoManaged = false;
            handle.Pause();


            TorrentInfo ti = new TorrentInfo(handle);
            ti.OriginalTorrentFilePath = path;
            ti.ApplyTorrentSettings(App.Settings.DefaultTorrentProperties);

            // we don't want all files to have a "lowest" file priorities since initialize priorities with the value 1
            // we change it to 3, the priority "normal" as considered by byteflood.

            set_files_priorities(handle, 3);

            handle_torrent_file_selection(ti);
        }
Пример #7
0
        private void Import(object sender, RoutedEventArgs e)
        {
            foreach (var listing in list)
            {
                try
                {
                    if (!listing.Import)
                        continue;

                    Ragnar.TorrentInfo torrent = new Ragnar.TorrentInfo(File.ReadAllBytes(listing.Path));

                    if (!torrent.IsValid)
                    {
                        continue;
                    }

                    AppState.BackupTorrent(listing.Path, torrent);

                    string savepath = null;

                    if (torrent.NumFiles > 1)
                    {
                        if (listing.SavePath.EndsWith(torrent.Name))
                        {
                            // then we should download in the parent directory
                            DirectoryInfo di = new DirectoryInfo(listing.SavePath);
                            savepath = di.Parent.FullName;
                        }
                        else
                        {
                            savepath = listing.SavePath;
                        }
                    }
                    else if (torrent.NumFiles == 1)
                    {
                        savepath = Path.GetDirectoryName(listing.SavePath);
                    }
                    else
                    {
                        savepath = listing.SavePath;
                    }

                    Ragnar.AddTorrentParams param = new Ragnar.AddTorrentParams()
                    {
                        SavePath = savepath,
                        TorrentInfo = torrent,
                        Name = listing.Name
                    };


                    // calling LibtorrentSession.AsyncAddTorrent will fire the TorrentAddedEvent
                    var handle = AppState.LibtorrentSession.AddTorrent(param);
                    AppState.set_files_priorities(handle, 3);
                }
                catch
                { }
            }
            App.Settings.ImportedTorrents = true;
            this.Close();
        }
Пример #8
0
        private void Import(object sender, RoutedEventArgs e)
        {
            foreach (var listing in list)
            {
                try
                {
                    if (!listing.Import)
                    {
                        continue;
                    }

                    Ragnar.TorrentInfo torrent = new Ragnar.TorrentInfo(File.ReadAllBytes(listing.Path));

                    if (!torrent.IsValid)
                    {
                        continue;
                    }

                    AppState.BackupTorrent(listing.Path, torrent);

                    string savepath = null;

                    if (torrent.NumFiles > 1)
                    {
                        if (listing.SavePath.EndsWith(torrent.Name))
                        {
                            // then we should download in the parent directory
                            DirectoryInfo di = new DirectoryInfo(listing.SavePath);
                            savepath = di.Parent.FullName;
                        }
                        else
                        {
                            savepath = listing.SavePath;
                        }
                    }
                    else if (torrent.NumFiles == 1)
                    {
                        savepath = Path.GetDirectoryName(listing.SavePath);
                    }
                    else
                    {
                        savepath = listing.SavePath;
                    }

                    Ragnar.AddTorrentParams param = new Ragnar.AddTorrentParams()
                    {
                        SavePath    = savepath,
                        TorrentInfo = torrent,
                        Name        = listing.Name
                    };


                    // calling LibtorrentSession.AsyncAddTorrent will fire the TorrentAddedEvent
                    var handle = AppState.LibtorrentSession.AddTorrent(param);
                    AppState.set_files_priorities(handle, 3);
                }
                catch
                { }
            }
            App.Settings.ImportedTorrents = true;
            this.Close();
        }