Esempio n. 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);
        }
Esempio n. 2
0
        public void Rename(string strDirection, ListView lvFilesLeft, ListView lvFilesRight, FolderBrowserDialog folderBrowserDialog, string strSearchPatternLeft, string strSearchPatternRight)
        {
            if (MessageBox.Show(Resources.TextUI_RenameOperationWarning, Resources.TextUI_Warning, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
            {
                foreach (ListViewItem lvItemLeft in lvFilesLeft.Items)
                {
                    foreach (ListViewItem lvItemRight in lvFilesRight.Items)
                    {
                        if (lvItemLeft.SubItems[LIST_VIEW_MATCH_INDEX].Text == lvItemRight.SubItems[LIST_VIEW_MATCH_INDEX].Text && lvItemLeft.SubItems[LIST_VIEW_MATCH_INDEX].Text.Length > 0)
                        {
                            FileInfo fileInfoLeft        = new FileInfo(RenameUtils.GetFullPath(folderBrowserDialog) + "\\" + lvItemLeft.Text);
                            string   strLeftFileNameOnly = fileInfoLeft.Name;
                            strLeftFileNameOnly = strLeftFileNameOnly.Replace(fileInfoLeft.Extension.ToString(), "");

                            FileInfo fileInfoRight        = new FileInfo(RenameUtils.GetFullPath(folderBrowserDialog) + "\\" + lvItemRight.Text);
                            string   strRightFileNameOnly = fileInfoRight.Name;
                            strRightFileNameOnly = strRightFileNameOnly.Replace(fileInfoRight.Extension.ToString(), "");

                            if (strDirection == DIRECTION_LEFT)
                            {
                                File.Move(fileInfoRight.FullName, fileInfoRight.Directory.FullName + "\\" + strLeftFileNameOnly + fileInfoRight.Extension);
                                LogUtils.AddLogTextLine("Renamed " + fileInfoRight.FullName + " to " + fileInfoRight.Directory.FullName + "\\" + strLeftFileNameOnly + fileInfoRight.Extension);
                                lvItemLeft.SubItems[LIST_VIEW_MATCH_INDEX].Text  = "";
                                lvItemRight.SubItems[LIST_VIEW_MATCH_INDEX].Text = "";
                            }
                            else
                            {
                                File.Move(fileInfoLeft.FullName, fileInfoLeft.Directory.FullName + "\\" + strRightFileNameOnly + fileInfoLeft.Extension);
                                LogUtils.AddLogTextLine("Renamed " + fileInfoLeft.FullName + " to " + fileInfoLeft.Directory.FullName + "\\" + strRightFileNameOnly + fileInfoLeft.Extension);
                                lvItemLeft.SubItems[LIST_VIEW_MATCH_INDEX].Text  = "";
                                lvItemRight.SubItems[LIST_VIEW_MATCH_INDEX].Text = "";
                            }
                        }
                    }
                }
                RenameUtils.PopulateFiles(lvFilesLeft, strSearchPatternLeft, folderBrowserDialog);
                RenameUtils.PopulateFiles(lvFilesRight, strSearchPatternRight, folderBrowserDialog);
            }
        }
Esempio n. 3
0
 public static void ClearMathingLeftRight(ListView lvFilesLeft, ListView lvFilesRight)
 {
     RenameUtils.ClearMatchStatus(lvFilesLeft);
     RenameUtils.ClearMatchStatus(lvFilesRight);
     LogUtils.AddLogTextLine("Matching cleared.");
 }
Esempio n. 4
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);
        }
Esempio n. 5
0
        public static void PopulateFiles(ListView lvFiles, string searchPattern, FolderBrowserDialog folderBrowserDialog)
        {
            //Populate listview with files
            string[] lvData = new string[4];

            //clear list
            InitListView(lvFiles);

            //check path
            if (Directory.Exists((string)GetFullPath(folderBrowserDialog)) == false)
            {
                MessageBox.Show(Resources.TextUI_DirectoryDoesNotExist);
            }
            else
            {
                try
                {
                    string[] stringFiles    = GetFiles(GetFullPath(folderBrowserDialog), searchPattern, SearchOption.TopDirectoryOnly);
                    string   stringFileName = "";
                    DateTime dtModifyDate;
                    Int64    lFileSize = 0;

                    //loop throught all files
                    foreach (string stringFile in stringFiles)
                    {
                        stringFileName = stringFile;
                        FileInfo objFileSize = new FileInfo(stringFileName);
                        lFileSize    = objFileSize.Length;
                        dtModifyDate = objFileSize.LastWriteTime; //GetLastWriteTime(stringFileName);

                        //create listview data
                        lvData[0] = RenameUtils.GetPathName(stringFileName);
                        lvData[1] = RenameUtils.FormatSize(lFileSize);

                        //check if file is in local current day light saving time
                        if (TimeZone.CurrentTimeZone.IsDaylightSavingTime(dtModifyDate) == false)
                        {
                            //not in day light saving time adjust time
                            lvData[2] = RenameUtils.FormatDate(dtModifyDate.AddHours(1));
                        }
                        else
                        {
                            //not in day light saving time adjust time
                            lvData[2] = RenameUtils.FormatDate(dtModifyDate);
                        }

                        //Create actual list item
                        ListViewItem lvItem = new ListViewItem(lvData, 0);
                        lvFiles.Items.Add(lvItem);
                    }
                }
                catch (IOException e)
                {
                    MessageBox.Show(Resources.TextUI_Error_DriveNotReady + e.Message);
                }
                catch (UnauthorizedAccessException e)
                {
                    MessageBox.Show(Resources.TextUI_Error_DriveAccessDenied + e.Message);
                }
                catch (Exception e)
                {
                    MessageBox.Show(Resources.TextUI_Error + e.Message);
                }
            }
        }