@@ -3,14 +3,10 @@ namespace BitMono.CLI.Modules;
33internal class OptionsObfuscationNeedsFactory
44{
55 private readonly string [ ] _args ;
6- private readonly ObfuscationSettings _obfuscationSettings ;
7- private readonly ILogger _logger ;
86
9- public OptionsObfuscationNeedsFactory ( string [ ] args , ObfuscationSettings obfuscationSettings , ILogger logger )
7+ public OptionsObfuscationNeedsFactory ( string [ ] args )
108 {
119 _args = args ;
12- _obfuscationSettings = obfuscationSettings ;
13- _logger = logger . ForContext < OptionsObfuscationNeedsFactory > ( ) ;
1410 }
1511
1612 [ SuppressMessage ( "ReSharper" , "AssignNullToNotNullAttribute" ) ]
@@ -22,20 +18,54 @@ public OptionsObfuscationNeedsFactory(string[] args, ObfuscationSettings obfusca
2218 with . HelpWriter = Console . Error ;
2319 } ) ;
2420 var parserResult = parser . ParseArguments < Options > ( _args ) ;
25- if ( parserResult . Errors . IsEmpty ( ) == false )
21+ if ( ! parserResult . Errors . IsEmpty ( ) )
2622 {
2723 return null ;
2824 }
2925 var options = parserResult . Value ;
26+
27+ ObfuscationSettings ? obfuscationSettings = null ;
28+ try
29+ {
30+ if ( options . ObfuscationFile != null && File . Exists ( options . ObfuscationFile ) )
31+ {
32+ var obfuscationConfig = new BitMonoObfuscationConfiguration ( options . ObfuscationFile ) ;
33+ obfuscationSettings = obfuscationConfig . Configuration . Get < ObfuscationSettings > ( ) ;
34+ }
35+ else if ( File . Exists ( KnownConfigNames . Obfuscation ) )
36+ {
37+ var obfuscationConfig = new BitMonoObfuscationConfiguration ( ) ;
38+ obfuscationSettings = obfuscationConfig . Configuration . Get < ObfuscationSettings > ( ) ;
39+ }
40+ }
41+ catch ( Exception ex )
42+ {
43+ Console . WriteLine ( $ "Warning: Could not load obfuscation configuration: { ex } ") ;
44+ }
45+
3046 var filePath = PathFormatterUtility . Format ( options . File ! ) ;
31- if ( File . Exists ( filePath ) == false )
47+ if ( ! File . Exists ( filePath ) )
3248 {
33- _logger . Fatal ( $ "File { filePath } cannot be found, please, try again!") ;
49+ Console . WriteLine ( $ "File { filePath } cannot be found, please, try again!") ;
3450 return null ;
3551 }
36- ObfuscationNeeds needs ;
3752 var fileBaseDirectory = Path . GetDirectoryName ( filePath ) ;
38- if ( _obfuscationSettings . ForceObfuscation )
53+
54+ ProtectionSettings ? protectionSettings = null ;
55+ if ( options . Protections . Any ( ) )
56+ {
57+ protectionSettings = new ProtectionSettings
58+ {
59+ Protections = options . Protections . Select ( x => new ProtectionSetting
60+ {
61+ Name = x ,
62+ Enabled = true
63+ } ) . ToList ( )
64+ } ;
65+ }
66+
67+ ObfuscationNeeds needs ;
68+ if ( obfuscationSettings ? . ForceObfuscation == true )
3969 {
4070 needs = new ObfuscationNeeds
4171 {
@@ -44,7 +74,11 @@ public OptionsObfuscationNeedsFactory(string[] args, ObfuscationSettings obfusca
4474 ReferencesDirectoryName = fileBaseDirectory ,
4575 OutputPath = fileBaseDirectory ,
4676 Protections = options . Protections . ToList ( ) ,
47- Way = ObfuscationNeedsWay . Options
77+ ProtectionSettings = protectionSettings ,
78+ Way = ObfuscationNeedsWay . Options ,
79+ CriticalsFile = options . CriticalsFile ,
80+ LoggingFile = options . LoggingFile ,
81+ ObfuscationFile = options . ObfuscationFile
4882 } ;
4983 }
5084 else
@@ -55,12 +89,16 @@ public OptionsObfuscationNeedsFactory(string[] args, ObfuscationSettings obfusca
5589 FileBaseDirectory = fileBaseDirectory ,
5690 ReferencesDirectoryName = options . Libraries ? . IsNullOrEmpty ( ) == false
5791 ? options . Libraries
58- : Path . Combine ( fileBaseDirectory , _obfuscationSettings . ReferencesDirectoryName ) ,
92+ : Path . Combine ( fileBaseDirectory , obfuscationSettings ? . ReferencesDirectoryName ?? "libs" ) ,
5993 OutputPath = options . Output ? . IsNullOrEmpty ( ) == false
6094 ? options . Output
61- : Path . Combine ( fileBaseDirectory , _obfuscationSettings . OutputDirectoryName ) ,
95+ : Path . Combine ( fileBaseDirectory , obfuscationSettings ? . OutputDirectoryName ?? "output" ) ,
6296 Protections = options . Protections . ToList ( ) ,
63- Way = ObfuscationNeedsWay . Options
97+ ProtectionSettings = protectionSettings ,
98+ Way = ObfuscationNeedsWay . Options ,
99+ CriticalsFile = options . CriticalsFile ,
100+ LoggingFile = options . LoggingFile ,
101+ ObfuscationFile = options . ObfuscationFile
64102 } ;
65103 }
66104
0 commit comments