Beispiel #1
0
        private DriveJunkNode GetJunkNodeFromLocation(string directory)
        {
            try
            {
                var dirInfo = new DirectoryInfo(directory);

                if (dirInfo.FullName.Contains(FullWindowsDirectoryName) || !dirInfo.Exists || dirInfo.Parent == null)
                {
                    return(null);
                }

                var newNode = new DriveJunkNode(Path.GetDirectoryName(directory),
                                                Path.GetFileName(directory), Uninstaller.DisplayName);
                newNode.Confidence.Add(ConfidencePart.ExplicitConnection);

                var generatedConfidence = GenerateConfidence(dirInfo.Name, dirInfo.Parent.FullName, 1, true);
                newNode.Confidence.AddRange(generatedConfidence);

                if (CheckAgainstOtherInstallers(dirInfo))
                {
                    newNode.Confidence.Add(ConfidencePart.DirectoryStillUsed);
                }

                return(newNode);
            }
            catch
            {
                return(null);
            }
        }
Beispiel #2
0
        private void FindJunkRecursively(ICollection <DriveJunkNode> returnList, DirectoryInfo directory, int level)
        {
            try
            {
                if ((directory.Attributes & FileAttributes.System) == FileAttributes.System)
                {
                    return;
                }

                var dirs = directory.GetDirectories();

                foreach (var dir in dirs)
                {
                    if (UninstallToolsGlobalConfig.IsSystemDirectory(dir))
                    {
                        continue;
                    }

                    var generatedConfidence = GenerateConfidence(dir.Name, directory.FullName, level, false);
                    var confidenceParts     = generatedConfidence as IList <ConfidencePart> ?? generatedConfidence.ToList();

                    if (confidenceParts.Any())
                    {
                        var newNode = new DriveJunkNode(directory.FullName, dir.Name, Uninstaller.DisplayName);
                        newNode.Confidence.AddRange(confidenceParts);

                        if (CheckAgainstOtherInstallers(dir))
                        {
                            newNode.Confidence.Add(ConfidencePart.DirectoryStillUsed);
                        }

                        returnList.Add(newNode);
                    }
                    else if (level < 1)
                    {
                        FindJunkRecursively(returnList, dir, level + 1);
                    }
                }
            }
            catch
            {
                if (Debugger.IsAttached)
                {
                    throw;
                }
            }
        }
Beispiel #3
0
        public static IEnumerable <DriveJunkNode> RemoveDuplicates(IEnumerable <DriveJunkNode> input)
        {
            foreach (var group in input.GroupBy(x => x.FullName))
            {
                DriveJunkNode node = null;
                foreach (var item in group)
                {
                    if (node == null)
                    {
                        node = item;
                    }
                    else
                    {
                        node.Confidence.AddRange(item.Confidence.ConfidenceParts);
                    }
                }

                if (node != null)
                {
                    yield return(node);
                }
            }
        }
        private IEnumerable <DriveJunkNode> FindJunkRecursively(DirectoryInfo directory, int level = 0)
        {
            var results = new List <DriveJunkNode>();

            try
            {
                var dirs = directory.GetDirectories();

                foreach (var dir in dirs)
                {
                    if (UninstallToolsGlobalConfig.IsSystemDirectory(dir))
                    {
                        continue;
                    }

                    var generatedConfidence = GenerateConfidence(dir.Name, directory.FullName, level).ToList();

                    DriveJunkNode newNode = null;
                    if (generatedConfidence.Any())
                    {
                        newNode = new DriveDirectoryJunkNode(directory.FullName, dir.Name, Uninstaller.DisplayName);
                        newNode.Confidence.AddRange(generatedConfidence);

                        if (CheckAgainstOtherInstallers(dir))
                        {
                            newNode.Confidence.Add(ConfidencePart.DirectoryStillUsed);
                        }

                        results.Add(newNode);
                    }

                    if (level >= 1)
                    {
                        continue;
                    }

                    var junkNodes = FindJunkRecursively(dir, level + 1).ToList();
                    results.AddRange(junkNodes);

                    if (newNode != null)
                    {
                        // Check if the directory will have nothing left after junk removal.
                        if (!dir.GetFiles().Any())
                        {
                            var subDirs = dir.GetDirectories();
                            if (!subDirs.Any() || subDirs.All(d => junkNodes.Any(y => PathTools.PathsEqual(d.FullName, y.FullName))))
                            {
                                newNode.Confidence.Add(ConfidencePart.AllSubdirsMatched);
                            }
                        }
                    }
                }
            }
            catch
            {
                if (Debugger.IsAttached)
                {
                    throw;
                }
            }

            return(results);
        }