コード例 #1
0
ファイル: BatchEditor.cs プロジェクト: yanisdreemurr/PKHeX
        private void RunBackgroundWorker()
        {
            if (RTB_Instructions.Lines.Any(line => line.Length == 0))
            {
                WinFormsUtil.Error(MsgBEInstructionInvalid); return;
            }

            var sets = StringInstructionSet.GetBatchSets(RTB_Instructions.Lines).ToArray();

            if (sets.Any(s => s.Filters.Any(z => string.IsNullOrWhiteSpace(z.PropertyValue))))
            {
                WinFormsUtil.Error(MsgBEFilterEmpty); return;
            }

            if (sets.Any(z => z.Instructions.Count == 0))
            {
                WinFormsUtil.Error(MsgBEInstructionNone); return;
            }

            var emptyVal = sets.SelectMany(s => s.Instructions.Where(z => string.IsNullOrWhiteSpace(z.PropertyValue))).ToArray();

            if (emptyVal.Length > 0)
            {
                string props   = string.Join(", ", emptyVal.Select(z => z.PropertyName));
                string invalid = MsgBEPropertyEmpty + Environment.NewLine + props;
                if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, invalid, MsgContinue))
                {
                    return;
                }
            }

            string?destPath = null;

            if (RB_Path.Checked)
            {
                WinFormsUtil.Alert(MsgExportFolder, MsgExportFolderAdvice);
                using var fbd = new FolderBrowserDialog();
                var dr = fbd.ShowDialog();
                if (dr != DialogResult.OK)
                {
                    return;
                }

                destPath = fbd.SelectedPath;
            }

            FLP_RB.Enabled = RTB_Instructions.Enabled = B_Go.Enabled = false;

            foreach (var set in sets)
            {
                BatchEditing.ScreenStrings(set.Filters);
                BatchEditing.ScreenStrings(set.Instructions);
            }
            RunBatchEdit(sets, TB_Folder.Text, destPath);
        }
コード例 #2
0
        public static IEnumerable <PKM> FilterByBatchInstruction(IEnumerable <PKM> res, IList <string> BatchInstructions)
        {
            if (BatchInstructions?.All(string.IsNullOrWhiteSpace) != false)
            {
                return(res); // none specified;
            }
            var lines   = BatchInstructions.Where(z => !string.IsNullOrWhiteSpace(z));
            var filters = StringInstruction.GetFilters(lines).ToArray();

            BatchEditing.ScreenStrings(filters);
            return(res.Where(pkm => BatchEditing.IsFilterMatch(filters, pkm))); // Compare across all filters
        }
コード例 #3
0
        public static IEnumerable <StringInstruction>?GetEncounterFilters(IEnumerable <string> lines)
        {
            var valid = lines.Where(z => z.StartsWith(EncounterFilterPrefix.ToString())).ToList();

            if (valid.Count == 0)
            {
                return(null);
            }
            var cleaned = valid.Select(z => z.TrimStart(EncounterFilterPrefix));
            var filters = StringInstruction.GetFilters(cleaned).ToArray();

            BatchEditing.ScreenStrings(filters);
            return(filters);
        }
コード例 #4
0
        // View Updates
        private IEnumerable <PKM> SearchDatabase()
        {
            // Populate Search Query Result
            IEnumerable <PKM> res = RawDB;

            // Filter for Selected Source
            if (!Menu_SearchBoxes.Checked)
            {
                res = res.Where(pk => pk.Identifier.StartsWith(DatabasePath + Path.DirectorySeparatorChar, StringComparison.Ordinal));
            }
            if (!Menu_SearchDatabase.Checked)
            {
                res = res.Where(pk => !pk.Identifier.StartsWith(DatabasePath + Path.DirectorySeparatorChar, StringComparison.Ordinal));
#if LOADALL
                res = res.Where(pk => !pk.Identifier.StartsWith(EXTERNAL_SAV, StringComparison.Ordinal));
#endif
            }

            int format = MAXFORMAT + 1 - CB_Format.SelectedIndex;
            switch (CB_FormatComparator.SelectedIndex)
            {
            case 0: /* Do nothing */ break;

            case 1: res = res.Where(pk => pk.Format >= format); break;

            case 2: res = res.Where(pk => pk.Format == format); break;

            case 3: res = res.Where(pk => pk.Format <= format); break;
            }
            if (CB_FormatComparator.SelectedIndex != 0)
            {
                if (format <= 2) // 1-2
                {
                    res = res.Where(pk => pk.Format <= 2);
                }
                if (format >= 3 && format <= 6) // 3-6
                {
                    res = res.Where(pk => pk.Format >= 3);
                }
            }

            switch (CB_Generation.SelectedIndex)
            {
            case 0: /* Do nothing */ break;

            case 1: res = res.Where(pk => pk.Gen7); break;

            case 2: res = res.Where(pk => pk.Gen6); break;

            case 3: res = res.Where(pk => pk.Gen5); break;

            case 4: res = res.Where(pk => pk.Gen4); break;

            case 5: res = res.Where(pk => pk.Gen3); break;
            }

            // Primary Searchables
            int species = WinFormsUtil.GetIndex(CB_Species);
            int ability = WinFormsUtil.GetIndex(CB_Ability);
            int nature  = WinFormsUtil.GetIndex(CB_Nature);
            int item    = WinFormsUtil.GetIndex(CB_HeldItem);
            if (species != -1)
            {
                res = res.Where(pk => pk.Species == species);
            }
            if (ability != -1)
            {
                res = res.Where(pk => pk.Ability == ability);
            }
            if (nature != -1)
            {
                res = res.Where(pk => pk.Nature == nature);
            }
            if (item != -1)
            {
                res = res.Where(pk => pk.HeldItem == item);
            }

            // Secondary Searchables
            int move1 = WinFormsUtil.GetIndex(CB_Move1);
            int move2 = WinFormsUtil.GetIndex(CB_Move2);
            int move3 = WinFormsUtil.GetIndex(CB_Move3);
            int move4 = WinFormsUtil.GetIndex(CB_Move4);
            var moves = new[] { move1, move2, move3, move4 }.Where(z => z > 0).ToList();
            int count = moves.Count;
            if (count > 0)
            {
                res = res.Where(pk => pk.Moves.Intersect(moves).Count() == count);
            }
            int vers = WinFormsUtil.GetIndex(CB_GameOrigin);
            if (vers != -1)
            {
                res = res.Where(pk => pk.Version == vers);
            }
            int hptype = WinFormsUtil.GetIndex(CB_HPType);
            if (hptype != -1)
            {
                res = res.Where(pk => pk.HPType == hptype);
            }
            if (CHK_Shiny.CheckState == CheckState.Checked)
            {
                res = res.Where(pk => pk.IsShiny);
            }
            if (CHK_Shiny.CheckState == CheckState.Unchecked)
            {
                res = res.Where(pk => !pk.IsShiny);
            }
            if (CHK_IsEgg.CheckState == CheckState.Checked)
            {
                res = res.Where(pk => pk.IsEgg);
            }
            if (CHK_IsEgg.CheckState == CheckState.Unchecked)
            {
                res = res.Where(pk => !pk.IsEgg);
            }
            if (CHK_IsEgg.CheckState == CheckState.Checked && int.TryParse(MT_ESV.Text, out int esv))
            {
                res = res.Where(pk => pk.PSV == esv);
            }

            // Tertiary Searchables
            res = FilterByLVL(res, CB_Level.SelectedIndex, TB_Level.Text);
            res = FilterByIVs(res, CB_IV.SelectedIndex);
            res = FilterByEVs(res, CB_EVTrain.SelectedIndex);

            slotSelected = -1; // reset the slot last viewed

            if (Menu_SearchLegal.Checked && !Menu_SearchIllegal.Checked)
            {
                res = res.Where(pk => new LegalityAnalysis(pk).Valid);
            }
            if (!Menu_SearchLegal.Checked && Menu_SearchIllegal.Checked)
            {
                res = res.Where(pk => !new LegalityAnalysis(pk).Valid);
            }

            if (RTB_Instructions.Lines.Any(line => line.Length > 0))
            {
                var filters = StringInstruction.GetFilters(RTB_Instructions.Lines).ToArray();
                BatchEditing.ScreenStrings(filters);
                res = res.Where(pkm => BatchEditing.IsFiltered(filters, pkm)); // Compare across all filters
            }

            if (Menu_SearchClones.Checked)
            {
                res = res.GroupBy(Hash).Where(group => group.Count() > 1).SelectMany(z => z);
            }

            return(res);
        }
コード例 #5
0
        // View Updates
        private void B_Search_Click(object sender, EventArgs e)
        {
            // Populate Search Query Result
            IEnumerable <MysteryGift> res = RawDB;

            int format = MAXFORMAT + 1 - CB_Format.SelectedIndex;

            switch (CB_FormatComparator.SelectedIndex)
            {
            case 0: /* Do nothing */ break;

            case 1: res = res.Where(mg => mg.Format >= format); break;

            case 2: res = res.Where(mg => mg.Format == format); break;

            case 3: res = res.Where(mg => mg.Format <= format); break;
            }

            // Primary Searchables
            int species = WinFormsUtil.GetIndex(CB_Species);
            int item    = WinFormsUtil.GetIndex(CB_HeldItem);

            if (species != -1)
            {
                res = res.Where(pk => pk.Species == species);
            }
            if (item != -1)
            {
                res = res.Where(pk => pk.HeldItem == item);
            }

            // Secondary Searchables
            int move1 = WinFormsUtil.GetIndex(CB_Move1);
            int move2 = WinFormsUtil.GetIndex(CB_Move2);
            int move3 = WinFormsUtil.GetIndex(CB_Move3);
            int move4 = WinFormsUtil.GetIndex(CB_Move4);

            if (move1 != -1)
            {
                res = res.Where(mg => mg.HasMove(move1));
            }
            if (move2 != -1)
            {
                res = res.Where(mg => mg.HasMove(move2));
            }
            if (move3 != -1)
            {
                res = res.Where(mg => mg.HasMove(move3));
            }
            if (move4 != -1)
            {
                res = res.Where(mg => mg.HasMove(move4));
            }
            if (CHK_Shiny.CheckState == CheckState.Checked)
            {
                res = res.Where(pk => pk.IsShiny);
            }
            if (CHK_Shiny.CheckState == CheckState.Unchecked)
            {
                res = res.Where(pk => !pk.IsShiny);
            }
            if (CHK_IsEgg.CheckState == CheckState.Checked)
            {
                res = res.Where(pk => pk.IsEgg);
            }
            if (CHK_IsEgg.CheckState == CheckState.Unchecked)
            {
                res = res.Where(pk => !pk.IsEgg);
            }

            slotSelected = -1; // reset the slot last viewed

            if (RTB_Instructions.Lines.Any(line => line.Length > 0))
            {
                var filters = StringInstruction.GetFilters(RTB_Instructions.Lines).ToArray();
                BatchEditing.ScreenStrings(filters);
                res = res.Where(pkm => BatchEditing.IsFilterMatch(filters, pkm)); // Compare across all filters
            }

            var results = res.ToArray();

            if (results.Length == 0)
            {
                WinFormsUtil.Alert(MsgDBSearchNone);
            }

            SetResults(new List <MysteryGift>(results)); // updates Count Label as well.
            System.Media.SystemSounds.Asterisk.Play();
        }