1+ #pragma warning disable CS8604
2+ namespace BitMono . CLI . Modules ;
3+
4+ [ SuppressMessage ( "ReSharper" , "InconsistentNaming" ) ]
5+ public class CLIOptionsObfuscationNeedsFactory : IObfuscationNeedsFactory
6+ {
7+ private readonly string [ ] m_Args ;
8+
9+ public CLIOptionsObfuscationNeedsFactory ( string [ ] args )
10+ {
11+ m_Args = args ;
12+ }
13+
14+ [ SuppressMessage ( "ReSharper" , "AssignNullToNotNullAttribute" ) ]
15+ public ObfuscationNeeds ? Create ( )
16+ {
17+ var parser = new Parser ( with =>
18+ {
19+ with . EnableDashDash = true ;
20+ with . HelpWriter = Console . Error ;
21+ } ) ;
22+ var parserResult = parser . ParseArguments < CLIOptions > ( m_Args ) ;
23+ if ( parserResult . Errors . IsEmpty ( ) == false )
24+ {
25+ return null ;
26+ }
27+ var options = parserResult . Value ;
28+ if ( File . Exists ( options . File ) == false )
29+ {
30+ Console . WriteLine ( "File cannot be found, please, try again!" ) ;
31+ return null ;
32+ }
33+ var fileBaseDirectory = Path . GetDirectoryName ( options . File ) ;
34+ var needs = new ObfuscationNeeds
35+ {
36+ FileName = options . File ,
37+ FileBaseDirectory = fileBaseDirectory ,
38+ DependenciesDirectoryName = options . Libraries . IsNullOrEmpty ( ) == false
39+ ? options . Libraries
40+ : Path . Combine ( fileBaseDirectory , "libs" ) ,
41+ OutputDirectoryName = options . Output . IsNullOrEmpty ( ) == false
42+ ? options . Output
43+ : Path . Combine ( fileBaseDirectory , "output" )
44+ } ;
45+
46+ Directory . CreateDirectory ( needs . OutputDirectoryName ) ;
47+ Directory . CreateDirectory ( needs . DependenciesDirectoryName ) ;
48+ return needs ;
49+ }
50+ }
0 commit comments