diff --git a/FoliCon/Modules/Extension/StreamExtension.cs b/FoliCon/Modules/Extension/StreamExtension.cs index 351ed27..6f339a0 100644 --- a/FoliCon/Modules/Extension/StreamExtension.cs +++ b/FoliCon/Modules/Extension/StreamExtension.cs @@ -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); diff --git a/FoliCon/ViewModels/ManualExplorerViewModel.cs b/FoliCon/ViewModels/ManualExplorerViewModel.cs index 8123c7f..cfad91b 100644 --- a/FoliCon/ViewModels/ManualExplorerViewModel.cs +++ b/FoliCon/ViewModels/ManualExplorerViewModel.cs @@ -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();