Exemplo n.º 1
0
        public async void ExecuteManualDownload(object parameter)
        {
            Torrent t = SelectedTorrent;

            if (await t.Download(TorrentDropDirectory))
            {
                ManuallyDownloadedTorrents.Add(t);

                RefreshAllDownloads();
            }
        }
Exemplo n.º 2
0
 public bool CanManualDownload(object parameter)
 {
     if (SelectedTorrent == null)
     {
         return(false);
     }
     else
     {
         return(!ManuallyDownloadedTorrents.Contains(SelectedTorrent));
     }
 }
Exemplo n.º 3
0
        public void ExecuteSaveBackup(object parameter)
        {
            if (!Directory.Exists(Path.GetDirectoryName(FeedsPath)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(FeedsPath));
            }

            XmlWriterSettings xws = new XmlWriterSettings()
            {
                Indent = true
            };
            DataContractSerializer dcs;

            // Feeds
            dcs = new DataContractSerializer(Feeds.GetType());
            using (XmlWriter xw = XmlWriter.Create(FeedsPath, xws))
            {
                dcs.WriteObject(xw, Feeds);
            }

            // Saves the index of SearchInFeed so that the feed can be loaded on Restore
            foreach (Filter f in Filters)
            {
                if (f.HasFeed)
                {
                    f.SearchInFeedIndex = Feeds.IndexOf(f.SearchInFeed);
                }
                else
                {
                    f.SearchInFeedIndex = -1;
                }
            }

            // Filters
            dcs = new DataContractSerializer(Filters.GetType());
            using (XmlWriter xw = XmlWriter.Create(FiltersPath, xws))
            {
                dcs.WriteObject(xw, Filters);
            }

            // Downloads
            dcs = new DataContractSerializer(ManuallyDownloadedTorrents.GetType());
            using (XmlWriter xw = XmlWriter.Create(ManuallyDownloadedTorrentsPath, xws))
            {
                dcs.WriteObject(xw, ManuallyDownloadedTorrents);
            }
        }
Exemplo n.º 4
0
        public void ExecuteRemoveDownload(object parameter)
        {
            if (ManuallyDownloadedTorrents.Contains(SelectedDownload))
            {
                ManuallyDownloadedTorrents.Remove(SelectedDownload);
            }
            else
            {
                foreach (Filter filter in Filters)
                {
                    if (filter.DownloadedTorrents.Contains(SelectedDownload))
                    {
                        filter.DownloadedTorrents.Remove(SelectedDownload);
                    }
                }
            }

            RefreshAllDownloads();
        }
Exemplo n.º 5
0
        public void ExecuteRestore(object parameter)
        {
            // TODO Implement backup of manual downloads

            using (FileStream fs = new FileStream(FeedsPath, FileMode.Open, FileAccess.Read))
            {
                DataContractSerializer dcs = new DataContractSerializer(Feeds.GetType());
                Feeds = dcs.ReadObject(fs) as ObservableCollection <Feed>;
            }

            using (FileStream fs = new FileStream(FiltersPath, FileMode.Open, FileAccess.Read))
            {
                DataContractSerializer dcs = new DataContractSerializer(Filters.GetType());
                Filters = dcs.ReadObject(fs) as ObservableCollection <Filter>;
            }

            using (FileStream fs = new FileStream(ManuallyDownloadedTorrentsPath, FileMode.Open, FileAccess.Read))
            {
                DataContractSerializer dcs = new DataContractSerializer(ManuallyDownloadedTorrents.GetType());
                ManuallyDownloadedTorrents = dcs.ReadObject(fs) as List <Torrent>;
            }

            // Uses saved indexes to load Feeds
            foreach (Filter f in Filters)
            {
                if (f.SearchInFeedIndex >= 0 && f.SearchInFeedIndex < Filters.Count)
                {
                    f.SearchInFeed = Feeds[f.SearchInFeedIndex];
                }
            }

            SelectedFeed   = Feeds[0];
            SelectedFilter = Filters[0];

            System.Windows.Application.Current.Shutdown();
        }