Skip to content

Commit

Permalink
Merge pull request #27 from vhandziuk/feature/adjust-configuration-da…
Browse files Browse the repository at this point in the history
…ta-structure

Feature/adjust configuration data structure
  • Loading branch information
vhandziuk authored Aug 5, 2023
2 parents 1c39e29 + d78db15 commit 6204a3e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 61 deletions.
41 changes: 21 additions & 20 deletions FileExtractor.Data/CsvFileInfoProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,34 @@ namespace FileExtractor.Data;

public sealed class CsvFileInfoProvider : ICsvFileInfoProvider
{
private const int RequiredColumnCount = 3;

public IEnumerable<FileInfoData> EnumerateEntries(string filePath)
{
using (var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
using (var reader = new StreamReader(stream))
using var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
using var reader = new StreamReader(stream);

while (reader.ReadLine() is string line)
{
while (reader.ReadLine() is string line)
var data = line.Split(',');
if (data.Length != RequiredColumnCount)
{
var data = line.Split(',');
if (data.Length != 2)
{
throw new Exception(
"Malformed configuration file. " +
"Data must contain 2 columns containing file name " +
"and [optionally] subfolder path or an empty space separated by a comma");
}

var directory = Path.GetDirectoryName(data[0]) ?? string.Empty;
var name = Path.GetFileName(data[0]);
var location = data[1];
throw new Exception(
"Malformed configuration file. " +
"Data must contain 3 columns containing file name, " +
"extraction subfolder, and path in the archive");
}

if (string.IsNullOrWhiteSpace(name))
{
throw new Exception("File name cannot be empty or whitespace");
}
var name = data[0];
var directory = data[1];
var location = data[2];

yield return new FileInfoData(directory, name, location);
if (string.IsNullOrWhiteSpace(name))
{
throw new Exception("File name cannot be empty or whitespace");
}

yield return new FileInfoData(directory, name, location);
}
}
}
14 changes: 2 additions & 12 deletions FileExtractor/Application/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,7 @@ namespace FileExtractor.Application;

internal sealed class App : IApp
{
private readonly string[] _supportedArchiveExtensions =
{
".zip",
".rar",
".7z",
".tar",
".bz2",
".gz",
".lz",
".xz"
};
private static readonly HashSet<string> SupportedArchiveExtensions = new() { ".zip", ".rar", ".7z", ".tar", ".bz2", ".gz", ".lz", ".xz" };

private readonly IEnvironment _environment;
private readonly IFileSystemUtils _fileSystemUtils;
Expand Down Expand Up @@ -78,7 +68,7 @@ public async ValueTask RunAsync(ICommandLineOptions options)
var archives = _fileSystemUtils
.GetFiles(sourcePath, "*.*", SearchOption.AllDirectories)
.Where(filePath =>
_supportedArchiveExtensions.Contains(Path.GetExtension(filePath), StringComparer.OrdinalIgnoreCase));
SupportedArchiveExtensions.Contains(Path.GetExtension(filePath), StringComparer.OrdinalIgnoreCase));

if (!archives.Any())
{
Expand Down
34 changes: 14 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,21 @@ Command line utility for selective unpacking of archived files.

The tool uses a CSV configuration file that provides file names and relative locations of the entries to extract. It checks all the supported archives in the given `source` path and tries to extract specific archived entries as defined in the configuration.

Supported archive types:
- Zip
- Rar
- 7z
- Tar
- Bz2
- Gz
- Lz
- Xz
Supported archive types: **Zip, Rar, 7z, Tar, Bz2, Gz, Lz, Xz**

**_NOTE:_** The tool does not support password-protected archives.

**_NOTE:_** The application is built with .NET 6. The respective .NET runtime (if missing) will be deployed as a prerequisite by the application installer.

## Configuration file structure

Configuration file must contain 2 columns, separated by a comma. The default file name is `configuration.csv`, and the default file location is the same as the `source` folder.
Configuration file must contain 3 columns, separated by a comma. The default file name is `configuration.csv`, and the default file location is the same as the `source` folder.

The first value is the name of the archive entry to be extracted (e.g., test1.txt). If the file is found in any of the archives (in a specified subpath, defined by the second value), it is then unpacked to the destination path. The entry name can optionally be prefixed by a relative path, (e.g., Output\test1.txt). In this case, the file will be unpacked to the corresponding subfolder of the destination path.
The first column is the name of the archive entry to be extracted (e.g., test1.txt). If the file is found in any of the archives (in a specified subpath, defined by the third column), it is then unpacked to the destination path. This value also supports simple wildcards `*` and `?`.

The second value is a part of the relative subpath of the entry in archive. If the entry is located in the archive root, the value should be left blank.
The second column is a relative path (e.g., Root\Output). When specified, the file will be unpacked to the corresponding subfolder of the destination path.

The third column is a part of the relative subpath of the entry in archive. If the entry is located in the archive root, the value should be left blank.

### Example archive data and configuration file

Expand All @@ -50,14 +44,14 @@ Let's imagine we have an archive with the following structure:
Let's consider that we want to extract every even file to the root of the destination directory, and every odd file - to the `Output` subfolder of the destination directory. Then, the corresponding configuration file will look as follows:

```
test01.txt,
test03.txt,Subfolder01
test05.txt,Nested
test07.txt,Subfolder02
Output\test02.txt,
Output\test04.txt,Subfolder01
Output\test06.txt,Subfolder01\Nested
Output\test08.txt,Subfolder02
test01.txt,,
test03.txt,,Subfolder01
test05.txt,,Nested
test07.txt,,Subfolder02
test02.txt,Output,
test04.txt,Output,Subfolder01
test06.txt,Output,Subfolder01\Nested
test08.txt,Output,Subfolder02
```

**_NOTE:_** It is not required to provide a relative subpath to archive entries. It is only necessary when archives contain multiple entries with the same file name but located in different subfolders of the archive.
Expand Down
20 changes: 11 additions & 9 deletions Setup/Dependencies.pas
Original file line number Diff line number Diff line change
Expand Up @@ -370,35 +370,37 @@ procedure Dependency_AddDotNet50Desktop;
procedure Dependency_AddDotNet60;
begin
// https://dotnet.microsoft.com/download/dotnet/6.0
if not Dependency_IsNetCoreInstalled('Microsoft.NETCore.App 6.0.6') then begin
if not Dependency_IsNetCoreInstalled('Microsoft.NETCore.App 6.0.20') then begin
Dependency_Add('dotnet60' + Dependency_ArchSuffix + '.exe',
'/lcid ' + IntToStr(GetUILanguage) + ' /passive /norestart',
'.NET Runtime 6.0.6' + Dependency_ArchTitle,
Dependency_String('https://download.visualstudio.microsoft.com/download/pr/60c4767e-c0df-491b-970c-cf69d0c2c581/524ccc6ff8aa96120753ab387bf22d5d/dotnet-runtime-6.0.6-win-x86.exe', 'https://download.visualstudio.microsoft.com/download/pr/7989338b-8ae9-4a5d-8425-020148016812/c26361fde7f706279265a505b4d1d93a/dotnet-runtime-6.0.6-win-x64.exe'),
'.NET Runtime 6.0.20' + Dependency_ArchTitle,
Dependency_String('https://download.visualstudio.microsoft.com/download/pr/3be5ee3a-c171-4cd2-ab98-00ca5c11eb8c/6fd31294b0c6c670ab5c060592935203/dotnet-runtime-6.0.20-win-x86.exe', 'https://download.visualstudio.microsoft.com/download/pr/3cfb6d2a-afbe-4ae7-8e5b-776f350654cc/6e8d858a60fe15381f3c84d8ca66c4a7/dotnet-runtime-6.0.20-win-x64.exe
'),
'', False, False);
end;
end;

procedure Dependency_AddDotNet60Asp;
begin
// https://dotnet.microsoft.com/download/dotnet/6.0
if not Dependency_IsNetCoreInstalled('Microsoft.AspNetCore.App 6.0.6') then begin
if not Dependency_IsNetCoreInstalled('Microsoft.AspNetCore.App 6.0.20') then begin
Dependency_Add('dotnet60asp' + Dependency_ArchSuffix + '.exe',
'/lcid ' + IntToStr(GetUILanguage) + ' /passive /norestart',
'ASP.NET Core Runtime 6.0.6' + Dependency_ArchTitle,
Dependency_String('https://download.visualstudio.microsoft.com/download/pr/b68b5e5c-aeaa-4efd-b194-b37bd73eff64/b2afe8dbd41c8f266f8df26df8fe4ce9/aspnetcore-runtime-6.0.6-win-x86.exe', 'https://download.visualstudio.microsoft.com/download/pr/7751b01b-4548-478d-ac63-ca57f2b66a3f/3339efd1fde8f62fed0ac2406f8bc559/aspnetcore-runtime-6.0.6-win-x64.exe'),
'ASP.NET Core Runtime 6.0.20' + Dependency_ArchTitle,
Dependency_String('https://download.visualstudio.microsoft.com/download/pr/0e37c76c-53b4-4eea-8f5c-6ad2f8d5fe3c/88a8620329ced1aee271992a5b56d236/aspnetcore-runtime-6.0.20-win-x86.exe', 'https://download.visualstudio.microsoft.com/download/pr/be9f67fd-60af-45b1-9bca-a7bcc0e86e7e/6a750f7d7432937b3999bb4c5325062a/aspnetcore-runtime-6.0.20-win-x64.exe'),
'', False, False);
end;
end;

procedure Dependency_AddDotNet60Desktop;
begin
// https://dotnet.microsoft.com/download/dotnet/6.0
if not Dependency_IsNetCoreInstalled('Microsoft.WindowsDesktop.App 6.0.6') then begin
if not Dependency_IsNetCoreInstalled('Microsoft.WindowsDesktop.App 6.0.20') then begin
Dependency_Add('dotnet60desktop' + Dependency_ArchSuffix + '.exe',
'/lcid ' + IntToStr(GetUILanguage) + ' /passive /norestart',
'.NET Desktop Runtime 6.0.6' + Dependency_ArchTitle,
Dependency_String('https://download.visualstudio.microsoft.com/download/pr/cc04076c-d188-4c20-9b4f-89be06f1a39c/32da746ef46fbeedb4f609b67cb451c3/windowsdesktop-runtime-6.0.6-win-x86.exe', 'https://download.visualstudio.microsoft.com/download/pr/9d6b6b34-44b5-4cf4-b924-79a00deb9795/2f17c30bdf42b6a8950a8552438cf8c1/windowsdesktop-runtime-6.0.6-win-x64.exe'),
'.NET Desktop Runtime 6.0.20' + Dependency_ArchTitle,
Dependency_String('https://download.visualstudio.microsoft.com/download/pr/0413b619-3eb2-4178-a78e-8d1aafab1a01/5247f08ea3c13849b68074a2142fbf31/windowsdesktop-runtime-6.0.20-win-x86.exe', 'https://download.visualstudio.microsoft.com/download/pr/1146f414-17c7-4184-8b10-1addfa5315e4/39db5573efb029130add485566320d74/windowsdesktop-runtime-6.0.20-win-x64.exe
'),
'', False, False);
end;
end;
Expand Down

0 comments on commit 6204a3e

Please sign in to comment.