예제 #1
0
        private void category_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (SuspendChange > 0)
            {
                return;
            }

            CategoryModel.Category cat = (category.SelectedItem as CategoryModel.Category);

            string Value;

            if (cat.SpecialCat == CategoryModel.Category.Special.AddNew)
            {
                InputWnd wnd = new InputWnd(Translate.fmt("msg_cat_name"), Translate.fmt("msg_cat_some"), App.mName);
                if (wnd.ShowDialog() != true || wnd.Value.Length == 0)
                {
                    return;
                }

                Value = wnd.Value;

                Value = Value.Replace(',', '.'); // this is our separator so it cant be in the name

                bool found = false;
                foreach (CategoryModel.Category curCat in CatModel.Categorys)
                {
                    if (Value.Equals((curCat.Content as String), StringComparison.OrdinalIgnoreCase))
                    {
                        found = true;
                    }
                }
                if (!found)
                {
                    CatModel.Categorys.Insert(0, new CategoryModel.Category()
                    {
                        Content = Value, Group = Translate.fmt("cat_cats")
                    });
                    category.SelectedIndex = 0;
                }
            }
            else if (cat.SpecialCat == CategoryModel.Category.Special.SetNone)
            {
                Value = "";
            }
            else
            {
                Value = (cat.Content as String);
            }

            Program.config.Category = Value;
            App.itf.UpdateProgram(Program.guid, Program.config);
        }
예제 #2
0
        private void BtnAddPreset_Click(object sender, RoutedEventArgs e)
        {
            InputWnd wnd = new InputWnd(Translate.fmt("msg_preset_name"), Translate.fmt("msg_preset_some"), App.Title);

            if (wnd.ShowDialog() != true || wnd.Value.Length == 0)
            {
                return;
            }

            var newPreset = new PresetGroup();

            newPreset.Name = wnd.Value;
            App.presets.UpdatePreset(newPreset);
        }
예제 #3
0
        public static string SelectTweakName()
        {
            List <string> PresetNames = new List <string>();

            foreach (var preset in App.presets.Presets.Values)
            {
                PresetNames.Add(preset.Name);
            }

            InputWnd wnd = new InputWnd(Translate.fmt("msg_preset_select"), PresetNames, "", true, App.Title);

            if (wnd.ShowDialog() != true || wnd.Value.Length == 0)
            {
                return(null);
            }

            return(wnd.Value);
        }
예제 #4
0
        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();
            }
        }