4
4
using System . Linq ;
5
5
using System . Runtime . InteropServices ;
6
6
using System . Text ;
7
+ using System . Text . RegularExpressions ;
7
8
using System . Threading . Tasks ;
8
9
9
10
namespace RdaConsoleTool
@@ -17,10 +18,10 @@ public RdaUnpacker()
17
18
_reader = new RDAReader ( ) ;
18
19
}
19
20
20
- public void UnpackFile ( String Filename , String OutputFolderName , bool overwrite )
21
+ public void UnpackFile ( String Filename , String OutputFolderName , String filter , bool overwrite )
21
22
{
22
23
SetupReader ( Filename ) ;
23
- ExtractToOutput ( OutputFolderName , overwrite ) ;
24
+ ExtractToOutput ( OutputFolderName , filter , overwrite ) ;
24
25
}
25
26
26
27
private void SetupReader ( String Filename )
@@ -29,23 +30,32 @@ private void SetupReader(String Filename)
29
30
_reader . ReadRDAFile ( ) ;
30
31
}
31
32
32
- private void ExtractToOutput ( String OutputFilename , bool overwrite )
33
+ private void ExtractToOutput ( String OutputFilename , String filter , bool overwrite )
33
34
{
34
35
if ( Directory . Exists ( OutputFilename ) && ! overwrite )
35
36
{
36
37
Console . WriteLine ( $ "Output Directory already exists. Use -y to overwrite") ;
37
38
return ;
38
39
}
39
40
Directory . CreateDirectory ( OutputFilename ) ;
40
- _reader . ExtractAllFiles ( OutputFilename ) ;
41
+ var files = _reader . rdaFolder . GetAllFiles ( ) ;
42
+ var regex = new Regex ( filter , RegexOptions . Compiled ) ;
43
+ files . RemoveAll ( f => ! regex . IsMatch ( f . FileName ) ) ;
44
+ if ( files . Count == 0 )
45
+ {
46
+ Console . WriteLine ( $ "Nothing left to extract, all files were filtered out") ;
47
+ return ;
48
+ }
49
+
50
+ _reader . ExtractFiles ( files , OutputFilename ) ;
41
51
}
42
52
}
43
53
44
54
internal static class RDAReaderExtensions
45
55
{
46
- public static void ExtractAllFiles ( this RDAReader reader , String Path )
56
+ public static void ExtractFiles ( this RDAReader reader , List < RDAFile > files , String Path )
47
57
{
48
- RDAExplorer . RDAFileExtension . ExtractAll ( reader . rdaFolder . GetAllFiles ( ) , Path ) ;
58
+ RDAExplorer . RDAFileExtension . ExtractAll ( files , Path ) ;
49
59
}
50
60
}
51
61
}
0 commit comments