Example #1
0
        private DataGridViewRow AddRow(DuplicateArchiveInfo data)
        {
            int             index = dgvResult.Rows.Add();
            DataGridViewRow row   = dgvResult.Rows[index];

            row.Cells["colCheck"].Value    = false;
            row.Cells["colFilename"].Value = data.Filename;
            if (data.MatchType == MatchType.ORIGINAL)
            {
                row.DefaultCellStyle.BackColor = Color.DarkGray;
            }
            else if (data.MatchType == MatchType.EQUALCOUNT)
            {
                row.DefaultCellStyle.BackColor = Color.LightGray;
            }

            row.Cells["colPercentage"].Value       = data.MatchType == MatchType.ORIGINAL ? "" : data.Percentage.ToString();
            row.Cells["colMatchType"].Value        = data.MatchType.ToString();
            row.Cells["colItemsCount"].Value       = data.Items.Count;
            row.Cells["colItemsCount"].ToolTipText = String.Format("File Count: {0}\r\nDir Count: {1}", data.Items.Count, data.DirectoryCount);

            if (data.NoMatches != null)
            {
                row.Cells["colNoMatchesCount"].Value       = data.NoMatches.Count > 0 ? data.NoMatches.Count.ToString() : "";
                row.Cells["colNoMatchesCount"].ToolTipText = ConcatItem(data.NoMatches);
            }

            row.Cells["colSize"].Value         = data.RealSize.ToString();
            row.Cells["colArchivedSize"].Value = data.ArchivedSize.ToString();
            row.Cells["colDupGroup"].Value     = data.MatchType == MatchType.ORIGINAL ? data.DupGroup.ToString("D4") : data.DupGroup.ToString("D4") + " ";
            row.Cells["colFileSize"].Value     = data.FileSize;
            row.Cells["colCreationTime"].Value = data.CreationTime;

            if (data.Skipped != null)
            {
                row.Cells["colSkipped"].Value       = data.Skipped.Count;
                row.Cells["colSkipped"].ToolTipText = ConcatItem(data.Skipped);
                row.Cells["colItemsCount"].Value    = data.Items.Count + " (" + (data.Items.Count + data.Skipped.Count) + ")";
            }
            else
            {
                row.Cells["colSkipped"].ToolTipText = "";
            }

            if (data.Skipped != null && data.Skipped.Count > 0)
            {
                row.DefaultCellStyle.Font = new Font(row.InheritedStyle.Font, FontStyle.Italic);
            }

            row.Cells["colCrc"].Value    = data.ToCRCString();
            row.Cells["colStatus"].Value = "";

            return(row);
        }
Example #2
0
        private DataGridViewRow AddRowSep(DuplicateArchiveInfo data)
        {
            int             index = dgvResult.Rows.Add();
            DataGridViewRow row   = dgvResult.Rows[index];

            row.DefaultCellStyle.BackColor = Color.Black;

            row.ReadOnly = true;
            var cellCheck = new HMergedCell();

            cellCheck.LeftColumn  = 0;
            cellCheck.RightColumn = 1;
            cellCheck.Value       = data.DupGroup.ToString("D4");
            row.Cells["colCheck"] = cellCheck;

            var cellGroup = new HMergedCell();

            cellGroup.LeftColumn     = 0;
            cellGroup.RightColumn    = 1;
            cellGroup.Value          = data.DupGroup.ToString("D4");
            row.Cells["colDupGroup"] = cellGroup;

            string filenameOnly = data.Filename.Substring(data.Filename.LastIndexOf("\\") + 1);

            row.Cells["colFilename"] = new HMergedCell();
            var mergedCells = (HMergedCell)row.Cells["colFilename"];

            mergedCells.LeftColumn  = 2;
            mergedCells.RightColumn = 13;
            mergedCells.Value       = filenameOnly;

            int nOffset = 2;

            for (int j = nOffset; j < 14; j++)
            {
                row.Cells[j] = new HMergedCell();
                HMergedCell pCell = (HMergedCell)row.Cells[j];
                pCell.LeftColumn  = 2;
                pCell.RightColumn = 13;
                pCell.Value       = filenameOnly;
            }
            row.Cells["colMatchType"].Value = "SEPARATOR";

            // Fill numeric data for sorting
            row.Cells["colItemsCount"].Value   = -1;
            row.Cells["colFileSize"].Value     = -1L;
            row.Cells["colCreationTime"].Value = DateTime.MinValue;
            return(row);
        }
        /// <summary>
        /// Check if file is duplicated
        /// </summary>
        /// <param name="Origin"></param>
        /// <param name="Duplicate"></param>
        /// <param name="option"></param>
        /// <returns></returns>
        private bool Compare(ref DuplicateArchiveInfo Origin, ref DuplicateArchiveInfo Duplicate, DuplicateSearchOption option)
        {
            NotifyCaller("Comparing: " + Origin.Filename + " to " + Duplicate.Filename, OperationStatus.COMPARING);

            // if item count is equal, try to check from crc strings.
            Origin.MatchType = MatchType.ORIGINAL;
            Origin.Percentage = 0.0;
            if (Origin.NoMatches != null) Origin.NoMatches.Clear();

            if (Origin.Items.Count == Duplicate.Items.Count)
            {
                Duplicate.MatchType = MatchType.EQUALCOUNT;

                if (Origin.ToCRCString() == Duplicate.ToCRCString())
                {
                    NotifyCaller("CRC Strings are equal.", OperationStatus.COMPARING);
                    Duplicate.Percentage = 100.0;
                    return true;
                }
                else if (option.OnlyPerfectMatch)
                {
                    return false;
                }
            }

            Duplicate.MatchType = MatchType.SUBSET;

            // Check each files in duplicate
            int limitCount;

            // if only have 'IgnoreLimit' files, then all must match
            if (option.IgnoreLimit > Duplicate.Items.Count) limitCount = 0;
            else limitCount = Duplicate.Items.Count - (Duplicate.Items.Count * option.Limit / 100);

            int skippedCount = 0;
            int i = 0;
            int j = 0;
            while (i < Origin.Items.Count && j < Duplicate.Items.Count && skippedCount <= limitCount)
            {
                // compare the from the biggest crc.
                int result = string.Compare(Origin.Items[i].Crc, Duplicate.Items[j].Crc, true, System.Globalization.CultureInfo.InvariantCulture);
                if (result == 0)
                {
                    ++i; ++j;
                }
                else if (result > 0)
                {
                    // Origin file skipped
                    ++i;
                }
                else
                {
                    // Duplicate file skipped, no match in Origin
                    ++skippedCount;
                    if (Duplicate.NoMatches == null) Duplicate.NoMatches = new List<ArchiveFileInfoSmall>();
                    Duplicate.NoMatches.Add(Duplicate.Items[j]);
                    ++j;
                }
            }

            if (j < Duplicate.Items.Count)
            {
                if (Duplicate.NoMatches == null) Duplicate.NoMatches = new List<ArchiveFileInfoSmall>();
                Duplicate.NoMatches.AddRange(Duplicate.Items.GetRange(j, Duplicate.Items.Count - j));
                skippedCount = Duplicate.NoMatches.Count;
            }

            double percent = (double)(Duplicate.Items.Count - skippedCount) / Duplicate.Items.Count * 100;
            if (percent >= option.Limit && skippedCount < limitCount)
            {
                NotifyCaller("Match: " + percent + "%", OperationStatus.COMPARING);
                Duplicate.Percentage = percent;
                return true;
            }

            NotifyCaller("Not Match", OperationStatus.COMPARING);
            if (Duplicate.NoMatches != null) Duplicate.NoMatches.Clear();
            return false;
        }