示例#1
0
        /// <summary>
        /// Stops torrent and moves it to the right directory
        /// </summary>
        public async void StopAndMove()
        {
            TorrentSource.Name = Handle.TorrentFile.Name;
            await Renamer.RenameAfterDownload(this);

            TorrentSource.FinishedAt  = DateTime.Now.ToString("dd.MM.yyyy HH:mm");
            TorrentSource.HasFinished = true;
            TorrentDatabase.Edit(TorrentSource.Magnet, TorrentSource);
            torrents.Remove(this);
        }
示例#2
0
        /// <summary>
        /// Events that takes care of everything that needs to be saved before closing
        /// </summary>
        private void Main_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (dimensions != null)
            {
                if (dimensions.LastState == WindowState.Maximized)
                {
                    Properties.Settings.Default.Maximized = true;
                }
                else
                {
                    Properties.Settings.Default.Maximized = false;
                }
                Properties.Settings.Default.Resolution = dimensions.Width + "x" + dimensions.Height;
            }
            else
            {
                if (this.WindowState == WindowState.Maximized)
                {
                    Properties.Settings.Default.Maximized = true;
                }
                else
                {
                    Properties.Settings.Default.Maximized = false;
                }
                Properties.Settings.Default.Resolution = this.Width + "x" + this.Height;
            }
            Properties.Settings.Default.Save();

            if (videoPlayback)
            {
                try {
                    LocalPlayer player = (LocalPlayer)((Frame)ContentOnTop.Children[ContentOnTop.Children.Count - 1]).Content;
                    player.episode.continueAt = player.Player.MediaPosition - 50000000 > 0 ? player.Player.MediaPosition - 50000000 : 0;
                    player.episode.finished   = player.Player.MediaDuration - 3000000000 < player.Player.MediaPosition ? true : false;
                    Database.EditEpisode(player.series.id, player.episode.id, player.episode);
                    player.Player.Stop();
                    player.Player.Close();
                } catch (Exception) {
                    TorrentStreamer player = (TorrentStreamer)((Frame)ContentOnTop.Children[ContentOnTop.Children.Count - 1]).Content;
                    var             series = Database.GetSeries(player.downloader.TorrentSource.Series.id);
                    var             ep     = Database.GetEpisode(player.downloader.TorrentSource.Series.id, player.downloader.TorrentSource.Episode.id);
                    ep.continueAt = player.Player.MediaPosition - 50000000 > 0 ? player.Player.MediaPosition - 50000000 : 0;
                    ep.finished   = player.Player.MediaDuration - 3000000000 < player.Player.MediaPosition ? true : false;
                    if (player.downloader.Status.IsSeeding)
                    {
                        player.downloader.StopAndMove();
                    }
                    else
                    {
                        var torrent = player.downloader.TorrentSource;
                        torrent.IsSequential = false;
                        TorrentDatabase.Edit(torrent.Magnet, torrent);
                    }
                    Database.EditEpisode(series.id, ep.id, ep);

                    player.Player.Stop();
                    player.Player.Close();
                }

                //this will give the player some time to end properly
                Thread.Sleep(500);
            }
        }