Skip to content

Commit d83cfd2

Browse files
Merge pull request #2 from anno-mods/feature/add-support-for-filtering-exported-files
2 parents 1449685 + fd068d1 commit d83cfd2

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

RdaConsole/ConsoleOptions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ class ExtractOptions
3535
[Option('o', "outputfile", Required = false, HelpText = "File name of the output file.")]
3636
public String OutputFolderName { get; set; } = "rda_out";
3737

38+
[Option("filter", Required = false, HelpText = "Extracts only files which satisfy a regex.")]
39+
public String Filter { get; set; } = ".*";
40+
3841
[Option('y', "overwrite", Required = false, HelpText = "Forces overwriting in the output folder")]
3942
public bool Overwrite { get; set; } = false;
4043

RdaConsole/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static void Main(string[] args)
3535

3636
foreach (String file in extract.Files)
3737
{
38-
unpacker.UnpackFile(file, extract.OutputFolderName, extract.Overwrite);
38+
unpacker.UnpackFile(file, extract.OutputFolderName, extract.Filter, extract.Overwrite);
3939
}
4040
return 0;
4141
},

RdaConsole/RdaUnpacker.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Linq;
55
using System.Runtime.InteropServices;
66
using System.Text;
7+
using System.Text.RegularExpressions;
78
using System.Threading.Tasks;
89

910
namespace RdaConsoleTool
@@ -17,10 +18,10 @@ public RdaUnpacker()
1718
_reader = new RDAReader();
1819
}
1920

20-
public void UnpackFile(String Filename, String OutputFolderName, bool overwrite)
21+
public void UnpackFile(String Filename, String OutputFolderName, String filter, bool overwrite)
2122
{
2223
SetupReader(Filename);
23-
ExtractToOutput(OutputFolderName, overwrite);
24+
ExtractToOutput(OutputFolderName, filter, overwrite);
2425
}
2526

2627
private void SetupReader(String Filename)
@@ -29,23 +30,32 @@ private void SetupReader(String Filename)
2930
_reader.ReadRDAFile();
3031
}
3132

32-
private void ExtractToOutput(String OutputFilename, bool overwrite)
33+
private void ExtractToOutput(String OutputFilename, String filter, bool overwrite)
3334
{
3435
if (Directory.Exists(OutputFilename) && !overwrite)
3536
{
3637
Console.WriteLine($"Output Directory already exists. Use -y to overwrite");
3738
return;
3839
}
3940
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);
4151
}
4252
}
4353

4454
internal static class RDAReaderExtensions
4555
{
46-
public static void ExtractAllFiles(this RDAReader reader, String Path)
56+
public static void ExtractFiles(this RDAReader reader, List<RDAFile> files, String Path)
4757
{
48-
RDAExplorer.RDAFileExtension.ExtractAll(reader.rdaFolder.GetAllFiles(), Path);
58+
RDAExplorer.RDAFileExtension.ExtractAll(files, Path);
4959
}
5060
}
5161
}

0 commit comments

Comments
 (0)