Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
taubenangriff committed Jul 7, 2022
2 parents 01e1040 + d83cfd2 commit 4c284ca
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
3 changes: 3 additions & 0 deletions RdaConsole/ConsoleOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class ExtractOptions
[Option('o', "outputfile", Required = false, HelpText = "File name of the output file.")]
public String OutputFolderName { get; set; } = "rda_out";

[Option("filter", Required = false, HelpText = "Extracts only files which satisfy a regex.")]
public String Filter { get; set; } = ".*";

[Option('y', "overwrite", Required = false, HelpText = "Forces overwriting in the output folder")]
public bool Overwrite { get; set; } = false;

Expand Down
2 changes: 1 addition & 1 deletion RdaConsole/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static void Main(string[] args)

foreach (String file in extract.Files)
{
unpacker.UnpackFile(file, extract.OutputFolderName, extract.Overwrite);
unpacker.UnpackFile(file, extract.OutputFolderName, extract.Filter, extract.Overwrite);
}
return 0;
},
Expand Down
22 changes: 16 additions & 6 deletions RdaConsole/RdaUnpacker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace RdaConsoleTool
Expand All @@ -17,10 +18,10 @@ public RdaUnpacker()
_reader = new RDAReader();
}

public void UnpackFile(String Filename, String OutputFolderName, bool overwrite)
public void UnpackFile(String Filename, String OutputFolderName, String filter, bool overwrite)
{
SetupReader(Filename);
ExtractToOutput(OutputFolderName, overwrite);
ExtractToOutput(OutputFolderName, filter, overwrite);
}

private void SetupReader(String Filename)
Expand All @@ -29,23 +30,32 @@ private void SetupReader(String Filename)
_reader.ReadRDAFile();
}

private void ExtractToOutput(String OutputFilename, bool overwrite)
private void ExtractToOutput(String OutputFilename, String filter, bool overwrite)
{
if (Directory.Exists(OutputFilename) && !overwrite)
{
Console.WriteLine($"Output Directory already exists. Use -y to overwrite");
return;
}
Directory.CreateDirectory(OutputFilename);
_reader.ExtractAllFiles(OutputFilename);
var files = _reader.rdaFolder.GetAllFiles();
var regex = new Regex(filter, RegexOptions.Compiled);
files.RemoveAll(f => !regex.IsMatch(f.FileName));
if (files.Count == 0)
{
Console.WriteLine($"Nothing left to extract, all files were filtered out");
return;
}

_reader.ExtractFiles(files, OutputFilename);
}
}

internal static class RDAReaderExtensions
{
public static void ExtractAllFiles(this RDAReader reader, String Path)
public static void ExtractFiles(this RDAReader reader, List<RDAFile> files, String Path)
{
RDAExplorer.RDAFileExtension.ExtractAll(reader.rdaFolder.GetAllFiles(), Path);
RDAExplorer.RDAFileExtension.ExtractAll(files, Path);
}
}
}

0 comments on commit 4c284ca

Please sign in to comment.