public void SetItem(FirewallPreset firewallPreset) { FirewallPreset = firewallPreset; SuspendChange++; presetName.Content = FirewallPreset.Name; WpfFunc.CmbSelect(cmbOnAccess, FirewallPreset.OnState.ToString()); cmbOnAccess.Background = ProgramControl.GetAccessColor(FirewallPreset.OnState); WpfFunc.CmbSelect(cmbOffAccess, FirewallPreset.OffState.ToString()); cmbOffAccess.Background = ProgramControl.GetAccessColor(FirewallPreset.OffState); SuspendChange--; LoadRules(); }
private void BtnAddPresetItem_Click(object sender, RoutedEventArgs e) { if (CurrentPreset == null) { return; } List <string> Categories = new List <string>(); Categories.Add(PresetType.Tweak.ToString()); Categories.Add(PresetType.Firewall.ToString()); //Categories.Add(PresetType.Custom.ToString()); // todo: InputWnd wnd = new InputWnd(Translate.fmt("msg_preset_item"), Categories, "", false, App.Title); if (wnd.ShowDialog() != true || wnd.Value.Length == 0) { return; } PresetItem newItem = null; if (wnd.Value == PresetType.Tweak.ToString()) { List <string> TweakNames = new List <string>(); var tweaks = App.tweaks.GetAllGroups().ToList(); foreach (var tweakGroup in tweaks) { TweakNames.Add(tweakGroup.Name); } InputWnd wnd2 = new InputWnd(Translate.fmt("msg_preset_tweak"), TweakNames, "", true, App.Title); if (wnd2.ShowDialog() != true || wnd2.Value.Length == 0) { return; } var tweak = tweaks.Find(x => x.Name.Equals(wnd2.Value)); if (tweak == null) { return; } TweakPreset item = new TweakPreset(); item.Name = tweak.Name; item.TweakGroup = tweak.Name; newItem = item; } else if (wnd.Value == PresetType.Firewall.ToString()) { List <string> ProgNames = new List <string>(); var progSets = App.client.GetPrograms(); foreach (var progSet in progSets) { ProgNames.Add(progSet.config.Name); } InputWnd wnd2 = new InputWnd(Translate.fmt("msg_preset_progset"), ProgNames, "", true, App.Title); if (wnd2.ShowDialog() != true || wnd2.Value.Length == 0) { return; } ProgramSet prog = progSets.Find(x => x.config.Name.Equals(wnd2.Value)); if (prog == null) { return; } FirewallPreset item = new FirewallPreset(); item.Name = prog.config.Name; item.ProgSetId = prog.guid; newItem = item; } else if (wnd.Value == PresetType.Custom.ToString()) { InputWnd wnd2 = new InputWnd(Translate.fmt("msg_preset_item_name"), "", App.Title); if (wnd2.ShowDialog() != true || wnd2.Value.Length == 0) { return; } CustomPreset item = new CustomPreset(); item.Name = wnd2.Value; newItem = item; } if (newItem != null) { if (!newItem.Sync()) { MessageBox.Show(Translate.fmt("msg_preset_item_failed"), App.Title, MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } CurrentPreset.Items.Add(newItem.guid, newItem); PresetItemList.UpdateItems(CurrentPreset.Items.Values.ToList()); CollapseAll(); } }
public RuleItemControl(FirewallPreset.SingleRule rule, FirewallRuleEx fwRule, FirewallPreset firewallPreset) { InitializeComponent(); int CustomMode = 0; if (firewallPreset.OnState == ProgramConfig.AccessLevels.CustomConfig) { CustomMode |= 1; } if (firewallPreset.OffState == ProgramConfig.AccessLevels.CustomConfig) { CustomMode |= 2; } PrepPresetCmb(cmbPreset, this, CustomMode); FwRule = fwRule; DoUpdate(rule); rect.MouseDown += new MouseButtonEventHandler(rect_Click); label.MouseDown += new MouseButtonEventHandler(rect_Click); info.PreviewMouseDown += new MouseButtonEventHandler(rect_Click); //toggle.Click += new RoutedEventHandler(toggle_Click); }