This repository has been archived by the owner on Feb 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace PathCleaner | ||
{ | ||
interface IPathChecker | ||
{ | ||
string Reason { get; } | ||
bool Identify(string folder, string previousFolder); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace PathCleaner | ||
{ | ||
class NoExecutablesPathChecker : IPathChecker | ||
{ | ||
private static HashSet<string> executableExtensions = new HashSet<string>() | ||
{ | ||
".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(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace PathCleaner | ||
{ | ||
class ProblemIdentifier | ||
{ | ||
public IEnumerable<IPathChecker> Checkers { get; private set; } | ||
public PathString PathString { get; private set; } | ||
|
||
public ProblemIdentifier(PathString pathString, IEnumerable<IPathChecker> checkers) | ||
{ | ||
this.PathString = pathString; | ||
this.Checkers = checkers; | ||
} | ||
|
||
public IEnumerable<PathProblem> Problems | ||
{ | ||
get | ||
{ | ||
var sortedFolders = new List<string>(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; | ||
} | ||
} | ||
} | ||
|
||
} | ||
} |