Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
93 lines (76 loc) · 2.61 KB
/
Copy pathProgram.cs
File metadata and controls
93 lines (76 loc) · 2.61 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
84
85
86
87
88
89
90
91
92
93
using System.CommandLine;
namespace StellaSoraMetadataDecryptor;
internal static class Program
{
private static readonly Option<string?> OutputPathOption = new("--output", "-o")
{
Description = "Decrypted metadata output path",
};
private static readonly Argument<string> InputPathArgument = new("input")
{
Description = "Encrypted global-metadata.dat file path",
Arity = ArgumentArity.ExactlyOne,
Validators =
{
(result) =>
{
var inputPath = result.GetValueOrDefault<string>();
if (string.IsNullOrEmpty(inputPath))
{
result.AddError("The <input> argument must be set.");
return;
}
var fullInputPath = Path.GetFullPath(inputPath);
if (!File.Exists(fullInputPath))
{
result.AddError($"Metadata file at \"{fullInputPath}\" is not exists.");
}
}
}
};
private static readonly RootCommand CommandInstance = new("Stella Sora Metadata Decryptor")
{
InputPathArgument,
OutputPathOption
};
static int Main(string[] args)
{
CommandInstance.SetAction(parseResult =>
{
string? inputPath = parseResult.GetValue(InputPathArgument);
if (inputPath == null)
{
Console.Error.WriteLine($"The <input> argument must be set.");
return 1;
}
string outputPath = GetOutputPath(parseResult);
var input = new FileInfo(inputPath);
var output = new FileInfo(outputPath);
if (output.Exists)
{
output.Delete();
output.Refresh();
}
Console.Write($"Decrypting metadata file \"{input.Name}\". ");
var result = Decryptor.DecryptMetadataFile(input, output);
if (!result.Success)
{
Console.WriteLine($"(Failed: {result.Error})");
return 1;
}
Console.WriteLine("(Success)");
return 0;
});
return CommandInstance.Parse(args).Invoke();
}
public static string GetOutputPath(ParseResult parseResult)
{
string inputPath = parseResult.GetRequiredValue(InputPathArgument);
var outputPath = parseResult.GetValue(OutputPathOption);
if (!string.IsNullOrEmpty(outputPath))
{
return Path.GetFullPath(outputPath);
}
return Path.GetFullPath(inputPath) + "_output";
}
}