diff --git a/OpenBullet/Pages/Main/Settings/OBSettingsPage.xaml.cs b/OpenBullet/Pages/Main/Settings/OBSettingsPage.xaml.cs index 3c90267..05b1a66 100644 --- a/OpenBullet/Pages/Main/Settings/OBSettingsPage.xaml.cs +++ b/OpenBullet/Pages/Main/Settings/OBSettingsPage.xaml.cs @@ -73,7 +73,7 @@ namespace OpenBullet.Pages.Main.Settings private void resetButton_Click(object sender, RoutedEventArgs e) { if (MessageBox.Show("Are you sure you want to reset all your OpenBullet settings?", "Confirmation", MessageBoxButton.YesNo) == MessageBoxResult.Yes) - Globals.obSettings = new OBSettingsViewModel(); + Globals.obSettings.Reset(); } } } diff --git a/OpenBullet/Pages/Main/Settings/RLSettingsPage.xaml.cs b/OpenBullet/Pages/Main/Settings/RLSettingsPage.xaml.cs index 6a7588b..a1890eb 100644 --- a/OpenBullet/Pages/Main/Settings/RLSettingsPage.xaml.cs +++ b/OpenBullet/Pages/Main/Settings/RLSettingsPage.xaml.cs @@ -81,7 +81,7 @@ namespace OpenBullet.Pages.Main.Settings private void resetButton_Click(object sender, RoutedEventArgs e) { if (MessageBox.Show("Are you sure you want to reset all your RuriLib settings?", "Confirmation", MessageBoxButton.YesNo) == MessageBoxResult.Yes) - Globals.rlSettings = new RLSettingsViewModel(); + Globals.rlSettings.Reset(); } } } diff --git a/OpenBullet/ViewModels/OBSettings/OBSettingsGeneral.cs b/OpenBullet/ViewModels/OBSettings/OBSettingsGeneral.cs index 97f7300..a8c6281 100644 --- a/OpenBullet/ViewModels/OBSettings/OBSettingsGeneral.cs +++ b/OpenBullet/ViewModels/OBSettings/OBSettingsGeneral.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; @@ -39,5 +40,16 @@ namespace OpenBullet.ViewModels public bool DisableSyntaxHelper { get { return disableSyntaxHelper; } set { disableSyntaxHelper = value; OnPropertyChanged(); } } private bool displayCapturesLast = false; public bool DisplayCapturesLast { get { return displayCapturesLast; } set { displayCapturesLast = value; OnPropertyChanged(); } } + + public void Reset() + { + OBSettingsGeneral def = new OBSettingsGeneral(); + IList props = new List(typeof(OBSettingsGeneral).GetProperties()); + + foreach (PropertyInfo prop in props) + { + prop.SetValue(this, prop.GetValue(def, null)); + } + } } } diff --git a/OpenBullet/ViewModels/OBSettings/OBSettingsSounds.cs b/OpenBullet/ViewModels/OBSettings/OBSettingsSounds.cs index 3872e0c..6b720a5 100644 --- a/OpenBullet/ViewModels/OBSettings/OBSettingsSounds.cs +++ b/OpenBullet/ViewModels/OBSettings/OBSettingsSounds.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; @@ -15,5 +16,16 @@ namespace OpenBullet.ViewModels public string OnHitSound { get { return onHitSound; } set { onHitSound = value; OnPropertyChanged(); } } private string onReloadSound = "rifle_reload.wav"; public string OnReloadSound { get { return onReloadSound; } set { onReloadSound = value; OnPropertyChanged(); } } + + public void Reset() + { + OBSettingsSounds def = new OBSettingsSounds(); + IList props = new List(typeof(OBSettingsSounds).GetProperties()); + + foreach (PropertyInfo prop in props) + { + prop.SetValue(this, prop.GetValue(def, null)); + } + } } } diff --git a/OpenBullet/ViewModels/OBSettings/OBSettingsThemes.cs b/OpenBullet/ViewModels/OBSettings/OBSettingsThemes.cs index 34a617c..bbb9a6a 100644 --- a/OpenBullet/ViewModels/OBSettings/OBSettingsThemes.cs +++ b/OpenBullet/ViewModels/OBSettings/OBSettingsThemes.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; @@ -47,5 +48,16 @@ namespace OpenBullet.ViewModels public int SnowAmount { get { return snowAmount; } set { snowAmount = value; OnPropertyChanged(); } } private bool allowTransparency = false; public bool AllowTransparency { get { return allowTransparency; } set { allowTransparency = value; OnPropertyChanged(); } } + + public void Reset() + { + OBSettingsThemes def = new OBSettingsThemes(); + IList props = new List(typeof(OBSettingsThemes).GetProperties()); + + foreach (PropertyInfo prop in props) + { + prop.SetValue(this, prop.GetValue(def, null)); + } + } } } diff --git a/OpenBullet/ViewModels/OBSettingsViewModel.cs b/OpenBullet/ViewModels/OBSettingsViewModel.cs index 173ccc6..bad1963 100644 --- a/OpenBullet/ViewModels/OBSettingsViewModel.cs +++ b/OpenBullet/ViewModels/OBSettingsViewModel.cs @@ -1,9 +1,19 @@ -namespace OpenBullet.ViewModels +using System.Collections.Generic; +using System.Reflection; + +namespace OpenBullet.ViewModels { public class OBSettingsViewModel { public OBSettingsGeneral General { get; set; } = new OBSettingsGeneral(); public OBSettingsSounds Sounds { get; set; } = new OBSettingsSounds(); public OBSettingsThemes Themes { get; set; } = new OBSettingsThemes(); + + public void Reset() + { + General.Reset(); + Sounds.Reset(); + Themes.Reset(); + } } } diff --git a/RuriLib/ViewModels/RLSettings/SettingsCaptchas.cs b/RuriLib/ViewModels/RLSettings/SettingsCaptchas.cs index d97522e..0dcc93f 100644 --- a/RuriLib/ViewModels/RLSettings/SettingsCaptchas.cs +++ b/RuriLib/ViewModels/RLSettings/SettingsCaptchas.cs @@ -1,4 +1,7 @@ -namespace RuriLib.ViewModels +using System.Collections.Generic; +using System.Reflection; + +namespace RuriLib.ViewModels { /// /// Provides captcha-related settings. @@ -64,5 +67,19 @@ private int timeout = 120; /// The maximum amount of time to wait until a captcha challenge is solved. public int Timeout { get { return timeout; } set { timeout = value; OnPropertyChanged(); } } + + /// + /// Resets the properties to their default value. + /// + public void Reset() + { + SettingsCaptchas def = new SettingsCaptchas(); + IList props = new List(typeof(SettingsCaptchas).GetProperties()); + + foreach (PropertyInfo prop in props) + { + prop.SetValue(this, prop.GetValue(def, null)); + } + } } } diff --git a/RuriLib/ViewModels/RLSettings/SettingsGeneral.cs b/RuriLib/ViewModels/RLSettings/SettingsGeneral.cs index 1220197..4df3c6e 100644 --- a/RuriLib/ViewModels/RLSettings/SettingsGeneral.cs +++ b/RuriLib/ViewModels/RLSettings/SettingsGeneral.cs @@ -1,4 +1,7 @@ -namespace RuriLib.ViewModels +using System.Collections.Generic; +using System.Reflection; + +namespace RuriLib.ViewModels { /// /// The level of detail of a bot's status. @@ -39,5 +42,19 @@ private bool _enableBotLog = false; /// Whether to keep the LogBuffer from BotData stored for future use (slows down the Runner). public bool EnableBotLog { get { return _enableBotLog; } set { _enableBotLog = value; OnPropertyChanged(); } } + + /// + /// Resets the properties to their default value. + /// + public void Reset() + { + SettingsGeneral def = new SettingsGeneral(); + IList props = new List(typeof(SettingsGeneral).GetProperties()); + + foreach (PropertyInfo prop in props) + { + prop.SetValue(this, prop.GetValue(def, null)); + } + } } } \ No newline at end of file diff --git a/RuriLib/ViewModels/RLSettings/SettingsProxies.cs b/RuriLib/ViewModels/RLSettings/SettingsProxies.cs index a39deb0..dbf53d4 100644 --- a/RuriLib/ViewModels/RLSettings/SettingsProxies.cs +++ b/RuriLib/ViewModels/RLSettings/SettingsProxies.cs @@ -1,4 +1,6 @@ using Extreme.Net; +using System.Collections.Generic; +using System.Reflection; namespace RuriLib.ViewModels { @@ -88,5 +90,19 @@ namespace RuriLib.ViewModels /// public string[] GlobalRetryKeys { get { return globalRetryKeys; } set { globalRetryKeys = value; OnPropertyChanged(); } } #endregion + + /// + /// Resets the properties to their default value. + /// + public void Reset() + { + SettingsProxies def = new SettingsProxies(); + IList props = new List(typeof(SettingsProxies).GetProperties()); + + foreach (PropertyInfo prop in props) + { + prop.SetValue(this, prop.GetValue(def, null)); + } + } } } diff --git a/RuriLib/ViewModels/RLSettings/SettingsSelenium.cs b/RuriLib/ViewModels/RLSettings/SettingsSelenium.cs index b7d1aa1..93329f4 100644 --- a/RuriLib/ViewModels/RLSettings/SettingsSelenium.cs +++ b/RuriLib/ViewModels/RLSettings/SettingsSelenium.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Reflection; namespace RuriLib.ViewModels { @@ -45,5 +46,19 @@ namespace RuriLib.ViewModels private int pageLoadTimeout = 60; /// The default timeout for page load in the browser. public int PageLoadTimeout { get { return pageLoadTimeout; } set { pageLoadTimeout = value; OnPropertyChanged(); } } + + /// + /// Resets the properties to their default value. + /// + public void Reset() + { + SettingsSelenium def = new SettingsSelenium(); + IList props = new List(typeof(SettingsSelenium).GetProperties()); + + foreach (PropertyInfo prop in props) + { + prop.SetValue(this, prop.GetValue(def, null)); + } + } } } diff --git a/RuriLib/ViewModels/RLSettingsViewModel.cs b/RuriLib/ViewModels/RLSettingsViewModel.cs index c25a1c2..4a636f0 100644 --- a/RuriLib/ViewModels/RLSettingsViewModel.cs +++ b/RuriLib/ViewModels/RLSettingsViewModel.cs @@ -13,5 +13,16 @@ public SettingsCaptchas Captchas { get; set; } = new SettingsCaptchas(); /// The Selenium Settings of RuriLib. public SettingsSelenium Selenium { get; set; } = new SettingsSelenium(); + + /// + /// Resets the properties to their default value. + /// + public void Reset() + { + General.Reset(); + Proxies.Reset(); + Captchas.Reset(); + Selenium.Reset(); + } } }