-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathProgram.cs
93 lines (84 loc) · 3.22 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
using EncryptMC.Utility;
namespace EncryptMC
{
internal static class Program
{
private static void Main(string[] args)
{
// Parse arguments or prompt for them interactively
var (inputPath, outputPath, contentKey, isInteractiveMode) = CommandLineHandler.ParseArgs(args);
// Validate user input
if (!InputValidator.ValidatePathsAndKey(inputPath, outputPath, contentKey, isInteractiveMode))
{
return;
}
// Retrieve UUID from manifest
string manifestUuid;
try
{
manifestUuid = ManifestUtility.GetManifestUuid(inputPath);
Console.WriteLine($"Manifest UUID: {manifestUuid}\n");
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"Failed to get manifest UUID: {ex.Message}\n");
ExitIfInteractive(isInteractiveMode);
return;
}
bool inputOutputPathsEqual = inputPath.Equals(outputPath, StringComparison.OrdinalIgnoreCase);
// Remove existing output directory (if any) to rebuild cleanly
if (Directory.Exists(outputPath) && !inputOutputPathsEqual)
{
try
{
Directory.Delete(outputPath, recursive: true);
Console.WriteLine($"Successfully removed the directory: {outputPath}\n");
}
catch (Exception ex)
{
throw new IOException($"Failed to remove the directory \"{outputPath}\": {ex.Message}", ex);
}
}
// Create and encrypt manifest signature
try
{
ManifestUtility.CreateManifestSignature(inputPath, outputPath, contentKey);
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"Failed to create manifest signature: {ex.Message}\n");
ExitIfInteractive(isInteractiveMode);
return;
}
// Encrypt entire pack
try
{
PackEncryption.EncryptPack(inputPath, outputPath, contentKey, manifestUuid);
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"Failed to encrypt pack: {ex.Message}\n");
ExitIfInteractive(isInteractiveMode);
return;
}
// Success message
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Encryption completed successfully.\n");
ExitIfInteractive(isInteractiveMode);
Console.ResetColor();
}
private static void ExitIfInteractive(bool isInteractiveMode)
{
if (isInteractiveMode)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write("Press any key to exit...");
Console.ReadKey(true);
Console.ResetColor();
}
}
}
}