Ejemplo n.º 1
0
        private void EmptyDirectory()
        {
            string[] EmptyDirChecksumSeed = { String.Empty };
            string   directoryChecksum;

            lock (_lockDirFingerprint)
            {
                completed         = true;
                directoryChecksum = ComputeFingerprint.DirectoryChecksum(EmptyDirChecksumSeed);

                RunParallelScan.progress.DirectoryCompleted(di, directoryChecksum, checksumsStored, numberOfItems);

                // Don't Pass empty checksum up to parent
                parentFingerprint?.ChildDirectorySkipped();
            }
        }
Ejemplo n.º 2
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;
        }