-
-
Notifications
You must be signed in to change notification settings - Fork 315
/
CliOptions.cs
131 lines (111 loc) · 4.42 KB
/
CliOptions.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
using System;
using System.IO;
using CommandLine;
namespace FFmpeg.AutoGen.CppSharpUnsafeGenerator;
/// <summary>
/// Command line options.
/// </summary>
public class CliOptions
{
[Option('n',
"namespace",
Default = "FFmpeg.AutoGen",
HelpText = "The namespace that will contain the generated symbols.")]
public string Namespace { get; set; }
[Option('c',
"class",
Default = "ffmpeg",
HelpText = "The name of the class that contains the FFmpeg unmanaged method calls.")]
public string ClassName { get; set; }
/// <summary>
/// See https://ybeernet.blogspot.ro/2011/03/techniques-of-calling-unmanaged-code.html.
/// </summary>
[Option('f',
"SuppressUnmanagedCodeSecurity",
HelpText = "Add the [SuppressUnmanagedCodeSecurity] attribute to unmanaged method calls " +
"(faster invocation).")]
public bool SuppressUnmanagedCodeSecurity { get; set; }
[Option('i',
"input",
Required = false,
HelpText = "The path to the directory that contains the FFmpeg header and binary files " +
"(must have the default structure).")]
public string FFmpegDir { get; set; }
[Option('h',
"headers",
Required = false,
HelpText = "The path to the directory that contains the FFmpeg header files.")]
public string FFmpegIncludesDir { get; set; }
[Option('b',
"bin",
Required = false,
HelpText = "The path to the directory that contains the FFmpeg binaries.")]
public string FFmpegBinDir { get; set; }
[Option('o',
"output",
Required = false,
HelpText = "The path to the directory where to output the generated files.")]
public string OutputDir { get; set; }
[Option('v',
HelpText = "Print details during execution.")]
public bool Verbose { get; set; }
public static CliOptions ParseArgumentsStrict(string[] args)
{
var result = Parser.Default.ParseArguments<CliOptions>(args);
var options = result.MapResult(x => x, x => new CliOptions());
options.Normalize();
return options;
}
private void Normalize()
{
// Support for the original path setup
var solutionDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../../../../");
if (string.IsNullOrWhiteSpace(FFmpegDir) &&
string.IsNullOrWhiteSpace(FFmpegIncludesDir) &&
string.IsNullOrWhiteSpace(FFmpegBinDir))
FFmpegDir = Path.Combine(solutionDir, "FFmpeg");
if (string.IsNullOrWhiteSpace(OutputDir)) OutputDir = Path.Combine(solutionDir, "FFmpeg.AutoGen/");
// If the FFmpegDir option is specified, it will take precedence
if (!string.IsNullOrWhiteSpace(FFmpegDir))
{
FFmpegIncludesDir = Path.Combine(FFmpegDir, "include");
FFmpegBinDir = Path.Combine(FFmpegDir, "bin/x64");
FFmpegDir = null;
}
// Fail if required options are not specified
if (string.IsNullOrWhiteSpace(FFmpegBinDir))
{
Console.WriteLine("The path to the directory that contains " +
"the FFmpeg binaries is missing (specify it using -b or --bin).");
Environment.Exit(1);
}
if (string.IsNullOrWhiteSpace(FFmpegIncludesDir))
{
Console.WriteLine("The path to the directory that contains " +
"the FFmpeg headers is missing (specify it using -h or --headers).");
Environment.Exit(1);
}
// Check paths exist
if (!Directory.Exists(FFmpegBinDir))
{
Console.WriteLine("The path to the directory that contains " +
"the FFmpeg binaries does not exist.");
Environment.Exit(1);
}
if (!Directory.Exists(FFmpegIncludesDir))
{
Console.WriteLine("The path to the directory that contains " +
"the FFmpeg headers does not exist.");
Environment.Exit(1);
}
if (!Directory.Exists(OutputDir))
{
Console.WriteLine("The output directory does not exist.");
Environment.Exit(1);
}
// Resolve paths
FFmpegIncludesDir = Path.GetFullPath(FFmpegIncludesDir);
FFmpegBinDir = Path.GetFullPath(FFmpegBinDir);
OutputDir = Path.GetFullPath(OutputDir);
}
}