From 952b65b387f91ec31b5a73c197ec1523c58e80e2 Mon Sep 17 00:00:00 2001 From: Chris Kaczor Date: Tue, 15 Aug 2017 16:57:24 -0400 Subject: [PATCH] Add setting for default user agent --- Application/FeedCenter.csproj | 7 -- Application/Feeds/Feed.cs | 5 +- Application/Options/GeneralOptionsPanel.xaml | 36 +++++++ .../Options/GeneralOptionsPanel.xaml.cs | 97 ++++++++++++++++++- Application/Options/OptionsWindow.xaml.cs | 1 - Application/Options/ReadingOptionsPanel.xaml | 34 ------- .../Options/ReadingOptionsPanel.xaml.cs | 64 ------------ Application/Properties/Resources.Designer.cs | 38 ++++++-- Application/Properties/Resources.resx | 12 ++- Application/Properties/Settings.Designer.cs | 15 ++- Application/Properties/Settings.settings | 3 + Application/app.config | 3 + 12 files changed, 192 insertions(+), 123 deletions(-) delete mode 100644 Application/Options/ReadingOptionsPanel.xaml delete mode 100644 Application/Options/ReadingOptionsPanel.xaml.cs diff --git a/Application/FeedCenter.csproj b/Application/FeedCenter.csproj index 4e1e368..7b31339 100644 --- a/Application/FeedCenter.csproj +++ b/Application/FeedCenter.csproj @@ -268,9 +268,6 @@ OptionsWindow.xaml - - ReadingOptionsPanel.xaml - UpdateOptionsPanel.xaml @@ -341,10 +338,6 @@ Designer MSBuild:Compile - - Designer - MSBuild:Compile - MSBuild:Compile Designer diff --git a/Application/Feeds/Feed.cs b/Application/Feeds/Feed.cs index 04c672e..bfc6784 100644 --- a/Application/Feeds/Feed.cs +++ b/Application/Feeds/Feed.cs @@ -142,7 +142,10 @@ namespace FeedCenter webRequest.Credentials = new NetworkCredential(Username, Password, Domain); // Set a user agent string - webRequest.UserAgent = "FeedCenter " + UpdateCheck.LocalVersion; + if (string.IsNullOrWhiteSpace(Properties.Settings.Default.DefaultUserAgent)) + webRequest.UserAgent = "FeedCenter/" + UpdateCheck.LocalVersion; + else + webRequest.UserAgent = Properties.Settings.Default.DefaultUserAgent; } // Set the default encoding diff --git a/Application/Options/GeneralOptionsPanel.xaml b/Application/Options/GeneralOptionsPanel.xaml index e4142a0..df41437 100644 --- a/Application/Options/GeneralOptionsPanel.xaml +++ b/Application/Options/GeneralOptionsPanel.xaml @@ -9,6 +9,14 @@ d:DesignHeight="300" d:DesignWidth="300"> + + + + + + + + @@ -17,6 +25,34 @@ Name="StartWithWindowsCheckBox" VerticalAlignment="Top" VerticalContentAlignment="Center" + Margin="0,5" Grid.ColumnSpan="2" /> + diff --git a/Application/Options/GeneralOptionsPanel.xaml.cs b/Application/Options/GeneralOptionsPanel.xaml.cs index 7d8e397..0154568 100644 --- a/Application/Options/GeneralOptionsPanel.xaml.cs +++ b/Application/Options/GeneralOptionsPanel.xaml.cs @@ -1,5 +1,15 @@ -using System.Windows; +using System.Collections.Generic; +using System.Windows; using Common.Wpf.Extensions; +using Common.Internet; +using System.Windows.Controls; +using System.Windows.Data; + +internal class UserAgentItem +{ + internal string Caption { get; set; } + internal string UserAgent { get; set; } +} namespace FeedCenter.Options { @@ -17,6 +27,10 @@ namespace FeedCenter.Options var settings = Properties.Settings.Default; StartWithWindowsCheckBox.IsChecked = settings.StartWithWindows; + + LoadBrowserComboBox(BrowserComboBox, settings.Browser); + + LoadUserAgentComboBox(UserAgentComboBox, settings.DefaultUserAgent); } public override bool ValidatePanel() @@ -28,12 +42,91 @@ namespace FeedCenter.Options { var settings = Properties.Settings.Default; - if (StartWithWindowsCheckBox.IsChecked.HasValue && settings.StartWithWindows != StartWithWindowsCheckBox.IsChecked.Value) + if (StartWithWindowsCheckBox.IsChecked.HasValue && + settings.StartWithWindows != StartWithWindowsCheckBox.IsChecked.Value) settings.StartWithWindows = StartWithWindowsCheckBox.IsChecked.Value; Application.Current.SetStartWithWindows(settings.StartWithWindows); + + settings.Browser = (string) ((ComboBoxItem) BrowserComboBox.SelectedItem).Tag; + + settings.DefaultUserAgent = (string) ((ComboBoxItem) UserAgentComboBox.SelectedItem).Tag; + + var expressions = this.GetBindingExpressions(new[] { UpdateSourceTrigger.Explicit }); + this.UpdateAllSources(expressions); } public override string CategoryName => Properties.Resources.optionCategoryGeneral; + + private static void LoadBrowserComboBox(ComboBox comboBox, string selected) + { + comboBox.SelectedIndex = 0; + + ComboBoxItem selectedItem = null; + + var browsers = Browser.DetectInstalledBrowsers(); + foreach (var browser in browsers) + { + var item = new ComboBoxItem { Content = browser.Value.Name, Tag = browser.Key }; + + comboBox.Items.Add(item); + + if (browser.Key == selected) + selectedItem = item; + } + + if (selectedItem != null) + comboBox.SelectedItem = selectedItem; + } + + private static void LoadUserAgentComboBox(ComboBox comboBox, string selected) + { + comboBox.SelectedIndex = 0; + + ComboBoxItem selectedItem = null; + + var userAgents = GetUserAgents(); + foreach (var userAgent in userAgents) + { + var item = new ComboBoxItem { Content = userAgent.Caption, Tag = userAgent.UserAgent }; + + comboBox.Items.Add(item); + + if (userAgent.UserAgent == selected) + selectedItem = item; + } + + if (selectedItem != null) + comboBox.SelectedItem = selectedItem; + } + + private static List GetUserAgents() + { + var userAgents = new List + { + new UserAgentItem + { + Caption = Properties.Resources.DefaultUserAgentCaption, + UserAgent = string.Empty + }, + new UserAgentItem + { + Caption = "Windows RSS Platform 2.0", + UserAgent = "Windows-RSS-Platform/2.0 (MSIE 9.0; Windows NT 6.1)" + }, + new UserAgentItem + { + Caption = "Feedly 1.0", + UserAgent = "Feedly/1.0" + }, + new UserAgentItem + { + Caption = "curl", + UserAgent = "curl/7.47.0" + } + }; + + return userAgents; + } } } diff --git a/Application/Options/OptionsWindow.xaml.cs b/Application/Options/OptionsWindow.xaml.cs index 6e33547..36476c5 100644 --- a/Application/Options/OptionsWindow.xaml.cs +++ b/Application/Options/OptionsWindow.xaml.cs @@ -36,7 +36,6 @@ namespace FeedCenter.Options _optionPanels.Add(new GeneralOptionsPanel()); _optionPanels.Add(new DisplayOptionsPanel()); _optionPanels.Add(new FeedsOptionsPanel()); - _optionPanels.Add(new ReadingOptionsPanel()); _optionPanels.Add(new UpdateOptionsPanel()); _optionPanels.Add(new AboutOptionsPanel()); } diff --git a/Application/Options/ReadingOptionsPanel.xaml b/Application/Options/ReadingOptionsPanel.xaml deleted file mode 100644 index 0fec025..0000000 --- a/Application/Options/ReadingOptionsPanel.xaml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - diff --git a/Application/Options/ReadingOptionsPanel.xaml.cs b/Application/Options/ReadingOptionsPanel.xaml.cs deleted file mode 100644 index 9ea94fd..0000000 --- a/Application/Options/ReadingOptionsPanel.xaml.cs +++ /dev/null @@ -1,64 +0,0 @@ -using Common.Internet; -using Common.Wpf.Extensions; -using System.Windows.Controls; -using System.Windows.Data; - -namespace FeedCenter.Options -{ - public partial class ReadingOptionsPanel - { - public ReadingOptionsPanel() - { - InitializeComponent(); - } - - public override void LoadPanel(FeedCenterEntities database) - { - base.LoadPanel(database); - - var settings = Properties.Settings.Default; - - LoadBrowserComboBox(BrowserComboBox, settings.Browser); - } - - public override bool ValidatePanel() - { - return true; - } - - public override void SavePanel() - { - var settings = Properties.Settings.Default; - - var browser = (string) ((ComboBoxItem) BrowserComboBox.SelectedItem).Tag; - - settings.Browser = browser; - - var expressions = this.GetBindingExpressions(new[] { UpdateSourceTrigger.Explicit }); - this.UpdateAllSources(expressions); - } - - public override string CategoryName => Properties.Resources.optionCategoryReading; - - private static void LoadBrowserComboBox(ComboBox comboBox, string selected) - { - comboBox.SelectedIndex = 0; - - ComboBoxItem selectedItem = null; - - var browsers = Browser.DetectInstalledBrowsers(); - foreach (var browser in browsers) - { - var item = new ComboBoxItem { Content = browser.Value.Name, Tag = browser.Key }; - - comboBox.Items.Add(item); - - if (browser.Key == selected) - selectedItem = item; - } - - if (selectedItem != null) - comboBox.SelectedItem = selectedItem; - } - } -} diff --git a/Application/Properties/Resources.Designer.cs b/Application/Properties/Resources.Designer.cs index a7b3d7d..3beb544 100644 --- a/Application/Properties/Resources.Designer.cs +++ b/Application/Properties/Resources.Designer.cs @@ -169,15 +169,6 @@ namespace FeedCenter.Properties { } } - /// - /// Looks up a localized string similar to _Browser:. - /// - public static string browserLabel { - get { - return ResourceManager.GetString("browserLabel", resourceCulture); - } - } - /// /// Looks up a localized string similar to Edit Multiple Feeds. /// @@ -470,7 +461,7 @@ namespace FeedCenter.Properties { } /// - /// Looks up a localized string similar to Default. + /// Looks up a localized string similar to < Windows Default >. /// public static string DefaultBrowserCaption { get { @@ -478,6 +469,33 @@ namespace FeedCenter.Properties { } } + /// + /// Looks up a localized string similar to Default _browser:. + /// + public static string defaultBrowserLabel { + get { + return ResourceManager.GetString("defaultBrowserLabel", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Feed Center. + /// + public static string DefaultUserAgentCaption { + get { + return ResourceManager.GetString("DefaultUserAgentCaption", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Default _user agent:. + /// + public static string defaultUserAgentLabel { + get { + return ResourceManager.GetString("defaultUserAgentLabel", resourceCulture); + } + } + /// /// Looks up a localized string similar to Delete Category. /// diff --git a/Application/Properties/Resources.resx b/Application/Properties/Resources.resx index 477699f..bc79932 100644 --- a/Application/Properties/Resources.resx +++ b/Application/Properties/Resources.resx @@ -346,11 +346,11 @@ _Register as default feed reader - - _Browser: + + Default _browser: - Default + < Windows Default > _Category: @@ -523,4 +523,10 @@ Category: {0} + + Feed Center + + + Default _user agent: + \ No newline at end of file diff --git a/Application/Properties/Settings.Designer.cs b/Application/Properties/Settings.Designer.cs index cb39435..c7ffc8c 100644 --- a/Application/Properties/Settings.Designer.cs +++ b/Application/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace FeedCenter.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.1.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); @@ -289,5 +289,18 @@ namespace FeedCenter.Properties { this["LastCategoryID"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Configuration.SettingsProviderAttribute(typeof(Common.Settings.GenericSettingsProvider))] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string DefaultUserAgent { + get { + return ((string)(this["DefaultUserAgent"])); + } + set { + this["DefaultUserAgent"] = value; + } + } } } diff --git a/Application/Properties/Settings.settings b/Application/Properties/Settings.settings index 89418d9..461a19a 100644 --- a/Application/Properties/Settings.settings +++ b/Application/Properties/Settings.settings @@ -71,5 +71,8 @@ + + + \ No newline at end of file diff --git a/Application/app.config b/Application/app.config index 850a605..678a240 100644 --- a/Application/app.config +++ b/Application/app.config @@ -60,6 +60,9 @@ + + +