This repository was archived by the owner on Feb 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathProblemIdentifier.cs
More file actions
43 lines (40 loc) · 1.4 KB
/
ProblemIdentifier.cs
File metadata and controls
43 lines (40 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
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> FindProblems()
{
var sortedFolders = new List<string>(PathString.Folders.OrderBy(s => s));
string previousFolder = null;
foreach (string folder in sortedFolders)
{
string expandedFolder = folder;
if (folder.IndexOf('%') >= 0)
{
expandedFolder = Environment.ExpandEnvironmentVariables(folder);
}
var successfulChecker = Checkers.FirstOrDefault(c => c.Identify(expandedFolder, previousFolder));
if (successfulChecker != null)
{
var problem = new PathProblem
{
Path = folder,
Reason = successfulChecker.Reason,
};
yield return problem;
}
previousFolder = folder;
}
}
}
}