0
0
mirror of https://github.com/sp-tarkov/installer.git synced 2025-02-12 17:30:44 -05:00

update ziphelper to use 7z.dll

also updated cache to drop compression extensions for aki release and patcher in preparation for 3.8.0
This commit is contained in:
IsWaffle 2024-03-23 14:15:48 -04:00
parent 745f0690d3
commit 1354eeb06c
10 changed files with 82 additions and 60 deletions

View File

@ -1,5 +1,4 @@
using Serilog;
using SharpCompress;
using SPTInstaller.CustomControls;
using SPTInstaller.Interfaces;
using SPTInstaller.Models;
@ -22,13 +21,18 @@ public class InstallController
{
_tasks = tasks;
_preChecks = preChecks;
_preChecks.ForEach(x => x.ReeevaluationRequested += (s, e) =>
foreach (var check in _preChecks)
{
if (s is IPreCheck preCheck)
check.ReeevaluationRequested += (s, _) =>
{
Log.Information($"{preCheck.Name}: requested re-evaluation");
if (s is not IPreCheck preCheck)
{
return;
}
Log.Information($"{preCheck.Name}: requested re-evaluation");
if (_installRunning)
{
Log.Warning("Install is running, re-evaluation denied (how did you do this?)");
@ -36,8 +40,8 @@ public class InstallController
}
RecheckRequested?.Invoke(this, null);
}
});
};
}
}
public async Task<IResult> RunPreChecks()
@ -45,7 +49,10 @@ public class InstallController
Log.Information("-<>--<>- Running PreChecks -<>--<>-");
var requiredResults = new List<IResult>();
_preChecks.ForEach(x => x.State = StatusSpinner.SpinnerState.Pending);
foreach (var check in _preChecks)
{
check.State = StatusSpinner.SpinnerState.Pending;
}
foreach (var check in _preChecks)
{

View File

@ -126,28 +126,39 @@ public static class FileHelper
}
}
public static void StreamAssemblyResourceOut(string resourceName, string outputFilePath)
public static bool StreamAssemblyResourceOut(string resourceName, string outputFilePath)
{
var assembly = Assembly.GetExecutingAssembly();
FileInfo outputFile = new FileInfo(outputFilePath);
if (outputFile.Exists)
try
{
outputFile.Delete();
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;
}
if (!outputFile.Directory.Exists)
catch (Exception ex)
{
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);
Log.Fatal(ex, $"Failed to stream resource out: {resourceName}");
return false;
}
}

View File

@ -1,46 +1,34 @@
using System.Linq;
using SharpCompress.Archives;
using SharpCompress.Archives.Zip;
using SharpCompress.Common;
using SevenZip;
using SPTInstaller.Models;
namespace SPTInstaller.Helpers;
public static class ZipHelper
{
public static Result Decompress(FileInfo ArchivePath, DirectoryInfo OutputFolderPath, IProgress<double> progress = null)
public static Result Decompress(FileInfo archiveFile, DirectoryInfo outputDirectory, IProgress<double> progress = null)
{
try
{
OutputFolderPath.Refresh();
using var archiveStream = archiveFile.OpenRead();
if (!OutputFolderPath.Exists) OutputFolderPath.Create();
var dllPath = Path.Join(DownloadCacheHelper.CachePath, "7z.dll");
SevenZipBase.SetLibraryPath(dllPath);
using var archive = ZipArchive.Open(ArchivePath);
var totalEntries = archive.Entries.Where(entry => !entry.IsDirectory);
var processedEntries = 0;
var extractor = new SevenZipExtractor(archiveStream);
foreach (var entry in totalEntries)
extractor.Extracting += (_, args) =>
{
entry.WriteToDirectory(OutputFolderPath.FullName, new ExtractionOptions()
{
ExtractFullPath = true,
Overwrite = true
});
progress.Report(args.PercentDone);
};
processedEntries++;
extractor.ExtractArchive(outputDirectory.FullName);
if (progress != null)
{
progress.Report(Math.Floor(((double)processedEntries / totalEntries.Count()) * 100));
}
}
outputDirectory.Refresh();
OutputFolderPath.Refresh();
if (!OutputFolderPath.Exists)
if (!outputDirectory.Exists)
{
return Result.FromError($"Failed to extract files: {ArchivePath.Name}");
return Result.FromError($"Failed to extract files: {archiveFile.Name}");
}
return Result.FromSuccess();

View File

@ -35,7 +35,9 @@ public class DownloadTask : InstallerTaskBase
var mirrorsList = JsonConvert.DeserializeObject<List<DownloadMirror>>(File.ReadAllText(file.FullName));
if (mirrorsList == null)
{
return Result.FromError("Failed to deserialize mirrors list");
}
foreach (var mirror in mirrorsList)
{
@ -59,7 +61,7 @@ public class DownloadTask : InstallerTaskBase
{
SetStatus("Downloading Patcher", "Verifying cached patcher ...", progressStyle: ProgressStyle.Indeterminate);
if (DownloadCacheHelper.CheckCache("patcher.zip", _expectedPatcherHash, out var cacheFile))
if (DownloadCacheHelper.CheckCache("patcher", _expectedPatcherHash, out var cacheFile))
{
_data.PatcherZipInfo = cacheFile;
Log.Information("Using cached file {fileName} - Hash: {hash}", _data.PatcherZipInfo.Name, _expectedPatcherHash);
@ -106,7 +108,7 @@ public class DownloadTask : InstallerTaskBase
SetStatus("Downloading SPT-AKI", _data.AkiReleaseDownloadLink, 0);
_data.AkiZipInfo = await DownloadCacheHelper.GetOrDownloadFileAsync("sptaki.zip", _data.AkiReleaseDownloadLink, progress, _data.AkiReleaseHash);
_data.AkiZipInfo = await DownloadCacheHelper.GetOrDownloadFileAsync("sptaki", _data.AkiReleaseDownloadLink, progress, _data.AkiReleaseHash);
if (_data.AkiZipInfo == null)
{

View File

@ -28,6 +28,13 @@ public class SetupClientTask : InstallerTaskBase
if (_data.PatchNeeded)
{
SetStatus("Preparing 7z", "", null, ProgressStyle.Indeterminate);
if (!FileHelper.StreamAssemblyResourceOut("7z.dll", Path.Join(DownloadCacheHelper.CachePath, "7z.dll")))
{
return Result.FromError("Failed to prepare 7z");
}
// extract patcher files
SetStatus("Extrating Patcher", "", 0);

View File

@ -61,7 +61,12 @@ public class InstallerUpdateInfo : ReactiveObject
UpdateAvailable = false;
var updater = new FileInfo(Path.Join(DownloadCacheHelper.CachePath, "update.ps1"));
FileHelper.StreamAssemblyResourceOut("update.ps1", updater.FullName);
if (!FileHelper.StreamAssemblyResourceOut("update.ps1", updater.FullName))
{
Log.Fatal("Failed to prepare update file");
return;
}
if (!updater.Exists)

View File

@ -10,7 +10,7 @@ public class HttpMirrorDownloader : MirrorDownloaderBase
public override async Task<FileInfo?> Download(IProgress<double> progress)
{
var file = await DownloadCacheHelper.DownloadFileAsync("patcher.zip", MirrorInfo.Link, progress);
var file = await DownloadCacheHelper.DownloadFileAsync("patcher", MirrorInfo.Link, progress);
if (file == null)
return null;

View File

@ -23,7 +23,7 @@ public class MegaMirrorDownloader : MirrorDownloaderBase
{
using var megaDownloadStream = await megaClient.DownloadAsync(new Uri(MirrorInfo.Link), progress);
var file = await DownloadCacheHelper.DownloadFileAsync("patcher.zip", megaDownloadStream);
var file = await DownloadCacheHelper.DownloadFileAsync("patcher", megaDownloadStream);
if (file == null)
return null;

Binary file not shown.

View File

@ -9,8 +9,8 @@
<PackageIcon>icon.ico</PackageIcon>
<ApplicationIcon>Assets\icon.ico</ApplicationIcon>
<Configurations>Debug;Release;TEST</Configurations>
<AssemblyVersion>2.41</AssemblyVersion>
<FileVersion>2.41</FileVersion>
<AssemblyVersion>2.42</AssemblyVersion>
<FileVersion>2.42</FileVersion>
<Company>SPT-AKI</Company>
</PropertyGroup>
@ -23,6 +23,8 @@
<ItemGroup>
<EmbeddedResource Include="Resources\update.ps1" />
<None Remove="Resources\7z.dll" />
<EmbeddedResource Include="Resources\7z.dll" />
</ItemGroup>
<ItemGroup>
@ -42,7 +44,7 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="SerilogTraceListener" Version="3.2.0" />
<PackageReference Include="SharpCompress" Version="0.34.0" />
<PackageReference Include="Squid-Box.SevenZipSharp" Version="1.6.1.23" />
<PackageReference Include="System.Reactive" Version="6.0.0" />
</ItemGroup>