Пример #1
0
        public void RemoveTorrentAndFiles(PeriodicTorrent torrent)
        {
            torrent.Torrent.TorrentStateChanged += (s, e) =>
            {
                if (e.NewState == TorrentState.Stopped || e.NewState == TorrentState.Error)
                {
                    Client.Unregister(torrent.Torrent);
                    // Delete cache
                    if (File.Exists(torrent.CacheFilePath))
                    {
                        File.Delete(torrent.CacheFilePath);
                    }
                    if (File.Exists(Path.Combine(SettingsManager.TorrentCachePath,
                                                 Path.GetFileNameWithoutExtension(torrent.CacheFilePath) + ".info")))
                    {
                        File.Delete(Path.Combine(SettingsManager.TorrentCachePath,
                                                 Path.GetFileNameWithoutExtension(torrent.CacheFilePath) + ".info"));
                    }
                    // Delete files
                    try
                    {
                        Directory.Delete(torrent.Torrent.Path, true);
                    }
                    catch { }

                    torrent.Torrent.Dispose();
                    Application.Current.Dispatcher.BeginInvoke(new Action(() => Torrents.Remove(torrent)));
                }
            };
            Task.Factory.StartNew(() => torrent.Stop());
        }
Пример #2
0
        public void MoveTorrent(PeriodicTorrent torrent, string path)
        {
            Task.Factory.StartNew(() =>
            {
                path = Path.Combine(path, Path.GetFileName(torrent.Torrent.Path));
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                var oldPath = torrent.Torrent.Path;
                torrent.Stop();
                while (torrent.State != TorrentState.Stopped)
                {
                    ;
                }
                torrent.Torrent.MoveFiles(path, true);
                torrent.Torrent.Start();
                Directory.Delete(oldPath, true);
                torrent.Torrent.Path = torrent.Torrent.SavePath;

                var cache = Path.Combine(SettingsManager.TorrentCachePath, Path.GetFileName(oldPath));
                cache     = Path.Combine(Path.GetDirectoryName(cache), Path.GetFileName(cache)) + ".info";
                torrent.TorrentInfo.Path = torrent.Torrent.Path;
                var serializer           = new JsonSerializer();
                using (var writer = new StreamWriter(cache))
                    serializer.Serialize(new JsonTextWriter(writer), torrent.TorrentInfo);
            });
        }
Пример #3
0
 public void RemoveTorrent(PeriodicTorrent torrent)
 {
     torrent.Torrent.TorrentStateChanged += (s, e) =>
     {
         if (e.NewState == TorrentState.Stopped || e.NewState == TorrentState.Error)
         {
             torrent.Stop();
             try
             {
                 Client.Unregister(torrent.Torrent);
             }
             catch { }     // TODO: See if we need to do more
             // Delete cache
             if (File.Exists(torrent.CacheFilePath))
             {
                 File.Delete(torrent.CacheFilePath);
             }
             if (File.Exists(Path.Combine(SettingsManager.TorrentCachePath,
                                          Path.GetFileNameWithoutExtension(torrent.CacheFilePath) + ".info")))
             {
                 File.Delete(Path.Combine(SettingsManager.TorrentCachePath,
                                          Path.GetFileNameWithoutExtension(torrent.CacheFilePath) + ".info"));
             }
             torrent.Torrent.Dispose();
             // We need to delay this until we're out of the handler for some reason
             Task.Factory.StartNew(() => Application.Current.Dispatcher.BeginInvoke(new Action(() => Torrents.Remove(torrent))));
         }
     };
     Task.Factory.StartNew(() => torrent.Stop());
 }
Пример #4
0
 public PeriodicTorrent AddTorrent(TorrentWrapper torrent)
 {
     var periodicTorrent = new PeriodicTorrent(torrent);
     Task.Factory.StartNew(() =>
         {
             Client.Register(torrent);
             if (SettingsManager.StartTorrentsImmediately)
                 torrent.Start();
         });
     Application.Current.Dispatcher.BeginInvoke(new Action(() => Torrents.Add(periodicTorrent)));
     return periodicTorrent;
 }
Пример #5
0
 void PiecedProgressBar_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
 {
     Dispatcher.Invoke(new Action(() => this.InvalidateVisual()));
     var torrent = DataContext as PeriodicTorrent;
     if (torrent != null)
     {
         if (Torrent != null)
             Torrent.PropertyChanged -= torrent_PropertyChanged;
         Torrent = torrent;
         torrent.PropertyChanged += torrent_PropertyChanged;
     }
 }
Пример #6
0
 public PeriodicTorrent AddTorrent(TorrentWrapper torrent)
 {
     var periodicTorrent = new PeriodicTorrent(torrent);
     Torrents.Add(periodicTorrent);
     torrent.Index = Torrents.Count;
     Task.Factory.StartNew(() =>
         {
             Client.Register(torrent);
             torrent.Start();
         });
     return periodicTorrent;
 }
Пример #7
0
 public PeriodicTorrent AddTorrent(TorrentWrapper torrent, bool startImmediately)
 {
     // Apply settings
     torrent.Settings.UseDht = SettingsManager.EnableDHT;
     torrent.Settings.MaxConnections = SettingsManager.MaxConnectionsPerTorrent;
     torrent.Settings.MaxDownloadSpeed = SettingsManager.MaxDownloadSpeed;
     torrent.Settings.MaxUploadSpeed = SettingsManager.MaxUploadSpeed;
     torrent.Settings.UploadSlots = SettingsManager.UploadSlotsPerTorrent;
     var periodicTorrent = new PeriodicTorrent(torrent);
     Task.Factory.StartNew(() =>
         {
             Client.Register(torrent);
             if (startImmediately)
                 torrent.Start();
         });
     Application.Current.Dispatcher.BeginInvoke(new Action(() => Torrents.Add(periodicTorrent)));
     return periodicTorrent;
 }
Пример #8
0
 private void CheckTorrentSeedingGuideliens(PeriodicTorrent torrent)
 {
     if (torrent.State == TorrentState.Seeding)
     {
         if (SettingsManager.HoursToSeed != 0 &&
             (DateTime.Now - torrent.CompletionTime).TotalHours > SettingsManager.HoursToSeed)
         {
             torrent.Pause();
             return;
         }
         if (SettingsManager.TargetSeedRatio != 0 &&
             torrent.Ratio >= SettingsManager.TargetSeedRatio)
         {
             torrent.Pause();
             return;
         }
     }
 }
Пример #9
0
        public PeriodicTorrent AddTorrent(TorrentWrapper torrent, bool startImmediately)
        {
            // Apply settings
            torrent.Settings.UseDht           = SettingsManager.EnableDHT;
            torrent.Settings.MaxConnections   = SettingsManager.MaxConnectionsPerTorrent;
            torrent.Settings.MaxDownloadSpeed = SettingsManager.MaxDownloadSpeed;
            torrent.Settings.MaxUploadSpeed   = SettingsManager.MaxUploadSpeed;
            torrent.Settings.UploadSlots      = SettingsManager.UploadSlotsPerTorrent;
            var periodicTorrent = new PeriodicTorrent(torrent);

            Task.Factory.StartNew(() =>
            {
                Client.Register(torrent);
                if (startImmediately)
                {
                    torrent.Start();
                }
            });
            Application.Current.Dispatcher.BeginInvoke(new Action(() => Torrents.Add(periodicTorrent)));
            return(periodicTorrent);
        }
Пример #10
0
        public void RemoveTorrentAndFiles(PeriodicTorrent torrent)
        {
            torrent.Torrent.TorrentStateChanged += (s, e) =>
            {
                if (e.NewState == TorrentState.Stopped)
                {
                    Client.Unregister(torrent.Torrent);
                    // Delete cache
                    if (File.Exists(torrent.CacheFilePath))
                        File.Delete(torrent.CacheFilePath);
                    if (File.Exists(Path.Combine(SettingsManager.TorrentCachePath,
                        Path.GetFileNameWithoutExtension(torrent.CacheFilePath) + ".info")))
                    {
                        File.Delete(Path.Combine(SettingsManager.TorrentCachePath,
                            Path.GetFileNameWithoutExtension(torrent.CacheFilePath) + ".info"));
                    }
                    // Delete files
                    Directory.Delete(torrent.Torrent.Path, true);

                    torrent.Torrent.Dispose();
                    Application.Current.Dispatcher.BeginInvoke(new Action(() => Torrents.Remove(torrent)));
                }
            };
            Task.Factory.StartNew(() => torrent.Torrent.Stop());
        }
Пример #11
0
 public void RemoveTorrent(PeriodicTorrent torrent)
 {
     torrent.Torrent.TorrentStateChanged += (s, e) =>
         {
             if (e.NewState == TorrentState.Stopped)
             {
                 torrent.Torrent.Stop();
                 try
                 {
                     Client.Unregister(torrent.Torrent);
                 }
                 catch { } // TODO: See if we need to do more
                 // Delete cache
                 if (File.Exists(torrent.CacheFilePath))
                     File.Delete(torrent.CacheFilePath);
                 if (File.Exists(Path.Combine(SettingsManager.TorrentCachePath,
                     Path.GetFileNameWithoutExtension(torrent.CacheFilePath) + ".info")))
                 {
                     File.Delete(Path.Combine(SettingsManager.TorrentCachePath,
                         Path.GetFileNameWithoutExtension(torrent.CacheFilePath) + ".info"));
                 }
                 torrent.Torrent.Dispose();
                 // We need to delay this until we're out of the handler for some reason
                 Task.Factory.StartNew(() => Application.Current.Dispatcher.BeginInvoke(new Action(() => Torrents.Remove(torrent))));
             }
         };
     Task.Factory.StartNew(() => torrent.Torrent.Stop());
 }
Пример #12
0
 private void CheckTorrentSeedingGuideliens(PeriodicTorrent torrent)
 {
     if (torrent.State == TorrentState.Seeding)
     {
         if (SettingsManager.HoursToSeed != 0 &&
             (DateTime.Now - torrent.CompletionTime).TotalHours > SettingsManager.HoursToSeed)
         {
             torrent.Pause();
             return;
         }
         if (SettingsManager.TargetSeedRatio != 0 &&
             torrent.Ratio >= SettingsManager.TargetSeedRatio)
         {
             torrent.Pause();
             return;
         }
     }
 }
Пример #13
0
        public void MoveTorrent(PeriodicTorrent torrent, string path)
        {
            Task.Factory.StartNew(() =>
                {
                    path = Path.Combine(path, Path.GetFileName(torrent.Torrent.Path));
                    if (!Directory.Exists(path))
                        Directory.CreateDirectory(path);
                    var oldPath = torrent.Torrent.Path;
                    torrent.Stop();
                    while (torrent.State != TorrentState.Stopped) ;
                    torrent.Torrent.MoveFiles(path, true);
                    torrent.Torrent.Start();
                    Directory.Delete(oldPath, true);
                    torrent.Torrent.Path = torrent.Torrent.SavePath;

                    var cache = Path.Combine(SettingsManager.TorrentCachePath, Path.GetFileName(oldPath));
                    cache = Path.Combine(Path.GetDirectoryName(cache), Path.GetFileName(cache)) + ".info";
                    torrent.TorrentInfo.Path = torrent.Torrent.Path;
                    var serializer = new JsonSerializer();
                    using (var writer = new StreamWriter(cache))
                        serializer.Serialize(new JsonTextWriter(writer), torrent.TorrentInfo);
                });
        }
Пример #14
0
 public PeriodicTorrent LoadFastResume(FastResume resume, TorrentWrapper torrent)
 {
     var periodicTorrent = new PeriodicTorrent(torrent);
     Torrents.Add(periodicTorrent);
     torrent.Index = Torrents.Count;
     Task.Factory.StartNew(() =>
         {
             torrent.LoadFastResume(resume);
             Client.Register(torrent);
             torrent.Start();
         });
     return periodicTorrent;
 }