Skip to content

Commit

Permalink
Change approch to filter files extract by "gallery extraction" feature (
Browse files Browse the repository at this point in the history
  • Loading branch information
DineshSolanki authored Jul 25, 2024
1 parent 33a0544 commit 8cdfe76
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
12 changes: 3 additions & 9 deletions FoliCon/Modules/Extension/StreamExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,13 @@ public static void ExtractPngAndIcoToDirectory(this Stream archiveStream, string
{
using var reader = ArchiveFactory.Open(archiveStream, ReaderOptions);
var pngAndIcoEntries = reader.Entries.Where(entry =>
(!entry.IsDirectory && !IsUnwantedDirectoryOrFileType(entry)) && FileUtils.IsPngOrIco(entry.Key));
!IsUnwantedDirectoryOrFileType(entry) && FileUtils.IsPngOrIco(entry.Key)).ToList();

var pngAndIcoFiles = pngAndIcoEntries.GroupBy(entry => Path.GetFileNameWithoutExtension(entry.Key))
.Select(group =>
group.Any(entry => Path.GetExtension(entry.Key) == ".png")
? group.First(entry => Path.GetExtension(entry.Key) == ".png")
: group.First())
.ToArray();

var totalCount = pngAndIcoFiles.Length;
var totalCount = pngAndIcoEntries.Count;
var extractionProgress = new ProgressInfo(0, totalCount, LangProvider.Instance.Extracting);
progressCallback.Report(extractionProgress);
foreach (var entry in pngAndIcoFiles)
foreach (var entry in pngAndIcoEntries)
{
cancellationToken.ThrowIfCancellationRequested();
entry.WriteToDirectory(targetPath, ExtractionSettings);
Expand Down
21 changes: 17 additions & 4 deletions FoliCon/ViewModels/ManualExplorerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,24 @@ public virtual async void OnDialogOpened(IDialogParameters parameters)
{
Logger.Debug("User cancelled manual extraction");

}
}

DArtDownloadResponse.LocalDownloadPath?.ToDirectoryInfo()
.GetFiles()
.ForEach(fileInfo => Directory.AddOnUI(fileInfo.FullName));
var extractedFiles = DArtDownloadResponse.LocalDownloadPath?.ToDirectoryInfo()
.GetFiles();
Logger.Trace("Total Files Extracted {TotalFiles}", extractedFiles?.Length);
if (extractedFiles?.Length > 0)
{
var pngOrAvailableFile = extractedFiles
.GroupBy(entry => Path.GetFileNameWithoutExtension(entry.Name))
.Select(group =>
{
var pngFile = group.FirstOrDefault(entry => Path.GetExtension(entry.Name) == ".png");
return pngFile ?? group.First();
}).ToList();

Logger.Trace("Total extracted files after filtering {TotalFiles}", pngOrAvailableFile.Count);
pngOrAvailableFile.ForEach(entry => Directory.AddOnUI(entry.FullName));
}

IsBusy = false;
_cts.Dispose();
Expand Down

0 comments on commit 8cdfe76

Please sign in to comment.