use sharpziplib

0b25566a7d
1dc52d21b3
This commit is contained in:
bluepilledgreat 2024-04-21 15:48:01 +01:00
parent b7dcc5ff18
commit b24f712d53
3 changed files with 16 additions and 58 deletions

View File

@ -44,6 +44,7 @@
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.49-beta">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="SharpZipLib" Version="1.4.2" />
</ItemGroup>
<ItemGroup>

View File

@ -1420,75 +1420,26 @@ namespace Bloxstrap
}
}
private async Task ExtractPackage(Package package)
private Task ExtractPackage(Package package)
{
const string LOG_IDENT = "Bootstrapper::ExtractPackage";
if (_cancelFired)
return;
return Task.CompletedTask;
string packageLocation = Path.Combine(Paths.Downloads, package.Signature);
string packageFolder = Path.Combine(_versionFolder, PackageDirectories[package.Name]);
App.Logger.WriteLine(LOG_IDENT, $"Reading {package.Name}...");
App.Logger.WriteLine(LOG_IDENT, $"Extracting {package.Name}...");
var archive = await Task.Run(() => ZipFile.OpenRead(packageLocation));
App.Logger.WriteLine(LOG_IDENT, $"Read {package.Name}. Extracting to {packageFolder}...");
// yeah so because roblox is roblox, these packages aren't actually valid zip files
// besides the fact that they use backslashes instead of forward slashes for directories,
// empty folders that *BEGIN* with a backslash in their fullname, but have an empty name are listed here for some reason...
foreach (var entry in archive.Entries)
{
if (_cancelFired)
return;
if (String.IsNullOrEmpty(entry.Name))
continue;
string extractPath = Path.Combine(packageFolder, entry.FullName);
string? directory = Path.GetDirectoryName(extractPath);
if (directory is not null)
Directory.CreateDirectory(directory);
var fileManifest = _versionFileManifest.FirstOrDefault(x => x.Name == Path.Combine(PackageDirectories[package.Name], entry.FullName));
string? signature = fileManifest?.Signature;
if (File.Exists(extractPath))
{
if (signature is not null && MD5Hash.FromFile(extractPath) == signature)
continue;
File.Delete(extractPath);
}
bool retry = false;
do
{
using var entryStream = entry.Open();
using var fileStream = new FileStream(extractPath, FileMode.Create, FileAccess.ReadWrite, FileShare.None, bufferSize: 0x1000);
await entryStream.CopyToAsync(fileStream);
if (signature is not null && MD5Hash.FromStream(fileStream) != signature)
{
if (retry)
throw new AssertionException($"Checksum of {entry.FullName} post-extraction did not match manifest");
retry = true;
}
}
while (retry);
File.SetLastWriteTime(extractPath, entry.LastWriteTime.DateTime);
}
var fastZip = new ICSharpCode.SharpZipLib.Zip.FastZip();
fastZip.ExtractZip(packageLocation, packageFolder, null);
App.Logger.WriteLine(LOG_IDENT, $"Finished extracting {package.Name}");
_packagesExtracted += 1;
return Task.CompletedTask;
}
private async Task ExtractFileFromPackage(string packageName, string fileName)

View File

@ -217,9 +217,15 @@
<TextBlock Margin="0,2,0,0" FontSize="12" Text="MIT License" Foreground="{DynamicResource TextFillColorTertiaryBrush}" />
</StackPanel>
</ui:CardAction>
<ui:CardAction Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Margin="0,8,0,0" Command="models:GlobalViewModel.OpenWebpageCommand" CommandParameter="https://github.com/MaximumADHD/Roblox-Studio-Mod-Manager/blob/main/LICENSE">
<ui:CardAction Grid.Row="1" Grid.Column="1" Margin="0,8,8,0" Command="models:GlobalViewModel.OpenWebpageCommand" CommandParameter="https://github.com/MaximumADHD/Roblox-Studio-Mod-Manager/blob/main/LICENSE">
<StackPanel>
<TextBlock FontSize="14" Text="Roblox Studio Mod Manager by MaximumADHD" />
<TextBlock FontSize="13" Text="RSMM by MaximumADHD" />
<TextBlock Margin="0,2,0,0" FontSize="12" Text="MIT License" Foreground="{DynamicResource TextFillColorTertiaryBrush}" />
</StackPanel>
</ui:CardAction>
<ui:CardAction Grid.Row="1" Grid.Column="2" Margin="0,8,0,0" Command="models:GlobalViewModel.OpenWebpageCommand" CommandParameter="https://github.com/icsharpcode/SharpZipLib/blob/master/LICENSE.txt">
<StackPanel>
<TextBlock FontSize="13" Text="SharpZipLib by icsharpcode" />
<TextBlock Margin="0,2,0,0" FontSize="12" Text="MIT License" Foreground="{DynamicResource TextFillColorTertiaryBrush}" />
</StackPanel>
</ui:CardAction>