Merge pull request 'update to create 7z archives' (#15) from imp/7z-compression into net8

Reviewed-on: #15
This commit is contained in:
IsWaffle 2024-03-22 18:33:59 +00:00
commit ecdef3dcec
8 changed files with 52 additions and 20 deletions

View File

@ -4,8 +4,8 @@
<TargetFramework>net8.0</TargetFramework>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<Nullable>enable</Nullable>
<AssemblyVersion>2.11.0</AssemblyVersion>
<FileVersion>2.11.0</FileVersion>
<AssemblyVersion>2.12.0</AssemblyVersion>
<FileVersion>2.12.0</FileVersion>
</PropertyGroup>
<ItemGroup>
<AvaloniaResource Include="Assets\**" />

View File

@ -4,8 +4,8 @@
<TargetFramework>net8.0</TargetFramework>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<Nullable>enable</Nullable>
<AssemblyVersion>2.11.0</AssemblyVersion>
<FileVersion>2.11.0</FileVersion>
<AssemblyVersion>2.12.0</AssemblyVersion>
<FileVersion>2.12.0</FileVersion>
</PropertyGroup>
<ItemGroup>
@ -27,7 +27,7 @@
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\7za.exe" />
<None Remove="Resources\7z.dll" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.10.11" />

View File

@ -16,6 +16,7 @@ using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using PatcherUtils.Model;
namespace PatchGenerator.ViewModels
{
@ -140,12 +141,19 @@ namespace PatchGenerator.ViewModels
System.Threading.Thread.Sleep(2000);
PatchItemCollection.Add(new PatchItem("Kicking off 7zip ..."));
PatchItemCollection.Add(new PatchItem("Zipping patcher ..."));
LazyOperations.StartZipProcess(generationInfo.PatchName.FromCwd(), $"{generationInfo.PatchName}.zip".FromCwd());
ProgressMessage = "Zipping patcher";
IndeterminateProgress = false;
var progress = new Progress<int>(p =>
{
PatchPercent = p;
});
LazyOperations.CompressDirectory(generationInfo.PatchName.FromCwd(), $"{generationInfo.PatchName}.7z".FromCwd(), progress);
PatchItemCollection.Add(new PatchItem("Done"));
}

View File

@ -1,7 +1,9 @@
using PatcherUtils.Model;
using System.Diagnostics;
using System;
using PatcherUtils.Model;
using System.IO;
using System.Reflection;
using Aki.Common.Utils;
using SevenZip;
namespace PatcherUtils
{
@ -18,12 +20,12 @@ namespace PatcherUtils
/// </summary>
public static string PatchFolder = "Aki_Patches";
private static string SevenZExe = "7za.exe";
private static string SevenZDll = "7z.dll";
/// <summary>
/// The path to the 7za.exe file in the <see cref="TempDir"/>
/// </summary>
public static string SevenZExePath = $"{TempDir}\\{SevenZExe}";
public static string SevenZDllPath = $"{TempDir}\\{SevenZDll}";
private static string PatcherClient = "PatchClient.exe";
/// <summary>
@ -79,9 +81,9 @@ namespace PatcherUtils
{
switch (resource)
{
case string a when a.EndsWith(SevenZExe):
case string a when a.EndsWith(SevenZDll):
{
StreamResourceOut(assembly, resource, SevenZExePath);
StreamResourceOut(assembly, resource, SevenZDllPath);
break;
}
case string a when a.EndsWith(PatcherClient):
@ -98,17 +100,34 @@ namespace PatcherUtils
}
}
public static void StartZipProcess(string SourcePath, string DestinationPath)
public static void CompressDirectory(string SourceDirectoryPath, string DestinationFilePath, IProgress<int> progress)
{
ProcessStartInfo procInfo = new ProcessStartInfo()
var outputFile = new FileInfo(DestinationFilePath);
SevenZipBase.SetLibraryPath(SevenZDllPath);
var compressor = new SevenZipCompressor()
{
FileName = SevenZExePath,
Arguments = $"a -mm=LZMA {DestinationPath} {SourcePath}"
ArchiveFormat = OutArchiveFormat.SevenZip,
CompressionMethod = CompressionMethod.Lzma2,
CompressionLevel = CompressionLevel.Normal
};
Process.Start(procInfo);
compressor.Compressing += (_, args) =>
{
progress.Report(args.PercentDone);
};
PatchLogger.LogInfo($"Zip process started");
using var outputStream = outputFile.OpenWrite();
compressor.CompressDirectory(SourceDirectoryPath, outputStream);
outputFile.Refresh();
// failed to compress data
if (!outputFile.Exists || outputFile.Length == 0)
{
Logger.LogError("Failed to compress patcher");
}
}
/// <summary>

View File

@ -11,6 +11,7 @@
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\7z.dll" />
<EmbeddedResource Include="Resources\xdelta3.exe" />
</ItemGroup>
@ -20,4 +21,8 @@
</Reference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Squid-Box.SevenZipSharp" Version="1.6.1.23" />
</ItemGroup>
</Project>

Binary file not shown.