private void Window_Loaded(object sender, RoutedEventArgs e) { local = (Settings)Utility.CloneObject(App.Settings); this.DataContext = local; this.themeCombox.ItemsSource = theme_list; this.themeCombox.SelectedItem = local.Theme; TrayIconComboBoxes = new ComboBox[] { tcb, tdcb, trcb }; WindowComboBoxes = new ComboBox[] { mb, cb }; Utility.SetItemsSource<ComboBox>(TrayIconComboBoxes, TrayIconBehaviorsReadable); Utility.SetItemsSource<ComboBox>(WindowComboBoxes, WindowBehaviorsReadable); enctype.ItemsSource = EncryptionTypesReadable; LoadNetworkInterfaces(); styleCombox.SelectedIndex = local.ApplicationStyle; styleCombox.SelectionChanged += this.ReloadStyle; LoadLangs(); }
private void UpdateDataContext(Settings s) { this.DataContext = s; this.themeCombox.SelectedItem = s == null ? Theme.Aero2 : s.Theme; }
public static void Save(Settings s, string path) { Utility.Serialize<Settings>(s, path); }
private void ResetToDefaultSettings(object sender, RoutedEventArgs e) { local = (Settings)Utility.CloneObject(Settings.DefaultSettings); UpdateDataContext(null); UpdateDataContext(local); }
public static Settings CompleteNullProperties(Settings s) { Type type = s.GetType(); PropertyInfo[] props = type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); Settings default_settings = Settings.DefaultSettings; foreach (PropertyInfo prop in props) { if (prop.PropertyType == typeof(Boolean)) { continue; } if (prop.CanWrite) { try { var value = prop.GetValue(s, null); if (value == null || value.Equals(Utility.GetDefault(value.GetType()))) { if (prop.PropertyType.IsValueType || prop.PropertyType.IsEnum || prop.PropertyType.Equals(typeof(System.String))) { prop.SetValue(s, prop.GetValue(default_settings, null), null); } } } catch { } } } if (s.OutgoingPortsRandom == false && s.OutgoingPortsEnd == s.OutgoingPortsStart && s.OutgoingPortsStart == 0) { s.OutgoingPortsRandom = default_settings.OutgoingPortsRandom; s.OutgoingPortsStart = default_settings.OutgoingPortsStart; s.OutgoingPortsEnd = default_settings.OutgoingPortsEnd; } // this is a rather special case, for upgrading users if ((s.PreviousPaths == Settings.DefaultSettings.PreviousPaths || s.PreviousPaths.Count == 0) && s.DefaultDownloadPath != null) s.PreviousPaths = new List<string>() { s.DefaultDownloadPath }; return s; }