diff --git a/DuplicatePathChecker.cs b/DuplicatePathChecker.cs new file mode 100644 index 0000000..75f4be4 --- /dev/null +++ b/DuplicatePathChecker.cs @@ -0,0 +1,18 @@ +using System; + +namespace PathCleaner +{ + class DuplicatePathChecker : IPathChecker + { + public string Reason + { + get { return "Duplicate"; } + } + + public bool Identify(string folder, string previousFolder) + { + return previousFolder != null + && String.Compare(folder, previousFolder, StringComparison.InvariantCultureIgnoreCase) == 0; + } + } +} diff --git a/EmptyPathChecker.cs b/EmptyPathChecker.cs new file mode 100644 index 0000000..0799c00 --- /dev/null +++ b/EmptyPathChecker.cs @@ -0,0 +1,19 @@ +using System.IO; +using System.Linq; + +namespace PathCleaner +{ + class EmptyPathChecker : IPathChecker + { + public string Reason + { + get { return "Empty"; } + } + + public bool Identify(string folder, string previousFolder) + { + return !Directory.EnumerateFiles(folder).Any(); + } + } + +} diff --git a/IPathChecker.cs b/IPathChecker.cs new file mode 100644 index 0000000..6832b61 --- /dev/null +++ b/IPathChecker.cs @@ -0,0 +1,9 @@ +namespace PathCleaner +{ + interface IPathChecker + { + string Reason { get; } + bool Identify(string folder, string previousFolder); + } + +} diff --git a/MissingPathChecker.cs b/MissingPathChecker.cs new file mode 100644 index 0000000..ed23d36 --- /dev/null +++ b/MissingPathChecker.cs @@ -0,0 +1,18 @@ +using System.IO; + +namespace PathCleaner +{ + class MissingPathChecker : IPathChecker + { + public string Reason + { + get { return "Missing"; } + } + + public bool Identify(string folder, string previousFolder) + { + return !Directory.Exists(folder); + } + } + +} diff --git a/NoExecutablesPathChecker.cs b/NoExecutablesPathChecker.cs new file mode 100644 index 0000000..b5fc980 --- /dev/null +++ b/NoExecutablesPathChecker.cs @@ -0,0 +1,27 @@ +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace PathCleaner +{ + class NoExecutablesPathChecker : IPathChecker + { + private static HashSet executableExtensions = new HashSet() + { + ".exe", ".com", ".bat", ".cmd", ".ps1", ".dll" + }; + + public string Reason + { + get { return "No executables"; } + } + + public bool Identify(string folder, string previousFolder) + { + return !Directory.EnumerateFiles(folder) + .Where(s => executableExtensions.Contains(Path.GetExtension(s))) + .Any(); + } + } + +} diff --git a/ProblemIdentifier.cs b/ProblemIdentifier.cs new file mode 100644 index 0000000..d861a43 --- /dev/null +++ b/ProblemIdentifier.cs @@ -0,0 +1,42 @@ +using System.Collections.Generic; +using System.Linq; + +namespace PathCleaner +{ + class ProblemIdentifier + { + public IEnumerable Checkers { get; private set; } + public PathString PathString { get; private set; } + + public ProblemIdentifier(PathString pathString, IEnumerable checkers) + { + this.PathString = pathString; + this.Checkers = checkers; + } + + public IEnumerable Problems + { + get + { + var sortedFolders = new List(PathString.Folders.OrderBy(s => s)); + string previousFolder = null; + foreach(string folder in sortedFolders) + { + var problem = Checkers.Where(c => c.Identify(folder, previousFolder)) + .Select(c => new PathProblem + { + Path = folder, + Reason = c.Reason, + }) + .FirstOrDefault(); + if (problem != null) + { + yield return problem; + } + previousFolder = folder; + } + } + } + + } +}