|
1 | 1 | using PicView.Core.DebugTools; |
2 | 2 | using PicView.Core.FileHandling; |
3 | | -using SharpCompress.Common; |
4 | 3 | using SharpCompress.Readers; |
5 | 4 |
|
6 | 5 | namespace PicView.Core.ArchiveHandling; |
@@ -62,43 +61,36 @@ public static async Task<bool> ExtractArchiveAsync(string archivePath, |
62 | 61 | } |
63 | 62 |
|
64 | 63 | await using var stream = File.OpenRead(archivePath); |
65 | | - using var reader = ReaderFactory.Open(stream); |
| 64 | + await using var reader = await ReaderFactory.OpenAsyncReader(stream); |
66 | 65 |
|
67 | 66 | var count = 0; |
68 | | - |
69 | | - await Task.Run(() => |
| 67 | + |
| 68 | + // Process each entry asynchronously to avoid blocking the thread |
| 69 | + while (await reader.MoveToNextEntryAsync()) |
70 | 70 | { |
71 | | - // Process each entry asynchronously to avoid blocking the thread |
72 | | - while (reader.MoveToNextEntry()) |
| 71 | + if (reader.Entry.IsDirectory) |
| 72 | + { |
| 73 | + continue; |
| 74 | + } |
| 75 | + |
| 76 | + // Extract only if the file is supported |
| 77 | + var entryFileName = reader.Entry.Key; |
| 78 | + if (entryFileName.IsSupported()) |
73 | 79 | { |
74 | | - if (reader.Entry.IsDirectory) |
75 | | - { |
76 | | - continue; |
77 | | - } |
78 | | - |
79 | | - // Extract only if the file is supported |
80 | | - var entryFileName = reader.Entry.Key; |
81 | | - if (entryFileName.IsSupported()) |
82 | | - { |
83 | | - reader.WriteEntryToDirectory(tempDirectory, new ExtractionOptions |
84 | | - { |
85 | | - ExtractFullPath = true, |
86 | | - Overwrite = true |
87 | | - }); |
| 80 | + await reader.WriteEntryToDirectoryAsync(tempDirectory); |
88 | 81 | #if DEBUG |
89 | | - Console.WriteLine($"Extracted: {entryFileName}"); |
| 82 | + Console.WriteLine($"Extracted: {entryFileName}"); |
90 | 83 | #endif |
91 | 84 |
|
92 | | - count++; |
93 | | - } |
94 | | - else |
95 | | - { |
| 85 | + count++; |
| 86 | + } |
| 87 | + else |
| 88 | + { |
96 | 89 | #if DEBUG |
97 | | - Console.WriteLine($"Skipped unsupported file: {entryFileName}"); |
| 90 | + Console.WriteLine($"Skipped unsupported file: {entryFileName}"); |
98 | 91 | #endif |
99 | | - } |
100 | 92 | } |
101 | | - }); |
| 93 | + } |
102 | 94 |
|
103 | 95 | if (count <= 0) |
104 | 96 | { |
|
0 commit comments