Ejemplo n.º 1
0
        private void search(SearchEventArgs e, List <ItemInDatabase> list)
        {
            Cursor oldCursor = Cursor.Current;

            try
            {
                Cursor.Current = Cursors.WaitCursor;

                // usuwanie podtekstów ".*", gdy przed tekstem nie ma œrednika lub pocz¹tku tekstu, a za tekstem jest œrednik lub koniec tekstu
                int i = 0;
                while ((i = e.FileMask.IndexOf(".*", i, StringComparison.Ordinal)) > -1)
                {
                    // i > -1
                    if ((i > 0) && (e.FileMask[i - 1] != ';') && ((i == e.FileMask.Length - 2) || (e.FileMask[i + 2] == ';')))
                    {
                        e.FileMask = e.FileMask.Substring(0, i) + e.FileMask.Substring(i + 2);
                    }
                }

                Regex fileMaskRegex = new Regex(e.FileMask.ToRegex(e.TreatFileMaskAsWildcard), RegexOptions.Compiled | RegexOptions.IgnoreCase);

                KeywordMatcher keywordMatcher = new KeywordMatcher(e.Keywords, e.AllKeywordsNeeded, e.CaseSensitiveKeywords, e.TreatKeywordsAsWildcard);

                list.Clear();

                if (e.OnlyDuplicates)
                {
                    List <FileInDatabase> foundFilesCrc   = new List <FileInDatabase>();
                    List <FileInDatabase> foundFilesNoCrc = new List <FileInDatabase>();

                    foreach (DiscInDatabase disc in e.SearchInVolumes)
                    {
                        disc.InsertFilesToList(fileMaskRegex, e.DateFrom, e.DateTo, e.SizeFrom, e.SizeTo, keywordMatcher, foundFilesCrc, foundFilesNoCrc);
                    }

                    foundFilesCrc.Sort(new FileComparer(true));
                    FileComparer noCrcComparer = new FileComparer(false);
                    foundFilesNoCrc.Sort(noCrcComparer);
                    FileInDatabase lastFile = null; ulong lastCrc = 0;
                    foreach (FileInDatabase file in foundFilesCrc)
                    {
                        if (file.Hash != 0)
                        {
                            if (lastCrc != file.Hash)
                            {
                                lastCrc  = file.Hash;
                                lastFile = file;
                            }
                            else
                            {
                                if (lastFile != null)
                                { // lastFile dodajemy tylko raz
                                    insertSimilarToList(lastFile, foundFilesNoCrc, list, noCrcComparer);
                                    list.Add(lastFile);
                                    lastFile = null;
                                }
                                list.Add(file);
                                insertSimilarToList(file, foundFilesNoCrc, list, noCrcComparer);
                            }
                        }
                    }
                    lastFile = null; string lastKey = null;
                    foreach (FileInDatabase file in foundFilesNoCrc)
                    {
                        if (lastKey != file.NameLengthKey)
                        {
                            lastKey  = file.NameLengthKey;
                            lastFile = file;
                        }
                        else
                        {
                            if (lastFile != null)
                            { // lastFile dodajemy tylko raz
                                list.Add(lastFile);
                                lastFile = null;
                            }
                            list.Add(file);
                        }
                    }
                }
                else
                {
                    foreach (DiscInDatabase disc in e.SearchInVolumes)
                    {
                        disc.InsertFilesToList(fileMaskRegex, e.DateFrom, e.DateTo, e.SizeFrom, e.SizeTo, keywordMatcher, list /*, lvSearchResults*/);
                    }
                }
            }
            finally
            {
                Cursor.Current = oldCursor;
            }
        }
Ejemplo n.º 2
0
        private static void insertSimilarToList(FileInDatabase file, List <FileInDatabase> foundFilesNoCrc, List <ItemInDatabase> list, FileComparer noCrcComparer)
        {
            int index;

            do
            {
                index = foundFilesNoCrc.BinarySearch(file, noCrcComparer);
                if (index >= 0)
                {
                    list.Add(foundFilesNoCrc[index]);
                    foundFilesNoCrc.RemoveAt(index);
                }
            }while (index > 0);
        }