Пример #1
0
        static void FileProcessor(int threadIndex)
        {
            Tuple <FileInfo, DirectoryFingerprint> file;

            // int filesProcessedByThisThread = 0;

            while ((file = fst.NextFile()) != null)
            {
                FileInfo             fi = file.Item1;
                DirectoryFingerprint parentFingerprint = file.Item2;

                // TODO: check if file should be skipped

                string fileChecksum = ComputeFingerprint.FileChecksum(fi.FullName);
                if (fileChecksum == "")
                {
                    parentFingerprint.ChildFileSkipped();
                }
                else
                {
                    progress.FileCompleted(fi, fileChecksum);
                    parentFingerprint.FileCompleted(fileChecksum);

                    // filesProcessedByThisThread++;
                }
            }

            // Console.WriteLine("\nThread {0} completed - {1} files processed\n", threadIndex, filesProcessedByThisThread);
            progress.ThreadCompleted();
        }
Пример #2
0
        static void FileProcessor(int threadIndex)
        {
            Tuple <FileInfo, DirectoryFingerprint> file;

            // int filesProcessedByThisThread = 0;

            while ((file = fst.NextFile()) != null)
            {
                FileInfo             fi = file.Item1;
                DirectoryFingerprint parentFingerprint = file.Item2;

                // TODO: check if file should be skipped

                string fileChecksum = ComputeFingerprint.FileChecksum(fi.FullName);
                if (fileChecksum == "")
                {
                    parentFingerprint.ChildFileSkipped();
                }
                else
                {
                    string originalFilePath;
                    if (db.IsUniqueFile(fi, fileChecksum, volumeName, out originalFilePath))
                    {
                        string destinationFullName, category;
                        CopyUniqueFile.Copy(fi.FullName, out destinationFullName, out category);

                        progress.UniqueFileCompleted(fi, destinationFullName, fileChecksum, category);
                    }
                    else
                    {
                        progress.DuplicateFileCompleted(fi, originalFilePath, fileChecksum);
                    }

                    parentFingerprint.FileCompleted(fileChecksum);
                }
            }


            progress.ThreadCompleted();
        }
Пример #3
0
        void ProcessDirectory(Tuple <DirectoryInfo, DirectoryFingerprint> d)
        {
            bool                 directoryAccessException = false;
            string               exceptionMessage         = "";
            int                  fileCount         = 0;
            int                  directoryCount    = 0;
            DirectoryInfo        dirInfo           = d.Item1;
            DirectoryFingerprint parentFingerprint = d.Item2;

            if (DirectoryInSkipList(dirInfo))
            {
                parentFingerprint?.ChildDirectorySkipped();
                RunParallelScan.progress.SkipListDirSkipped(dirInfo);
                return;
            }

            DirectoryFingerprint myFingerprint = new DirectoryFingerprint(dirInfo, parentFingerprint);

            try
            {
                string     reason;
                FileInfo[] nextFiles = dirInfo.GetFiles();
                foreach (FileInfo fi in nextFiles)
                {
                    if (FileIncluded(fi, out reason))
                    {
                        files.Enqueue(Tuple.Create <FileInfo, DirectoryFingerprint>(fi, myFingerprint));
                        fileCount++;
                    }
                    else
                    {
                        RunParallelScan.progress.FileSkipped(fi, reason);
                    }
                }
            }
            catch (UnauthorizedAccessException)
            {
                Error("Directory: " + dirInfo.FullName, "Access denied");
                directoryAccessException = true;
                exceptionMessage         = "UnauthorizedAccessException";
            }
            catch (DirectoryNotFoundException)
            {
                Error("Directory: " + dirInfo.FullName, "Directory not found");
                directoryAccessException = true;
                exceptionMessage         = "DirectoryNotFoundException";
            }
            catch (Exception e)
            {
                Error("Directory (Unexpected REF1): " + dirInfo.FullName, e.ToString() + "\n");
                // Unexpected exception, keep trying
            }

            // If we've had an UnauthorizedAccessException on this directory there's no need to try accessing it again as it will fail again
            if (directoryAccessException)
            {
                parentFingerprint?.ChildDirectorySkipped();
                RunParallelScan.progress.DirException(dirInfo, exceptionMessage);
                return;
            }
            else
            {
                try
                {
                    DirectoryInfo[] nextDirectories = dirInfo.GetDirectories();
                    Array.Reverse(nextDirectories); // Push the first directory found last so that it gets popped first
                                                    //  -- this results in a depth-first traversal in the natural directory order that Windows File Explorer shows
                    foreach (DirectoryInfo di in nextDirectories)
                    {
                        if (DirectoryIncluded(di))
                        {
                            directories.Push(Tuple.Create <DirectoryInfo, DirectoryFingerprint>(di, myFingerprint));
                            directoryCount++;
                        }
                        else
                        {
                            RunParallelScan.progress.HiddenSystemDirSkipped(di);
                        }
                    }

                    myFingerprint.SetNumberOfItems(fileCount, directoryCount);
                }
                catch (Exception e)
                {
                    Error("Directory (Unexpected REF2): " + dirInfo.FullName, e.ToString() + "\n");
                    parentFingerprint?.ChildDirectorySkipped();
                }
            }

            return;
        }
Пример #4
0
 public DirectoryFingerprint(DirectoryInfo di, DirectoryFingerprint parentFingerprint)
 {
     this.di = di;
     this.parentFingerprint = parentFingerprint;
 }