mirror of
https://github.com/JuniorDark/RustyHearts-Launcher.git
synced 2026-05-07 05:21:44 -04:00
Refactor zip handling for System.IO.Compression
This commit is contained in:
parent
9fb4b4a6af
commit
8526698244
1 changed files with 11 additions and 7 deletions
|
|
@ -1,8 +1,8 @@
|
|||
using System.IO.Compression;
|
||||
using RHLauncher.RHLauncher.Helper;
|
||||
using RHLauncher.RHLauncher.Helper;
|
||||
using RHLauncher.RHLauncher.i8n;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO.Compression;
|
||||
using System.Net;
|
||||
|
||||
namespace RHLauncher.RHLauncher.Http
|
||||
|
|
@ -152,8 +152,11 @@ namespace RHLauncher.RHLauncher.Http
|
|||
// Calculate total uncompressed size of all files in all zip archives
|
||||
long totalUncompressedSize = fileEntries.Sum(file =>
|
||||
{
|
||||
using ZipArchive zip = ZipFile.OpenRead(file);
|
||||
return zip.Entries.Sum(entry => entry.Length);
|
||||
using FileStream fs = new(file, FileMode.Open, FileAccess.Read);
|
||||
using ZipArchive zip = new(fs, ZipArchiveMode.Read);
|
||||
|
||||
static long entryLength(ZipArchiveEntry entry) => entry.Length;
|
||||
return zip.Entries.Sum(entryLength);
|
||||
});
|
||||
long totalExtracted = 0;
|
||||
|
||||
|
|
@ -163,7 +166,8 @@ namespace RHLauncher.RHLauncher.Http
|
|||
{
|
||||
await Task.Run(() =>
|
||||
{
|
||||
using ZipArchive zip = ZipFile.OpenRead(file);
|
||||
using FileStream fs = new(file, FileMode.Open, FileAccess.Read);
|
||||
using ZipArchive zip = new(fs, ZipArchiveMode.Read);
|
||||
foreach (var entry in zip.Entries)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
|
@ -175,7 +179,7 @@ namespace RHLauncher.RHLauncher.Http
|
|||
Directory.CreateDirectory(directoryPath);
|
||||
}
|
||||
|
||||
entry.ExtractToFile(destinationPath, true);
|
||||
entry.ExtractToFile(destinationPath, overwrite: true);
|
||||
totalExtracted += entry.Length;
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
|
|
@ -218,4 +222,4 @@ namespace RHLauncher.RHLauncher.Http
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue