using LANCommander.Server.Data; using LANCommander.Server.Data.Models; using LANCommander.Server.Services.Extensions; using LANCommander.SDK.Helpers; using System.IO.Compression; using System.Security.Cryptography.X509Certificates; using YamlDotNet.Serialization; using YamlDotNet.Serialization.NamingConventions; using LANCommander.SDK.Enums; using Microsoft.Extensions.Logging; using Microsoft.EntityFrameworkCore; using ZiggyCreatures.Caching.Fusion; namespace LANCommander.Server.Services { public class RedistributableService : BaseDatabaseService { private readonly ArchiveService ArchiveService; public RedistributableService( ILogger logger, IFusionCache cache, RepositoryFactory repositoryFactory, ArchiveService archiveService) : base(logger, cache, repositoryFactory) { ArchiveService = archiveService; } public async Task ImportAsync(Guid objectKey) { var importArchive = await ArchiveService.FirstOrDefaultAsync(a => a.ObjectKey == objectKey.ToString()); var importArchivePath = ArchiveService.GetArchiveFileLocation(importArchive); using (var importZip = ZipFile.OpenRead(importArchivePath)) { var manifest = ManifestHelper.Deserialize(await importZip.ReadAllTextAsync(ManifestHelper.ManifestFilename)); var redistributable = await GetAsync(manifest.Id); var exists = redistributable != null; if (!exists) redistributable = new Redistributable(); redistributable.Id = manifest.Id; redistributable.Name = manifest.Name; redistributable.Description = manifest.Description; redistributable.Notes = manifest.Notes; #region Scripts if (redistributable.Scripts == null) redistributable.Scripts = new List