Skip to content

Commit 58795f4

Browse files
authored
Fix: Fixed multi-part RAR extraction failure and improved error logging (#17712)
1 parent 6a5ac59 commit 58795f4

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/Files.App/Services/Storage/StorageArchiveService.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Files.Shared.Helpers;
55
using ICSharpCode.SharpZipLib.Core;
66
using ICSharpCode.SharpZipLib.Zip;
7+
using Microsoft.Extensions.Logging;
78
using SevenZip;
89
using System.IO;
910
using System.Text;
@@ -137,9 +138,10 @@ async Task<bool> DecompressAsyncWithSevenZip(string archiveFilePath, string dest
137138

138139
isSuccess = true;
139140
}
140-
catch
141+
catch (Exception ex)
141142
{
142143
isSuccess = false;
144+
App.Logger.LogError(ex, "SevenZipLib error extracting archive file.");
143145
}
144146
finally
145147
{
@@ -288,7 +290,7 @@ await ThreadingService.ExecuteOnUiThreadAsync(() =>
288290
catch (Exception ex)
289291
{
290292
isSuccess = false;
291-
Console.WriteLine($"Error during decompression: {ex.Message}");
293+
App.Logger.LogError(ex, "SharpZipLib error during decompression.");
292294
}
293295
finally
294296
{
@@ -362,7 +364,7 @@ public async Task<bool> IsEncodingUndeterminedAsync(string archiveFilePath)
362364
}
363365
catch (Exception ex)
364366
{
365-
Console.WriteLine($"SharpZipLib error: {ex.Message}");
367+
App.Logger.LogError(ex, "SharpZipLib error.");
366368
return true;
367369
}
368370
}
@@ -398,7 +400,7 @@ public async Task<bool> IsEncodingUndeterminedAsync(string archiveFilePath)
398400
}
399401
catch (Exception ex)
400402
{
401-
Console.WriteLine($"SharpZipLib error: {ex.Message}");
403+
App.Logger.LogError(ex, "SharpZipLib error detecting encoding.");
402404
return null;
403405
}
404406
}
@@ -409,8 +411,9 @@ public async Task<bool> IsEncodingUndeterminedAsync(string archiveFilePath)
409411
return await FilesystemTasks.Wrap(async () =>
410412
{
411413
BaseStorageFile archive = await StorageHelpers.ToStorageItem<BaseStorageFile>(archiveFilePath);
412-
413-
var extractor = new SevenZipExtractor(await archive.OpenStreamForReadAsync(), password);
414+
var extractor = string.IsNullOrEmpty(password)
415+
? new SevenZipExtractor(archive.Path)
416+
: new SevenZipExtractor(archive.Path, password);
414417

415418
// Force to load archive (1665013614u)
416419
return extractor?.ArchiveFileData is null ? null : extractor;

0 commit comments

Comments
 (0)