예제 #1
0
 public void LoadInfo(TorrentInfo info)
 {
     TorrentInfo    = info;
     Label          = TorrentInfo.Label;
     CompletionTime = TorrentInfo.CompletionTime;
     Torrent.Settings.MaxConnections     = info.MaxConnections;
     Torrent.Settings.MaxDownloadSpeed   = info.MaxDownloadSpeed;
     Torrent.Settings.MaxUploadSpeed     = info.MaxUploadSpeed;
     Torrent.Settings.UploadSlots        = info.UploadSlots;
     Torrent.Settings.UseDht             = info.EnableDHT;
     Torrent.Settings.EnablePeerExchange = info.EnablePeerExchange;
 }
예제 #2
0
 public PeriodicTorrent(TorrentWrapper wrapper)
 {
     TorrentInfo = new TorrentInfo();
     Torrent = wrapper;
     PeerList = new ObservableCollection<PeerId>();
     Update();
     Name = Torrent.Name;
     Size = Torrent.Size;
     CompletedOnAdd = Torrent.Complete;
     CompletionTime = DateTime.MinValue;
     NotifiedComplete = false;
     PiecePicker = new RandomisedPicker(new StandardPicker());
     wrapper.PieceManager.BlockReceived += PieceManager_BlockReceived;
     wrapper.PieceHashed += wrapper_PieceHashed;
     TorrentInfo.Path = Torrent.Path;
     PausedFromSeeding = false;
 }
예제 #3
0
        public PeriodicTorrent(TorrentWrapper wrapper)
        {
            TorrentInfo = new TorrentInfo();
            Torrent     = wrapper;
            PeerList    = new ObservableCollection <PeerId>();

            Name             = Torrent.Name;
            Size             = Torrent.Size;
            CompletedOnAdd   = Torrent.Complete;
            CompletionTime   = DateTime.MinValue;
            NotifiedComplete = false;
            PiecePicker      = new RandomisedPicker(new StandardPicker());
            wrapper.PieceManager.BlockReceived += PieceManager_BlockReceived;
            wrapper.PieceHashed += wrapper_PieceHashed;
            TorrentInfo.Path     = Torrent.Path;
            PausedFromSeeding    = false;
            StoppedByUser        = false;
            ExcludeFromQueue     = false;
            Update(false);
        }
예제 #4
0
 public void LoadInfo(TorrentInfo info)
 {
     TorrentInfo = info;
     Label = TorrentInfo.Label;
     CompletionTime = TorrentInfo.CompletionTime;
     Torrent.Settings.MaxConnections = info.MaxConnections;
     Torrent.Settings.MaxDownloadSpeed = info.MaxDownloadSpeed;
     Torrent.Settings.MaxUploadSpeed = info.MaxUploadSpeed;
     Torrent.Settings.UploadSlots = info.UploadSlots;
     Torrent.Settings.UseDht = info.EnableDHT;
     Torrent.Settings.EnablePeerExchange = info.EnablePeerExchange;
 }
예제 #5
0
        private void ImportTorrents()
        {
            var patchy = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ".patchy");
            var torrentcache = Path.Combine(patchy, "torrentcache");

            var uTorrent = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "uTorrent");
            var transmission = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "transmission");

            var serializer = new JsonSerializer();

            Directory.CreateDirectory(patchy);
            Directory.CreateDirectory(Path.Combine(patchy, torrentcache));

            if (uTorrentImportCheckBox.IsChecked.Value)
            {
                try
                {
                    if (Directory.Exists(uTorrent))
                    {
                        var torrents = Directory.GetFiles(uTorrent, "*.torrent");
                        BEncodedDictionary dictionary;
                        if (File.Exists(Path.Combine(uTorrent, "resume.dat")))
                        {
                            using (var stream = File.OpenRead(Path.Combine(uTorrent, "resume.dat")))
                                dictionary = (BEncodedDictionary)BEncodedDictionary.Decode(stream);
                            foreach (var torrent in torrents)
                            {
                                if (dictionary.ContainsKey(Path.GetFileName(torrent)))
                                {
                                    // Add torrent
                                    var info = new TorrentInfo
                                    {
                                        Label = new TorrentLabel("µTorrent", "#00853F") { Foreground = "#FFFFFF" },
                                        Path = ((BEncodedDictionary)dictionary[Path.GetFileName(torrent)])["path"].ToString()
                                    };
                                    using (var json = new StreamWriter(Path.Combine(torrentcache,
                                        Path.GetFileNameWithoutExtension(torrent) + ".info")))
                                        serializer.Serialize(new JsonTextWriter(json), info);
                                    File.Copy(torrent, Path.Combine(torrentcache, Path.GetFileName(torrent)));
                                }
                            }
                        }
                    }
                }
                catch { MessageBox.Show("Failed to import from uTorrent.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); }
            }
            if (transmissionImportCheckBox.IsChecked.Value)
            {
                try
                {
                    if (Directory.Exists(transmission))
                    {
                        var torrents = Directory.GetFiles(Path.Combine(transmission, "Torrents"), "*.torrent");
                        var dictionaries = Path.Combine(transmission, "Resume");
                        foreach (var torrent in torrents)
                        {
                            if (File.Exists(Path.Combine(dictionaries,
                                Path.GetFileNameWithoutExtension(torrent) + ".resume")))
                            {
                                BEncodedDictionary dictionary;
                                using (var stream = File.OpenRead(Path.Combine(dictionaries,
                                    Path.GetFileNameWithoutExtension(torrent) + ".resume")))
                                    dictionary = (BEncodedDictionary)BEncodedDictionary.Decode(stream);
                                // Add torrent
                                var name = dictionary["name"].ToString();
                                var info = new TorrentInfo
                                {
                                    Label = new TorrentLabel("Transmission", "#DA0000") { Foreground = "#FFFFFF" },
                                    Path = dictionary["destination"].ToString()
                                };
                                using (var json = new StreamWriter(Path.Combine(torrentcache, name + ".info")))
                                    serializer.Serialize(new JsonTextWriter(json), info);
                                File.Copy(torrent, Path.Combine(torrentcache, name + ".torrent"));
                            }
                        }
                    }
                }
                catch { MessageBox.Show("Failed to import from Transmission.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); }
            }
        }