예제 #1
0
        /// <summary>
        /// Starts the search.
        /// </summary>
        private void Search()
        {
            _files = new List <string>();

            foreach (var paths in _paths)
            {
                _cts.Token.ThrowIfCancellationRequested();

                DriveInfo drive = null;

                if (paths.Key != string.Empty)
                {
                    try
                    {
                        drive = new DriveInfo(paths.Key);
                        var s = drive.AvailableFreeSpace; // make sure disk is ready
                    }
                    catch (DriveNotFoundException) { continue; }
                    catch (IOException)            { continue; }
                    catch (Exception ex)
                    {
                        MainWindow.HandleUnexpectedException(ex);
                    }
                }

                if (drive != null && drive.DriveFormat == "NTFS" && Settings.Get <bool>("Search NTFS MFT records") && Utils.IsAdmin)
                {
                    try
                    {
                        ScanNtfsMftForFile(drive, paths.Value.Count == 1 && paths.Value[0].Length == 3 ? null : paths.Value);
                    }
                    catch (OperationCanceledException)
                    {
                        throw;
                    }
                    catch (Exception ex)
                    {
                        MainWindow.HandleUnexpectedException(ex);
                    }
                }
                else
                {
                    foreach (var path in paths.Value)
                    {
                        FileSearchProgressChanged.Fire(this, "Searching recursively for matching files in " + path + "...");

                        ScanDirectoryForFile(path);
                    }
                }
            }

            FileSearchDone.Fire(this, _files);
        }
예제 #2
0
        /// <summary>
        /// Scans the NTFS Master File Table entries for a matching file.
        /// </summary>
        /// <param name="drive">The partition to scan.</param>
        /// <param name="paths">The paths to which the search should be limited.</param>
        private void ScanNtfsMftForFile(DriveInfo drive, IEnumerable <string> paths = null)
        {
            FileSearchProgressChanged.Fire(this, "Reading the MFT records of the " + drive.Name[0] + " partition...");

            IEnumerable <string> list;

            Log.Debug("Reading the MFT records of the " + drive.Name[0] + " partition...");

            try
            {
                _cts.Token.ThrowIfCancellationRequested();
                var usn = new NtfsUsnJournal(drive);

                _cts.Token.ThrowIfCancellationRequested();
                list = usn.GetParsedPaths(ShowNames.Regexes.KnownVideo, paths);

                _cts.Token.ThrowIfCancellationRequested();
            }
            catch (OperationCanceledException)
            {
                throw;
            }
            catch (Exception ex)
            {
                Log.Error("Error while reading the MFT records of the " + drive.Name[0] + " partition.", ex);
                return;
            }

            FileSearchProgressChanged.Fire(this, "Searching for matching files in the " + drive.Name[0] + " partition...");

            foreach (var file in list)
            {
                _cts.Token.ThrowIfCancellationRequested();

                try
                {
                    if (_checkFile(file))
                    {
                        _files.Add(file);
                    }
                }
                catch (PathTooLongException)        { }
                catch (SecurityException)           { }
                catch (UnauthorizedAccessException) { }
                catch (DirectoryNotFoundException)  { }
                catch (Exception ex)
                {
                    Log.Error("Error while checking file.", ex);
                }
            }
        }