-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInputValidator.cs
55 lines (48 loc) · 1.71 KB
/
InputValidator.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
using EncryptMC.Utility;
namespace EncryptMC
{
internal static class InputValidator
{
internal static bool ValidatePathsAndKey(string inputPath, string outputPath, string contentKey, bool isInteractive)
{
// Check input path
if (!Directory.Exists(inputPath))
{
ShowError("Input path does not exist or is not a directory.\n", isInteractive);
return false;
}
// Check output path
if (!Directory.Exists(outputPath))
{
ShowError("Output path does not exist or is not a directory.\n", isInteractive);
return false;
}
// Check if input path is a subpath of output path
if (PathUtility.IsSubPath(inputPath, outputPath))
{
ShowError("Input path cannot be a subpath of output path.\n", isInteractive);
return false;
}
// Check if content key is 32 bytes
if (contentKey.Length != 32)
{
ShowError("Content key must be exactly 32 bytes long.\n", isInteractive);
return false;
}
return true;
}
private static void ShowError(string message, bool isInteractive)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(message);
Console.ResetColor();
if (isInteractive)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Press Enter to exit...");
Console.ReadKey(true);
Console.ResetColor();
}
}
}
}