Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
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();
        }