示例#1
0
        public int DeepMatchListViews(ListView lvFilesLeft, ListView lvFilesRight, ToolStripProgressBar pbProgres, ComboBox cbRegexes)
        {
            int matchCounter = 0;

            pbProgres.Value = 0;
            LogUtils.AddLogTextLine("Deep matching operation started.");

            RenameUtils.ClearMathingLeftRight(lvFilesLeft, lvFilesRight);

            foreach (var item in cbRegexes.Items)
            {
                string regex = item.GetType().GetProperty("Value").GetValue(item, null).ToString();
                matchCounter += AutoMatchListViews(lvFilesLeft, lvFilesRight, pbProgres, true, regex, true, false);
            }

            matchCounter += AutoMatchListViews(lvFilesLeft, lvFilesRight, pbProgres, false, "", true, false);

            pbProgres.Value = 100;
            return(matchCounter);
        }
示例#2
0
        public int AutoMatchListViews(ListView lvFilesLeft, ListView lvFilesRight, ToolStripProgressBar pbProgres, bool flagUseComplexRegex, string strRegex, bool flagUseFastRendering, bool flagClearMatching)
        {
            int matchCounter = 0;

            if (flagClearMatching)
            {
                RenameUtils.ClearMathingLeftRight(lvFilesLeft, lvFilesRight);
            }

            LogUtils.AddLogTextLine("Auto matching operation " + (flagUseComplexRegex ? "with " : "without ") + "regex support " + (flagUseFastRendering ? "using " : "not using ") + "fast rendering.");

            pbProgres.Value = 0;
            foreach (ListViewItem lvItem in lvFilesLeft.Items)
            {
                //if matching done - skip
                if (lvItem.SubItems[LIST_VIEW_MATCH_INDEX].Text != string.Empty)
                {
                    continue;
                }

                string strLeftFileName  = GetFilenameWithoutExtension(lvItem.Text);
                string strKeyNumberLeft = RenameUtils.ExtractNumbers(strLeftFileName, flagUseComplexRegex ? strRegex : String.Empty);

                if (strKeyNumberLeft == "")
                {
                    //MessageBox.Show("CONTINUE 1");
                    continue;
                }

                int.TryParse(strKeyNumberLeft, out int uniqueLeftFileId);

                foreach (ListViewItem lvRightItem in lvFilesRight.Items)
                {
                    //if matching done - skip
                    if (lvRightItem.SubItems[LIST_VIEW_MATCH_INDEX].Text != string.Empty)
                    {
                        continue;
                    }

                    string strRightFileName  = GetFilenameWithoutExtension(lvRightItem.Text);
                    string strKeyNumberRight = RenameUtils.ExtractNumbers(strRightFileName, flagUseComplexRegex ? strRegex : String.Empty);

                    if (strKeyNumberRight == "")
                    {
                        //MessageBox.Show("CONTINUE 2");
                        continue;
                    }

                    int.TryParse(strKeyNumberRight, out int uniqueRightFileId);

                    //MessageBox.Show(strKeyNumberLeft + " : " + uniqueLeftFileId.ToString() + " || " + strKeyNumberRight + " : " + uniqueRightFileId.ToString());

                    if ((!flagUseComplexRegex && uniqueLeftFileId == uniqueRightFileId) ||
                        (flagUseComplexRegex && (strKeyNumberLeft.Contains(strKeyNumberRight) || strKeyNumberRight.Contains(strKeyNumberLeft))))
                    {
                        lvItem.Checked      = true;
                        lvRightItem.Checked = true;
                        this.MatchLeftRight(lvFilesLeft, lvFilesRight);
                        matchCounter++;
                        if (!flagUseFastRendering)
                        {
                            lvFilesLeft.Refresh();//for special effect.
                            lvFilesRight.Refresh();
                        }
                        break;
                    }
                }

                pbProgres.Value = (int)((decimal)(lvItem.Index + 1.00) * (decimal)(100.00 / lvFilesLeft.Items.Count));
            }

            pbProgres.Value = 100;
            return(matchCounter);
        }