update to create 7z archives

This commit is contained in:
IsWaffle 2024-03-22 13:03:07 -04:00
parent 75194f31a5
commit c272c0da54
8 changed files with 52 additions and 20 deletions

View File

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

View File

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

View File

@ -16,6 +16,7 @@ using System.Reflection;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Timers; using System.Timers;
using PatcherUtils.Model;
namespace PatchGenerator.ViewModels namespace PatchGenerator.ViewModels
{ {
@ -140,12 +141,19 @@ namespace PatchGenerator.ViewModels
System.Threading.Thread.Sleep(2000); 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; 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")); PatchItemCollection.Add(new PatchItem("Done"));
} }

View File

@ -1,7 +1,9 @@
using PatcherUtils.Model; using System;
using System.Diagnostics; using PatcherUtils.Model;
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
using Aki.Common.Utils;
using SevenZip;
namespace PatcherUtils namespace PatcherUtils
{ {
@ -18,12 +20,12 @@ namespace PatcherUtils
/// </summary> /// </summary>
public static string PatchFolder = "Aki_Patches"; public static string PatchFolder = "Aki_Patches";
private static string SevenZExe = "7za.exe"; private static string SevenZDll = "7z.dll";
/// <summary> /// <summary>
/// The path to the 7za.exe file in the <see cref="TempDir"/> /// The path to the 7za.exe file in the <see cref="TempDir"/>
/// </summary> /// </summary>
public static string SevenZExePath = $"{TempDir}\\{SevenZExe}"; public static string SevenZDllPath = $"{TempDir}\\{SevenZDll}";
private static string PatcherClient = "PatchClient.exe"; private static string PatcherClient = "PatchClient.exe";
/// <summary> /// <summary>
@ -79,9 +81,9 @@ namespace PatcherUtils
{ {
switch (resource) 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; break;
} }
case string a when a.EndsWith(PatcherClient): 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, ArchiveFormat = OutArchiveFormat.SevenZip,
Arguments = $"a -mm=LZMA {DestinationPath} {SourcePath}" 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> /// <summary>

View File

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

Binary file not shown.