-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProgram.cs
More file actions
83 lines (76 loc) · 2.96 KB
/
Program.cs
File metadata and controls
83 lines (76 loc) · 2.96 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
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace KeyCheck
{
public static class Program
{
private static void Main(string[] args)
{
// Set default exit code as success
Environment.ExitCode = 0;
if (args == null || args.Length == 0)
{
Console.WriteLine("Missing arguments!!");
Environment.ExitCode = 1;
}
else
{
var DirectoryPath = args[0];
if (!Directory.Exists(DirectoryPath))
{
Console.WriteLine("Directory \"{0}\" does not exist!!", DirectoryPath);
Environment.ExitCode = 1;
}
else
{
var KeyFiles = Directory.EnumerateFiles(DirectoryPath, "*.cs", SearchOption.TopDirectoryOnly);
string[] ExcludeFiles = null;
if (args.Length == 2)
{
ExcludeFiles = args[1].Split(',');
}
foreach (var FilePath in KeyFiles)
{
try
{
var info = new FileInfo(FilePath);
if (ExcludeFiles != null && (ExcludeFiles.Contains(info.Name) || ExcludeFiles.Contains(info.FullName)))
{
Console.WriteLine("Skipping file path: {0}", FilePath);
continue;
}
Console.WriteLine("File path: {0}", FilePath);
var content = File.ReadAllText(FilePath);
if (content.Contains("return null;") ||
!Regex.Match(content, "return \".*\";", RegexOptions.IgnoreCase).Success)
{
Console.WriteLine("Key missing from file!!");
Environment.ExitCode = 1;
}
else
{
Console.WriteLine("Key found!!");
}
}
catch (FileNotFoundException)
{
Console.WriteLine("File \"{0}\" does not exist!!", FilePath);
Environment.ExitCode = 1;
}
catch (Exception)
{
Console.WriteLine("Error accessing file!!");
Environment.ExitCode = 1;
}
}
}
}
Environment.Exit(Environment.ExitCode);
}
}
}