예제 #1
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());
 }
예제 #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 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());
        }
예제 #4
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());
        }
예제 #5
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());
 }
예제 #6
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);
                });
        }