-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
102 lines (84 loc) · 3.55 KB
/
Program.cs
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using System;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Xml.Serialization;
namespace CSharpMissingFileFinder
{
class Program
{
static string _path { get; set; } = "";
static string _projectPath { get; set; } = "";
static string[] _gitignoreLines { get; set; } = new string[0];
static void Main(string[] args)
{
while (_path == "")
{
Console.Write("Please enter the file path of the project: ");
var input = Console.ReadLine().Replace("\"", "");
if (!input.Contains(".csproj"))
{
Console.WriteLine(">> Not a project file");
continue;
}
var projectFileInfo = new FileInfo(input);
if (!projectFileInfo.Exists)
{
Console.WriteLine(">> File Doesn't exist");
continue;
}
_path = projectFileInfo.Directory.FullName;
_projectPath = projectFileInfo.FullName;
var gitLocation = projectFileInfo.Directory.GetFiles()
.FirstOrDefault(file => file.Name == ".gitignore");
if (gitLocation.Exists)
_gitignoreLines = File
.ReadAllLines(gitLocation.FullName)
.Where(line
=> line != ""
&& !line.StartsWith("#"))
.ToArray();
}
var serilizer = new XmlSerializer(typeof(Project));
var fileStream = File.OpenRead(_projectPath);
var project = (Project)serilizer.Deserialize(fileStream);
foreach (var group in project.ItemGroup)
{
foreach (var item in group.Reference)
TestFile(item.HintPath);
foreach (var item in group.Compile)
TestFile(item.Include);
foreach (var item in group.Content)
TestFile(item.Include);
}
Console.WriteLine("-".PadRight(20, '-'));
Console.WriteLine("Finished");
}
static string GetPath(string hintPath) => Path.Combine(_path, HttpUtility.UrlDecode(hintPath));
static void TestFile (string relativeFilePath) {
if (relativeFilePath == null || relativeFilePath.StartsWith(@"C:\"))
return;
var fullPath = GetPath(relativeFilePath);
if (File.Exists(fullPath)) {
var isIgnored = _gitignoreLines.Any(line => relativeFilePath.Contains(line));
if (isIgnored) {
WriteIgnored(relativeFilePath);
return;
}
//WriteFound(relativeFilePath);
return;
}
WriteMissing(relativeFilePath);
}
static void WriteResult(string content, ConsoleColor colour) {
var previousColour = Console.ForegroundColor;
Console.ForegroundColor = colour;
Console.WriteLine(content);
Console.ForegroundColor = previousColour;
}
static void WriteFound(string path) => WriteResult($"[FOUND] {path}", ConsoleColor.Green);
static void WriteMissing(string path) => WriteResult($"[MISSING] {path}", ConsoleColor.Red);
static void WriteIgnored(string path) => WriteResult($"[IGNORED] {path}", ConsoleColor.Yellow);
}
}