add compression task to handle creating 7z file
This commit is contained in:
parent
1b0acdc262
commit
8d62adb25e
@ -5,8 +5,8 @@
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<AssemblyVersion>1.5.6</AssemblyVersion>
|
||||
<FileVersion>1.5.6</FileVersion>
|
||||
<AssemblyVersion>1.5.7</AssemblyVersion>
|
||||
<FileVersion>1.5.7</FileVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@ -19,6 +19,7 @@
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="6.0.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
<PackageReference Include="Spectre.Console" Version="0.44.0" />
|
||||
<PackageReference Include="Squid-Box.SevenZipSharp" Version="1.6.1.23" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@ -36,4 +37,9 @@
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="Resources\7z.dll" />
|
||||
<EmbeddedResource Include="Resources\7z.dll" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
44
EftPatchHelper/EftPatchHelper/Helpers/FileHelper.cs
Normal file
44
EftPatchHelper/EftPatchHelper/Helpers/FileHelper.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using System.Reflection;
|
||||
using Spectre.Console;
|
||||
|
||||
namespace EftPatchHelper.Helpers;
|
||||
|
||||
public class FileHelper
|
||||
{
|
||||
public bool StreamAssemblyResourceOut(string resourceName, string outputFilePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
var assembly = Assembly.GetExecutingAssembly();
|
||||
|
||||
FileInfo outputFile = new FileInfo(outputFilePath);
|
||||
|
||||
if (outputFile.Exists)
|
||||
{
|
||||
outputFile.Delete();
|
||||
}
|
||||
|
||||
if (!outputFile.Directory.Exists)
|
||||
{
|
||||
Directory.CreateDirectory(outputFile.Directory.FullName);
|
||||
}
|
||||
|
||||
var resName = assembly.GetManifestResourceNames().First(x => x.EndsWith(resourceName));
|
||||
|
||||
using (FileStream fs = File.Create(outputFilePath))
|
||||
using (Stream s = assembly.GetManifestResourceStream(resName))
|
||||
{
|
||||
s.CopyTo(fs);
|
||||
}
|
||||
|
||||
outputFile.Refresh();
|
||||
return outputFile.Exists;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AnsiConsole.WriteException(ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
45
EftPatchHelper/EftPatchHelper/Helpers/ZipHelper.cs
Normal file
45
EftPatchHelper/EftPatchHelper/Helpers/ZipHelper.cs
Normal file
@ -0,0 +1,45 @@
|
||||
using SevenZip;
|
||||
using Spectre.Console;
|
||||
|
||||
namespace EftPatchHelper.Helpers;
|
||||
|
||||
public class ZipHelper
|
||||
{
|
||||
public string DllPath = Path.Join(Environment.CurrentDirectory, "7z.dll");
|
||||
public bool Compress(DirectoryInfo folder, FileInfo outputArchive,
|
||||
IProgress<double> progress)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var outputStream = outputArchive.OpenWrite();
|
||||
|
||||
SevenZipBase.SetLibraryPath(DllPath);
|
||||
|
||||
var compressor = new SevenZipCompressor()
|
||||
{
|
||||
CompressionLevel = CompressionLevel.Normal,
|
||||
CompressionMethod = CompressionMethod.Lzma2,
|
||||
ArchiveFormat = OutArchiveFormat.SevenZip
|
||||
};
|
||||
|
||||
compressor.Compressing += (_, args) => { progress.Report(args.PercentDone); };
|
||||
|
||||
compressor.CompressDirectory(folder.FullName, outputStream);
|
||||
|
||||
outputArchive.Refresh();
|
||||
|
||||
if (!outputArchive.Exists)
|
||||
{
|
||||
AnsiConsole.MarkupLine("output archive not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AnsiConsole.WriteException(ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
namespace EftPatchHelper.Interfaces;
|
||||
|
||||
public interface ICompressPatcherTask : ITaskable
|
||||
{
|
||||
}
|
@ -92,6 +92,7 @@ namespace EftPatchHelper
|
||||
services.AddTransient<IFileProcessingTasks, FileProcessingTasks>();
|
||||
services.AddTransient<IPatchGenTasks, PatchGenTasks>();
|
||||
services.AddTransient<IPatchTestingTasks, PatchTestingTasks>();
|
||||
services.AddTransient<ICompressPatcherTask, CompressPatcherTask>();
|
||||
services.AddTransient<IReleaseCreator, CreateReleaseTasks>();
|
||||
services.AddTransient<IUploadTasks, UploadTasks>();
|
||||
services.AddTransient<Program>();
|
||||
|
BIN
EftPatchHelper/EftPatchHelper/Resources/7z.dll
Normal file
BIN
EftPatchHelper/EftPatchHelper/Resources/7z.dll
Normal file
Binary file not shown.
64
EftPatchHelper/EftPatchHelper/Tasks/CompressPatcherTask.cs
Normal file
64
EftPatchHelper/EftPatchHelper/Tasks/CompressPatcherTask.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using EftPatchHelper.Extensions;
|
||||
using EftPatchHelper.Helpers;
|
||||
using EftPatchHelper.Interfaces;
|
||||
using EftPatchHelper.Model;
|
||||
using Spectre.Console;
|
||||
|
||||
namespace EftPatchHelper.Tasks;
|
||||
|
||||
public class CompressPatcherTask : ICompressPatcherTask
|
||||
{
|
||||
private Options _options;
|
||||
private FileHelper _fileHelper;
|
||||
private ZipHelper _zipHelper;
|
||||
|
||||
public CompressPatcherTask(Options options, FileHelper fileHelper, ZipHelper zipHelper)
|
||||
{
|
||||
_options = options;
|
||||
_fileHelper = fileHelper;
|
||||
_zipHelper = zipHelper;
|
||||
}
|
||||
|
||||
public bool CompressPatcher()
|
||||
{
|
||||
AnsiConsole.Progress()
|
||||
.Columns(new ProgressColumn[]
|
||||
{
|
||||
new TaskDescriptionColumn(),
|
||||
new ProgressBarColumn(),
|
||||
new PercentageColumn(),
|
||||
new ElapsedTimeColumn(),
|
||||
new SpinnerColumn(Spinner.Known.Dots2)
|
||||
})
|
||||
.Start(ctx =>
|
||||
{
|
||||
var compressionTask = ctx.AddTask("Compressing Patcher");
|
||||
compressionTask.MaxValue = 100;
|
||||
|
||||
if (!_fileHelper.StreamAssemblyResourceOut("7z.dll", _zipHelper.DllPath))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var patchFolder = new DirectoryInfo(_options.OutputPatchPath);
|
||||
|
||||
if (!patchFolder.Exists)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var patchArchiveFile = new FileInfo(_options.OutputPatchPath + ".7z");
|
||||
|
||||
var progress = new Progress<double>(p => { compressionTask.Increment(p - compressionTask.Percentage);});
|
||||
|
||||
return _zipHelper.Compress(patchFolder, patchArchiveFile, progress);
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Run()
|
||||
{
|
||||
CompressPatcher().ValidateOrExit();
|
||||
}
|
||||
}
|
@ -48,7 +48,6 @@ namespace EftPatchHelper.Tasks
|
||||
$"OutputFolderName::{patcherOutputName}",
|
||||
$"SourceFolderPath::{_options.SourceClient.PrepPath}",
|
||||
$"TargetFolderPath::{_options.TargetClient.PrepPath}",
|
||||
$"AutoZip::{_settings.AutoZip}",
|
||||
$"AutoClose::{_settings.AutoClose}"
|
||||
}
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user